Cube fitting View

43 views
Skip to first unread message

Miroku

unread,
Nov 12, 2011, 11:40:58 AM11/12/11
to Away3D.dev
Hi everyone,
I'm in a Flash Pro project with my View3D as big as the stage
and I'm trying to make a cube of the dimension of the stage which
would fit exactly the View.
Practically the user shouldn't be aware of the presence of a 3D cube
(unless I animate it)

How can I achieve this?

thank you in advance =)

Miroku

unread,
Nov 15, 2011, 7:26:48 AM11/15/11
to Away3D.dev
I was thinking about using trigonometry in this way:
I know that my camera has a vertical FOV in degrees, and I know the
height of my cube. This way I can draw an isosceles triangle. Now I
can use trigonometry. I divide the triangle in two horizontally and
got two right triangles with these attributes:
beta angle = FOV/2
b cathetus = cube.height / 2

in this way the distance from camera and the side of the cube is equal
to the a cathetus so my formule should be: a = sin(beta) / b +
cube.depth / 2

well... this idea of mine............... doesn't work in practice... I
get a number way too far to what I achieved by trial and error =\

John Brookes

unread,
Nov 15, 2011, 9:18:13 AM11/15/11
to away3...@googlegroups.com
var maxheight:Number = Math.tan((PerspectiveLens(view.camera.lens).fieldOfView * 0.5) * Math.PI / 180) * distanceFromCamera * 2;
var maxWidth:Number = maxheight * (view.width / view.height);

remember distance from camera would be the distance to the face you looking at. Not the objects center.

Andrea Silvestri

unread,
Nov 15, 2011, 4:20:05 PM11/15/11
to away3...@googlegroups.com
Thank you for answering, John =)

Since the thing I need is exactly distanceFromCamera you mean I should
do this:
var distanceFromCamera = cube.width /
(Math.tan((PerspectiveLens(view.camera.lens).fieldOfView * 0.5) *
Math.PI / 180) * 2)
?

and then
camera.position = new Vector3D(0,0,distanceFromCamera)
?

Anyway I tried the code you posted but (despite that I imported the
PerspectiveLens package) I keep getting this error:
Main_VideoCubeAway3D.as, Line 34 1119: Access of possibly undefined
property fieldOfView through a reference with static type
away3d.cameras.lenses:PerspectiveLens.
If it helps I'm using a TargetCamera3D and Away3D version 3

John Brookes

unread,
Nov 15, 2011, 5:14:16 PM11/15/11
to away3...@googlegroups.com
ahh no, thats for away 4

Andrea Silvestri

unread,
Nov 15, 2011, 5:30:27 PM11/15/11
to away3...@googlegroups.com
Any solution for away 3? =\

John Brookes

unread,
Nov 16, 2011, 5:07:14 AM11/16/11
to away3...@googlegroups.com
I think its the same. Just replace with camera.fov

eg camera at defualt 0,0,-1000 a plane at 0,0,0

var maxheight:Number = Math.tan((view.camera.fov * 0.5) * Math.PI / 180) * 1000 * 2;
var maxWidth:Number = maxheight * (stage.stageWidth / stage.stageHeight);

plane = new Plane({material:material, width:maxWidth, height:maxheight, yUp:false, bothsides:true});
scene.addChild(plane);

Miroku

unread,
Nov 16, 2011, 10:31:08 AM11/16/11
to Away3D.dev
Problem is that camera.fov always returns 0 to me =\

On 16 Nov, 11:07, John Brookes <jbp...@googlemail.com> wrote:
> I think its the same. Just replace with camera.fov
>
> eg camera at defualt 0,0,-1000 a plane at 0,0,0
>
> var maxheight:Number = Math.tan((view.camera.fov * 0.5) * Math.PI / 180) *
> 1000 * 2;
> var maxWidth:Number = maxheight * (stage.stageWidth / stage.stageHeight);
>
> plane = new Plane({material:material, width:maxWidth, height:maxheight,
> yUp:false, bothsides:true});
> scene.addChild(plane);
>

John Brookes

unread,
Nov 16, 2011, 1:19:56 PM11/16/11
to away3...@googlegroups.com
You can get the fov by doing a single render, but..
Just tried it and the above doesn't work for 3.
So don't really know :/

A hcky way would be to do pixel perfect type thang with the default camera.

set the cubes width and depth to the stageWidth, and height to stageHeight
and
set the camera.z to -900-stagewidth/2

That would give you a cube that fills the stage.
Reply all
Reply to author
Forward
0 new messages