Problems getting the scale factor

Software: Away3D 4.x

enguer, Newbie
Posted: 27 August 2012 09:26 AM   Total Posts: 6

Hi,
I have some problems getting the scale factor formula to work…
I’m using the lens perspective with fieldOfView = 20.

I need to adjust the camera z position in order to display all my object3d on the screen. This object’s height may vary.

Each time i modify my object, i adjust the camera position.

The distance formula works pretty well :

public function setCameraConfig(NumberNumberypos Number) : void {
var sw Number _view.width;
var 
sh Number _view.height;
// detection du mode
var mode String = (sw sh) ? "paysage" "portrait";

var 
Number = (((mode == "portrait") ? _view.height sw) / 2) / Math.tan((PerspectiveLens(_view.camera.lens).fieldOfView / (180 Math.PI)) / 2);
return 
z;


I need to display a plane on front of this object, and this plane need to have the exact height of my view, and a width in pixels.

When i use this formula which seems to be correct:

public function scaleByFOV(FOV Numberdistance NumberviewHeight Number) : Number {
   
var fl Number viewHeight / (Math.tan(FOV * (180 Math.PI)));
   
// scale = fLength / (fLength   distanceFromViewer);
   
return -/ (fl / (fl   distance));
  

the scale isn’t true. my plane is not at the right dimensions, and this dimensions vary when i move the camera .

I’ve searched a lot on this forum, but all the solutions returns the same result.

I’m using the last Away3d 4.0 gold one.

Have you some advice for me ?

 

   

enguer, Newbie
Posted: 27 August 2012 08:26 PM   Total Posts: 6   [ # 1 ]

I reply to myself.
I’ve found the right way to precisely get scale factor with the perspective lens.

public function scaleByVector(Number) : Number {
   
var v0 Vector3D _View.camera.unproject(-100);
   var 
v1 Vector3D _View.camera.unproject(100);
   
v0.scaleBy(/ (v0._View.camera.z));
   
v1.scaleBy(/ (v1._View.camera.z));
   var 
dist Number Vector3D.distance(v0v1);
   var 
scale Number dist _View.width;
   return 
scale;
  

the method unproject return a Vector3D with 20 unit of magnitude. You only need to scale it to your length and calculate the distance.

And a way to use it:

var scale:Number scaleByVector((_View.camera.z+100));
   
_Cube.= -100;
   
_Cube.= (512)*scale;
   
_Cube.-= (75)*scale;
   
_Cube.scaleX =_Cube.scaleY _Cube.scaleZ 1;
   
_Cube.scale(scale); 
   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X