View Single Post
  #1  
Old 08-27-2007, 09:22 AM
shivanangel shivanangel is offline
Member
 
Join Date: Feb 2006
Location: New Jersey
Posts: 182
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
Reply With Quote