View scale to Object scale size

Software: Away3D 4.x

Avatar
Darcey, Moderator
Posted: 03 October 2012 12:00 AM   Total Posts: 209

Hi,

Anyone got any pointers on keeping an object (cube) which I have at the same size in true pixels as the Away3D 4.x view/scene resizes itself on browser/window resize?

My goal is to resize a cube to an exact width and height which is specified in xml (so this is variable). I have hard coded this for full screen 1920x1080 but it would be nice so that I could match the pixel width of the 2D item when someone resizes the browser and not have the 3D element scale or undercale.

Is there an equation that I can obtain to maintain an objects size no matter what width and height the view becomes?

Process flow:
1. So my cube’s dimensions are initially 128x64
2. On cube selection it moves forward 800px
3. The cube’s pixel size is measured in photoshop as 2D is 530x265
4. Get xml target sizes - which are 640x480
5. Find % scale of cube so that it would match 2D object of 640x480

(TargetWidth/5.3)/100; // For width
(TargetHeight/2.65)/100; // For height

6. Tween scaleX & Y of the cube targetX & Y using equation above.
7. PROBLEM: Screen resolution is not 1920x1080, equation no longer works as cube at stage 3 is no longer 530x265 and the act of measuring it’s 2D size is manual process…?


Any ideas?


Thanks

Darcey

   

Avatar
loth, Sr. Member
Posted: 03 October 2012 07:52 AM   Total Posts: 236   [ # 1 ]

maybe this can help you
http://www.everyday3d.com/blog/index.php/2008/07/07/pixel-precision-in-papervision3d/

   

Avatar
Darcey, Moderator
Posted: 03 October 2012 06:31 PM   Total Posts: 209   [ # 2 ]

Solved it but not using anything from camera etc, a tad messy but it works.

//H = Height of browser/application

// 1:2 Ratio 
var scaleYAt1080:Number 3// Verified visually even though cube is 128x64 - 2:1
var scaleYAt540:Number 1.5// Verified visually even though cube is 128x64 - 2:1
var scaleYDifferenceAt960From1080:Number scaleYAt1080 scaleYAt540;
var 
scaleYPerPixel:Number scaleYDifferenceAt960From1080/540;
var 
heightDifferenceFrom1080:Number 1080 Variables.stage.stageHeight;
var 
scaleDifferenceBasedOnHeight:Number heightDifferenceFrom1080 scaleYPerPixel;
   
scalerY scaleYAt1080 scaleDifferenceBasedOnHeight;
targetScaleY = (get2DTargetHeight()/scalerY)/100;
   
scalerX scalerY 2;
targetScaleX = (get2DTargetWidth()/scalerX)/100;

cube.scaleX targetScaleX;
cube.scaleY targetScaleY
   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X