Pick porblem with arrays
Hello,
I am having a little bit of a problem with the Pick() function. My code is below, but I will try to explain how the problem came up to begin with. I was working on a selection class to highlight an object or expand to see different objects when it was clicked. I was using the Pick() function for highlighting the eligable objects, and if the left mouse button was also clicked, it would then set that object as selected and would then cause several spheres to come out and be visible (which would later be equivolent to different selection choices). Anyways, I had it working, but then I went and used an array to hold each instance of a class called element, which was basically what I was checking for in the selection algorithm. This is the new, very initial code just to make a sphere highlight when selected. An array, composed of objects, is passed to the function: class ElementArray: def __init__(self): #Create two arrays elem1coords = -5,-1,0 elem2coords = 5,1,0 elem1 = Element(elem1coords, viz.ON) elem2 = Element(elem2coords, viz.ON) self.myArray = [elem1,elem2] These objects in the array each have an associated model and I would access it by typing instanceofclass.model. Before I would just check to see if a variable set equal to viz.pick(1) was equal to the instanceofclass.model and this worked just fine. Now however, with the new array of objects I find that the addresses that are being referenced are not equal to one another. Basically, I just printed out the picked object and what I am looking for. I watched the output and when I moused over the object, the memory addresses were not the same. Here is the selection code: [I]def SelectionLoop(elementArray): #What is the Mouse over? item = viz.pick(1) #Make a loop equal to the array size. Iterate through every element in the array. for i in range(len(elementArray.myArray)): #Check to see if the mouse is over the object print 'elemArray' print elementArray.myArray[i].model print 'item.object' print item.object if item.object == elementArray.myArray.model: #highlight the object item.ambient(5,5,5) else: #unhighlight the object item.object.ambient(0.5,0.5,0.5) Any help would be great, thank you! George Lecakes Rowan University |
Could you post a full script that I can run? Also, when posting code on the forums, please use the [code][/code] tags, it will preserve the formatting and make it easier to read.
|
Sorry about the incorrect formatting procedures. Here is the code, broken down:
Here is the main file, with the Viz.go. Code:
import viz Here is the ElementArray class: Code:
import viz Code:
import viz |
You might need this class as well, it isn't implemented, but I think the Element class has some calls to it, so better safe than sorry:
Code:
####################################################### George Lecakes Rowan University |
All times are GMT -7. The time now is 03:13 PM. |
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Copyright 2002-2023 WorldViz LLC