RESOLVED: Camera view vector

Software: Away3D 4.x

Sorceror, Newbie
Posted: 22 September 2011 10:39 AM   Total Posts: 3

I would like to have directional light on current camera position and with direction of current camera view vector. But I didn’t found any way how to obtain camera view vector of Away3D/Stage3D camera.
Is it possible to get direction or point on which is current camera looking to?
Thanks for any advice
Paul

   

John Brookes, Moderator
Posted: 22 September 2011 10:49 AM   Total Posts: 732   [ # 1 ]

import away3d.core.math.Matrix3DUtils;
//renderloop
light.direction = Matrix3DUtils.getForward(view.camera);

   

Avatar
Alejandro Santander, Administrator
Posted: 22 September 2011 03:35 PM   Total Posts: 414   [ # 2 ]

Nice one John!

Sometimes I do this, light.transform = view.camera.transform.clone()
But yours I like more =)

   

Alex Bogartz, Sr. Member
Posted: 22 September 2011 04:14 PM   Total Posts: 216   [ # 3 ]

Ok, I know this is probably an easy answer, but how do I get the opposite?

I can set the light to the left of the camera like so:

mainLight.direction = Matrix3DUtils.getRight(view.camera.transform);

But for “getLeft” (which doesn’t exist), I need to have the negative value of the vector.  What’s the way to get that?

   

Avatar
Choons, Sr. Member
Posted: 22 September 2011 04:27 PM   Total Posts: 281   [ # 4 ]

doesn’t just changing the sign of each component reverse the vector direction?

   

Avatar
80prozent, Sr. Member
Posted: 22 September 2011 04:29 PM   Total Posts: 430   [ # 5 ]

since its a vector3d that is returned by the getRight method, you can use vector3d.negate(). never tried it, but in the adobe docs they say:

negate():void
Sets the current Vector3D object to its inverse.

 Signature 

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

   

Alex Bogartz, Sr. Member
Posted: 22 September 2011 04:34 PM   Total Posts: 216   [ # 6 ]

mainLight.direction = Matrix3DUtils.getRight(view.camera.transform);
mainLight.direction.negate();

Still makes the light appear from the left of the scene.  That second line appears to have no effect.

   

John Brookes, Moderator
Posted: 22 September 2011 04:42 PM   Total Posts: 732   [ # 7 ]

var dir:Vector3D = Matrix3DUtils.getRight(view.camera.transform);
dir.negate();
light.direction = dir;

   

Alex Bogartz, Sr. Member
Posted: 22 September 2011 04:55 PM   Total Posts: 216   [ # 8 ]

Works!

Ok, so I think the reason the previous code didn’t work is that the setter for “direction” is like this:

public function set direction(value Vector3D) : void
  {
   _direction 
value;
   
//lookAt(new Vector3D(x + _direction.x, y + _direction.y, z + _direction.z));
   
if(!_tmpLookAt_tmpLookAt = new Vector3D();
   
_tmpLookAt._direction.x;
   
_tmpLookAt._direction.y;
   
_tmpLookAt._direction.z;
   
   
lookAt(_tmpLookAt);
  

It’s actually calling the lookAt for the light vector.  And since lookAt isn’t a public function, you can’t call that on your own.  Maybe it needs an applyDirection function so you could say:

light.direction.x*=1;
light.applyDirection(); 

For animating effects?

 

 

   

Sorceror, Newbie
Posted: 22 September 2011 07:27 PM   Total Posts: 3   [ # 9 ]

Thanks a lot for all answers, this code works pretty well

light.direction Matrix3DUtils.getForward(view.camera.viewProjection); 

Paul

   

Avatar
Alejandro Santander, Administrator
Posted: 22 September 2011 08:46 PM   Total Posts: 414   [ # 10 ]

Lads, I added getters for forwardVector, rightVector, upVector, backVector,
leftVector and downVector in Object3D.as using the methods you suggested here. Everyone faces this problem often, so I figured it could be handy.

Please sync to the latest github source. You can do things like:

var director:Vector3D cube.downVector;
director.scaleBy(500);
sphere.position cube.position.add(director); 
   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X