WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 08-12-2004, 05:13 PM
tavaksai tavaksai is offline
Member
 
Join Date: Jul 2004
Posts: 22
node3d.center function

Hi,

Is it possible to stop the node3d.center(...) function from changing the position of the object as soon as it is called?

For example:

obj1 = viz.add('box.wrl')
obj1.rotate(40,0,0)
obj1.center(-1,0,-1)

As soon as the center function is called, it changes the rotation
(translation really) of obj1 relative to new center. I would like obj1 to stay still when center function is called and rotate around the new center only when obj1.rotate(...) is used.


Max
Reply With Quote
  #2  
Old 08-12-2004, 10:54 PM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
Hi Max,

The order in which you call the center and rotate commands makes no difference in the final position of the object. In your case you will need to either perform the matrix operations manually using a vizmat transform or use a transform hierarchy. Here's some sample code on how to use a transform hierarchy:
Code:
#Create a group node that will be the parent for the box
objParent = viz.add(viz.GROUP)

#Add the box to the group node
obj1 = objParent.add('box.wrl')

#Set the center of the group node
objParent.center(-1,0,-1)

#This won't affect the position of the box,
#because the rotation is being applied beneath the group node
obj1.rotate(40,0,0)

#This will affect the position of the box,
#becuase the rotation is being applied above the box node
objParent.rotate(40,0,0)
Let me know if you need any more help.
Reply With Quote
  #3  
Old 08-13-2004, 10:21 AM
tavaksai tavaksai is offline
Member
 
Join Date: Jul 2004
Posts: 22
clarification

Hi Farshizzo,

I don't think the group method helps. It has the same problem.
Just to clarify what I meant, here is a sample code:

import viz
viz.go()

outer_tube = viz.add("outer_tube_97_m.wrl")
# rotate around original 0,0,0 center
outer_tube.rotate(40,0,0)
print 'first position:', outer_tube.getpos(viz.ABSOLUTE_WORLD)
# don't want this next call to change position of object until next
# rotate call is made
outer_tube.center(.6,0,0)
print 'second position:', outer_tube.getpos(viz.ABSOLUTE_WORLD)

Notice first position and second position are different.
I would like second position to be equal to first after .center call.
In other words, I would like to prevent the object from moving
in any way upon obj.center(...) call.
I would like it to move only when rotate or translate functions are called.

Thanks for the help so far ,
Max
Reply With Quote
  #4  
Old 08-13-2004, 11:05 AM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
Hi Max,

Try using the following code to set the center of an object without affecting its translation:
Code:
oldpos = obj1.get(viz.POSITION,viz.ABSOLUTE_WORLD)
obj1.center(-1,0,-1)
newpos = obj1.get(viz.POSITION,viz.ABSOLUTE_WORLD)
obj1.translate(oldpos[0]-newpos[0],oldpos[1]-newpos[1],oldpos[2]-newpos[2],viz.RELATIVE_WORLD)
Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 09:54 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2019, vBulletin Solutions, Inc.
Copyright 2002-2018 WorldViz LLC