Rotating a cube always towards you

Software: Away3D 4.x

Saaikouze, Newbie
Posted: 22 November 2012 09:46 PM   Total Posts: 10

Hope the title made sense…
What I’m trying to figure out is how I’m going to rotate a cube the “correct” way.
Right now, I have a setup where the cube rotates towards you with drag up->down but when I rotate the cube 90 degrees left/right it rotates to the left/right, this because it’s still rotating on the Y axis while it probably should rotate on the Z axis. I do have some thoughts but I think there should be an easier way for it to rotate the way I want it to.

I hope I made any sense.

Here’s the example: http://www.mariusposthumus.nl/away3D
and the current code: http://pastebin.com/wEQczE7C

Thx again!!

Greetz
Marius
(The Netherlands)

   

Saaikouze, Newbie
Posted: 25 November 2012 07:10 PM   Total Posts: 10   [ # 1 ]

no one able to help me out?
Is there perhaps a Class that can help me out, or do I need to setup a complicated calculation?

   

Avatar
80prozent, Sr. Member
Posted: 25 November 2012 07:30 PM   Total Posts: 430   [ # 2 ]

hi

Take a lookAt the “lookAt”-function build into the object3d.as class (and therefore inherited by all other objects).

hope that helps

 Signature 

sorry…i hope my actionscript is better than my english…

   

Saaikouze, Newbie
Posted: 25 November 2012 07:34 PM   Total Posts: 10   [ # 3 ]

So in stead of rotating the cube Im going to rotate the camera with lookAt? That basicly what you mean?

   

Avatar
80prozent, Sr. Member
Posted: 25 November 2012 07:45 PM   Total Posts: 430   [ # 4 ]

No, you can specifiy a position in the local space of your object, to have the object always look at this position (i believe it will point the objects y-axis towards the position).

in your case, you could use your cameras position, to have your object always look towards the camera.

all you need to calculate is the cameras position in your objects-local-space.
if you have this, you can just do it like this:

yourObject.lookAt(yourCamerasPositionInYourObjectsSpace

 

 

 Signature 

sorry…i hope my actionscript is better than my english…

   

Saaikouze, Newbie
Posted: 25 November 2012 07:48 PM   Total Posts: 10   [ # 5 ]

Hmm I think I get it. So even though Im rotating the cube around its Xaxis, the XYZ pointer always stays in one position because its aimed at the camera, so when I drag up/down for the Yrotation the cube wil rotate towards me because Y will still be in my direction.

Thx for the tip, Ill try it out and post when I got it working

   

Avatar
80prozent, Sr. Member
Posted: 25 November 2012 07:52 PM   Total Posts: 430   [ # 6 ]

i didnt played a lot with the lookAt function, so i cant tell you how it will behave when trying to rotate the Object manually while having it lookAt something. could be that your manually set rotation will be overwritten by the lookAt function and therefore will have no effect. Or it could be that it messes the lookAt function up, so the Object will no longer lookAt the position.
or it could just work fine. I dont know.
Please let me know how it works for you. smile

 Signature 

sorry…i hope my actionscript is better than my english…

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X