PDA

View Full Version : Why does tut_cone move on its own?


imperialkat
03-18-2010, 02:01 PM
I'm trying to make a simulation of light coming from a laser diode (it's generally a cone shape). I figured I could use the tut_cone model and change its domensions. But when I change the cone's scale the cone will move somewhere else. Why won't it stay still?

Below is a program that illustrates my problem. The cone is supposed to be in front of the on-the-fly object there. The slider is only supposed to change the scale of the bottom of the cone (the circle).

import viz
import vizmenu
import math

viz.MainView.setPosition(0,0,-4)

viz.go()

viz.clearcolor(0.5, 0.5, 1)

#on-the-fly diode model
diode = viz.add( 'cylinder.wrl')
diode.color(0.5, 0.5, 0)
diode.scale(2, 0.1, 2)
diode.rotate(0, 0, 90)

diode1 = diode.add( 'cylinder.wrl')
diode1.color(0.5, 0, 0)
diode1.scale(.6, 1.5, .6)
diode1.setPosition(0, -.75, 0)

leg1 = diode.add('cylinder.wrl')
leg1.color(1, 0.3, 0.2)
leg1.scale(0.1, 7, 0.1)
leg1.setPosition(0.03, 0.5, 0)
leg2 = diode.add('cylinder.wrl')
leg2.color(1, 0.3, 0.2)
leg2.scale(0.1, 7, 0.1)
leg2.setPosition(-0.03, 0.5, 0)
leg3 = diode.add('cylinder.wrl')
leg3.color(1, 0.3, 0.2)
leg3.scale(0.1, 7, 0.1)
leg3.setPosition(0, 0.5, 0.03)
leg4 = diode.add('cylinder.wrl')
leg4.color(1, 0.3, 0.2)
leg4.scale(0.1, 7, 0.1)
leg4.setPosition(0, 0.5, -0.03)

#Here's the problem area
cone = diode.add('tut_cone.wrl')
cone.translate(0, 0, 0)
cone.scale(1, 1, 1)

slider = viz.add(viz.SLIDER, parent=viz.SCREEN)
slider.setPosition(.5, .85)

def onSlider(obj,pos):
if obj == slider:
cone.setScale(pos, 1, pos)

viz.callback(viz.SLIDER_EVENT,onSlider)

farshizzo
03-18-2010, 02:10 PM
The geometry in that model is not centered about the origin, therefore applying a scale will inherently affect its position.

I suggest using the vizshape module to create a cone. Example:import vizshape
cone = vizshape.addCone(radius=0.5,height=1)