WorldViz User Forum rotate object in relation of sth. else
 Register FAQ Search Today's Posts Mark Forums Read

#1
05-05-2009, 02:49 AM
 Penguin Member Join Date: Mar 2009 Posts: 14
rotate object in relation of sth. else

Probably a simple question:

How do I rotate an object (node3d) in relation to another objects local coordinate system?

For instance, I want to relatively rotate object1 by 1 degree in relation to the z-axis of object2s local coordinate system (roll of 1 degree according to object2).

In another example I want to relatively rotate object1 by 1 degree in relation to the main view (roll of 1 degree according to main view).
#2
05-05-2009, 12:47 PM
 farshizzo WorldViz Team Member Join Date: Mar 2003 Posts: 2,849
You can use the matrix.preEuler methods to rotate objects relative to arbitrary coordinate frames. Here is how you would roll object1 relative to object2's coordinate frame:
Code:
```m = object2.getMatrix()
m.preEuler(0,0,1)
object1.setQuat(m.getQuat())```
You would use similar code to perform the rotation relative to the viewpoint by retrieving the matrix from the viz.MainView object.

Let me know if I misunderstood your question or you need more specific examples.
#3
05-05-2009, 11:45 PM
 Penguin Member Join Date: Mar 2009 Posts: 14
This is not exactly what I meant.

For illustrating I attached some screen shots:

Left picture:
Start position. object1 = blue torus, object2 = white torus)

Middle picture:
Your end position. Your code seems to copy the complete orientation of object2 to object1

Right picture:
Desired end position. I want to rotate object1 according to the orientation of object2. Kinda object1.setEuler([0,0,45],viz.REL_LOCAL_of_object2)
Attached Thumbnails

#4
05-06-2009, 10:37 AM
 farshizzo WorldViz Team Member Join Date: Mar 2003 Posts: 2,849
Ok, it sounds like you want a hierarchical relationship between object1 and object2. In this case you would simply add object1 as a child to object2. When object2 is rotated, object1 will automatically rotate in object2's reference frame. If for some reason you don't want a to use a hierarchical relationship, then here is some code to manually compute the matrix:
Code:
```euler = viz.Matrix.euler(0,0,roll)
m1 = object1.getMatrix()
m2 = object2.getMatrix()

diff = m1 * m2.inverse()

m2new = euler * m2
object2.setQuat(m2new.getQuat())
object1.setMatrix(diff * m2new)```
#5
05-06-2009, 12:05 PM
 Gladsomebeast Member Join Date: Mar 2005 Location: Isla Vizta, CA Posts: 397
Me gusta el code. Porque yo tengo code similar, pero esto code es mas fácil.

También, Penguin usted puede utilizar un objeto Link para esto, si no te gusta hierarchical.
__________________
Paul Elliott
WorldViz LLC
#6
05-06-2009, 12:16 PM
 farshizzo WorldViz Team Member Join Date: Mar 2003 Posts: 2,849
Vous êtes fou mec. J'ai comme vous, mais vous êtes fou.
#7
05-11-2009, 08:54 AM
 Penguin Member Join Date: Mar 2009 Posts: 14
Thank you, the code works best for me! I only did some minor changes: translating to origin before rotating:

Code:
```euler = viz.Matrix.euler(0,0,roll)
m1 = object1.getMatrix()
m2 = object2.getMatrix()

m1.setTrans(0,0,0)
m2.setTrans(0,0,0)

diff = m1 * m2.inverse()

m2new = euler * m2
object2.setQuat(m2new.getQuat())
m1new = diff * m2new
m1new.setTrans(object1.getPosition(viz.ABS_GLOBAL))
object1.setMatrix(m1new)```

 Thread Tools Display Modes Rate This Thread Linear Mode Rate This Thread: 5 : Excellent 4 : Good 3 : Average 2 : Bad 1 : Terrible

 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 Rules
 Forum Jump User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home Announcements Vizard Precision Position Tracker (PPT) Plug-in development

 Similar Threads Thread Thread Starter Forum Replies Last Post Geoffrey Vizard 11 12-11-2009 04:26 AM nasr Vizard 5 05-05-2009 03:11 AM durf Vizard 3 03-17-2009 11:48 PM paulgoldberg Vizard 5 09-05-2006 11:33 AM jargon Vizard 1 08-08-2005 12:20 PM

All times are GMT -7. The time now is 01:05 AM.