Work out camera facing direction based on motion

Software: Away3D 4.x

Avatar
Darcey, Moderator
Posted: 25 August 2011 08:35 PM   Total Posts: 209

Hi,

Anyone got the equation for working out how to get the camera to look in the direction of motion?

I’ve got an object controlled in 3D space and need to work out which way we are going and look in that direction. The object may or maynot (probably wont) be facing the direction we are moving in.

Any ideas?

Thanks

Darcey

   

Avatar
Choons, Sr. Member
Posted: 25 August 2011 09:26 PM   Total Posts: 281   [ # 1 ]

it’s easy if your object faces direction of motion- view.camera.transform = myObject.transform and then offset it a bit so not inside your mesh. But motion off center not sure. You could calculate a vector using a lastPosition/currentPosition in the frame event and assign it to the camera, but there’s probably a builr-in method for that I’m not aware of

   

Avatar
Darcey, Moderator
Posted: 25 August 2011 09:59 PM   Total Posts: 209   [ # 2 ]

hmmmm maybe I should re-think my camera positioning to be locked to direction facing and the user then can offset camera to their choice and when timeout occurs the camera returns to object facing direction instead of motion direction.

But I will still need the equation for when the user selects look in direction of motion. I think I will try and do the messy version till I can find a decent equation for this. Which would be working out a sin and cos equation for each quadrant of direction on the x,y,z graph (4 quad) and see where that takes me. Take a normal of the target and look at that. hmmm

or maybe if i can project direction from velocity on x,y,z and take a normal of that.. err..

1. Mesh is not facing direction of motion
2. Mesh x,y,z is known
3. Velocity on x,y,z is known

Calculate normal based velocity and mesh x,y,z.

Ok, time to break out the pen, paper and the desktop calculator…
Googling lots of stuff… These test projects are flying out lol

Number crunching

   

Richard Olsson, Administrator
Posted: 26 August 2011 07:10 AM   Total Posts: 1192   [ # 3 ]

Try this:

  lookAtVector = camera.position.add(velocityVector);
  camera.lookAt(lookAtVector);

This should get a point that should be in front of the camera, and then rotate the camera to face that point.

   

Avatar
Darcey, Moderator
Posted: 26 August 2011 08:41 AM   Total Posts: 209   [ # 4 ]

Nice one Richard!

Will give that a shot after work tonight.

Cheers

D

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X