View Single Post
  #4  
Old 08-27-2007, 11:10 AM
shivanangel shivanangel is offline
Member
 
Join Date: Feb 2006
Location: New Jersey
Posts: 180
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:
#######################################################
## Created By: George Lecakes
## Purpose: 
##		The Visualizer class is meant as a container
##		to hold the model information as well as what
##		to do when the user selected an object.
##
##	Requirements:
##		This class requires a timer to check
##		for onMouseOver events. 
##
## Date Created: August 13, 2007
##		Created the class.
##
#######################################################

import viz
import vizact
import vizinfo

class Visualizer:
	def __init__(self):
	#Initialize Variables
		#Sets the model for this instance.
		self.model = viz.add('testSphere.OSG')
		#Set the model coordinates
		self.coords = [0,0,0]
		#Set the model scale
		self.scale = [1,1,1]
		#Is the object Moused Over?
		self.isMousedOver = 0
		#Is this object selected or not?
		self.isSelected = 0
		#sets the base alpha state
		self.alpha = 0.5
		#sets the base gamma state
		self.ambient = [1,1,1]
		#Set the gamma when onMouseOver
		self.overambient = [2,2,2]
		#Set the color of the selected item
		self.selectedColor = [0,1,0]
		#Event when mouse is over an object
		self.MouseOverObject = vizact.fade([1,1,1],[0.5,0.5,0.5],0.25)
		#Event when mouse is selecting an object
		self.MouseSelectObject = vizact.fade([1,1,1],[0,1,0],0.25)
		#Event when mouse is not selecting object
		self.noMouseSelectObject = vizact.fade([0,1,0],[0.5,0.5,0.5],0.25)

	def overObject(self):
		self.item = viz.pick(1)
		
		# If the mouse if moving over the instance and it is not selected
		if self.item.object == self.model and self.isMousedOver == 0 and self.isSelected == 0:
			self.isMousedOver = 1
			self.model.runAction(self.MouseOverObject)
		# If the mouse if not over the instance
		else:
			self.isMousedOver = 0
		#If the mouse if over the object, it is not selected and it is left clicked
		if self.item.object == self.model and self.isMousedOver == 1 and viz.mouse.getState() == viz.MOUSEBUTTON_LEFT and self.isSelected == 0:
			self.isSelected = 1
			self.model.runAction(self.MouseSelectObject)
		#If the mouse is not over the object, it is selected, and there is a left click
		if self.item.object != self.model and self.isMousedOver == 0 and viz.mouse.getState() == viz.MOUSEBUTTON_LEFT and self.isSelected == 1:
			self.isSelected = 0
			self.model.runAction(self.noMouseSelectObject)
		#If the object is not selected, the object is not selected, and there is a left click
		if self.item.object != self.model and self.isMousedOver == 0 and viz.mouse.getState() == viz.MOUSEBUTTON_LEFT and self.isSelected == 0:
			self.isSelected = 0


	#def selectObject(self, num):
Thanks!

George Lecakes
Rowan University
Reply With Quote