RESOLVED: Camera / Projection functionality

Software: Away3D 3.x

R Villani, Newbie
Posted: 12 February 2012 02:40 PM   Total Posts: 13   [ # 16 ]

Hector, you’re very welcome! Knowlege is only worth it if you share it, said a friend of mine.

I haven’t had time to look your files yet but one thing I read you’re doing wrong is to set the Z of your container to the focalLength.

The correct position for the focal length is focalLength distant from CAMERA, not world origin, ie., xyz0. Thus, if your camera is at z:-100, your focal length is 100 and you position your container at z:focalLength, your object will be at z:100 and your camera at z:-100. That means your object is 200 away from the camera. Not the focalLength distance. Got it?

To position something in front of your camera at a given distance, use the forward vector of your camera multiplied by the distance you want added to the position of the camera.

Like this (if you want your object to be at focalLength distance from camera):

var camDirection:Vector3D camera.forwardVector;
camDirection.scaleBy(focalLength);
spriteContainer.position camera.position.add(camDirection); 

This will only work correctly if both camera and container are at the same coordinate space, ie., both are children of the same parent. Else, you’ll have to transform one of the matrices.

 

   

R Villani, Newbie
Posted: 12 February 2012 02:49 PM   Total Posts: 13   [ # 17 ]

Seeing your file confirmed what I said. XD

Your Cam is at z 2500 and your sprite 431.9~. The distance among them is 2068~, while your FL is 431.9~ with FOV 30.

Also, I don’t know if it was clear enough, but the distance parameter in my function is the actual distance between your object and the camera. So it can compensate the object’s scale knowing if it’s near or far.
An easy way to get this is to use the positions of both in the static function distance() from the Vector3D class.

distance = Vector3D.distance(cam.position, sprite.position);

 

   

Hector, Sr. Member
Posted: 14 February 2012 11:18 AM   Total Posts: 137   [ # 18 ]

Thanks R Villani, I missunderstood the use of the distance. I have corrected it in this test (See attached file) but still I’m not getting the results I expected.

For example if I have:
ViewHeight = 388
Distance = 2500
FOV = 30

focalLength = 388 / ( 2 * Math.tan( 30 * (180 / Math.PI) ) ) = 431.86~
fovScale = 1 / ( 431.86~ / ( 431.86~ + 2500 )) = 6.78~

If FOV changes to 29.5 fovScale is equal to 1.62~
If FOV changes to 29 fovScale is equal to -3.34~

So either I still have something wrong or I’m not using the right formula to keep the object’s size on screen when FOV changes.

 

File Attachments
SpriteScale2.zip  (File Size: 152KB - Downloads: 245)
   

Karim Beyrouti, Administrator
Posted: 27 March 2012 12:29 PM   Total Posts: 30   [ # 19 ]

Hello,

Well - I am wondering if anyone has managed to solve this one. I am trying to get pixel perfect precision in Away3D 4.0, and am not having much luck with any of those solutions.

Here is a test: http://kurst.co.uk/samples/pixelprecision/scaletest.html

Size of Sprite3D varies a little when I change the height of the stage ( resize browser window ), also size of Sprite3D seems different depending on whether it’s in the center or not.

if any of you have found a good solution I would love to hear it.

Here are my source files, if it helps: http://kurst.co.uk/samples/pixelprecision/scaletest.zip

Kind regards

 

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X