applyRotation() to Camera ??

12 views
Skip to first unread message

ben

unread,
May 6, 2009, 10:05:18 AM5/6/09
to away3d.dev
Hi,
I'm having to use lots of rotations by tweening and interpolating
matrix of a camera
I would like to catch cameras eulers sometimes,
but the fact is that after a matrix transformation, the eulers are not
updated, as well as rotations properties.
And I can't use the applyRotation() on a camera (no mesh)...

I can't find a way to update those properties and then read them...
I can only use the transform.forward of the camera to get an
information about its direction...

any tricks ?

Peter Kapelyan

unread,
May 6, 2009, 10:21:35 AM5/6/09
to away3...@googlegroups.com
Maybe you can do that to a null or blank Object3D and then just move the camera/rotations to that null?

-Pete
--
___________________

Actionscript 3.0 Flash 3D Graphics Engine

HTTP://AWAY3D.COM

ben

unread,
May 6, 2009, 10:42:19 AM5/6/09
to away3d.dev
the problem is not to move/tween/rotate the camera to a position/
direction/rotation
but to update the eulers properties.
using a null object would'nt be any help, because of the method, it's
eulers properties wouldn't be updated too.

Rob Bateman

unread,
May 6, 2009, 7:04:04 PM5/6/09
to away3...@googlegroups.com
Hey ben

can i ask how you are modifying the transform matrix of the camera? if you do not fire the transform setter (and simply modify the properties within it), then the euler angles will not update on the camera object.

maybe a code snippet of what you are doing would help solve this problem?

cheers

Rob
--
Rob Bateman
Flash Development & Consultancy

rob.b...@gmail.com
www.infiniteturtles.co.uk
www.away3d.com

ben

unread,
May 7, 2009, 4:39:29 AM5/7/09
to away3d.dev
HI Rib,
here is the code snipet of my transformation,
but you answered the main question:
"if you
do not fire the transform setter (and simply modify the properties
within
it), then the euler angles will not update on the camera object. "

here is the main part of the transformation that tween any object
matrix then positions and 3D rotations:

//added on scene init:
cameraTarget=new Object3D ;
startQuaternion=null;
endQuaternion=null;
currentQuaternion=null;
//added to any object in the scene
thing.addOnMouseDown(onMouseClickOnObject);

function onMouseClickOnObject(e:MouseEvent3D):void {
if (e.target!=null) {
cameraTarget.transform=e.target.transform;
if (e.target is Plane) {
cameraTarget.moveUp(200);
cameraTarget.pitch(90);///because plane need a 90 rotationX to be
straight
}

if (e.target is Plane!=true) {
cameraTarget.moveForward(200);
cameraTarget.roll(90),cameraTarget.yaw(180);
}

createTween(cameraTarget);
}

}
function createTween(target:Object3D):void {

camera.slerp=0;///this is an extra propertie added to object3D, you
can also use the embed extra propertie
var tweenObject:Object={};
tweenObject.x=target.x;
tweenObject.y=target.y;
tweenObject.z=target.z;
//tweenObject.bezierThrough=[{x:0,y:0,z:0,slerp:.2}];
tweenObject.ease="easeOut.Elastic";
tweenObject.slerp=1;
tweenObject.onUpdate=camera_updateCallback;

startQuaternion=Quaternion.createFromMatrix(camera.transform);//this
is a method I added to the Quaternion class
endQuaternion=Quaternion.createFromMatrix(target.transform);

TweenMax.to(camera, 1, tweenObject);

}
function camera_updateCallback():void {
currentQuaternion=Quaternion.slerp
(startQuaternion,endQuaternion,camera.slerp);///this is another method
I added to the Quaternion class
camera.transform.copy3x3(Quaternion.quaternion2Matrix
(currentQuaternion));////quaternion2Matrix is one more method I added
to the Quaternion class
}

the method added to the quaternion class are here:
http://groups.google.com/group/away3d-dev/browse_thread/thread/4056d80422f13929/e7895f56f9befcdf?lnk=gst&q=vector+quaternion#e7895f56f9befcdf


ben

unread,
May 7, 2009, 5:58:02 AM5/7/09
to away3d.dev
for more info:

what I want to achieve is a simple pan/tilt of the camera,
but after the tween (see above),
the simple method here give me a bug:
the first time I move the panObject(the target) steps to another place
than it's previous place (along the new forward vector of the camera
at determined distance when i click to initialize the pan/tilt
movement)...after that it works fairly well, but I would like to avoid
this "step" :

here is the method, a basic one:
private function initNavigationMode(e:MouseEvent):void
{
trace("init navigationMOde");
navigationMode = true;
moveMode = false;
paintMode = false;
//createMode = false;
//modelerMode = false;
quitMoveMode();
if (tools == null)
{
tools = new Sprite();
addChild(tools);
navigator = new Navigator();
navigator.x = SW/2;
navigator.y = SH/2;
tools.addChild(navigator);
navigator.useHandCursor = true;
}
else {
addChild(tools);
tools.addChild(navigator);
}
navigator.addEventListener(MouseEvent.MOUSE_DOWN,startMove);
}

private function startMove(e:MouseEvent):void
{
doNav=true;
panTarget.transform = camera.transform;
panTarget.moveForward(100);
panTarget.lookAt(camera.position);
lastPanAngle = panangle;
lastTiltAngle = tiltangle;
lastMouseX = navigator.mouseX;
lastMouseY = navigator.mouseY;
trace(panangle,tiltangle);
e.target.removeEventListener(MouseEvent.MOUSE_DOWN,startMove);
e.target.addEventListener(MouseEvent.MOUSE_MOVE,doMove);
e.target.addEventListener(MouseEvent.MOUSE_UP,stopMove);
e.target.addEventListener(MouseEvent.MOUSE_OUT,stopMove);
}
private function stopMove(e:MouseEvent):void
{
doNav=false;
trace(panangle,tiltangle);
e.target.removeEventListener(MouseEvent.MOUSE_OUT,stopMove);
e.target.removeEventListener(MouseEvent.MOUSE_MOVE,doMove);
e.target.addEventListener(MouseEvent.MOUSE_DOWN,startMove);
}
private function doMove(e:MouseEvent):void
{
var rotationMatrix:Matrix3D = new Matrix3D();
if(upView == true){
var currentMousePoint:Point = new Point(navigator.mouseX,
navigator.mouseY);
var difference:Point = currentMousePoint.subtract
(previousMousePoint);
var rotationAxis:Number3D = new Number3D()
var distance:Number = Point.distance(currentMousePoint,
previousMousePoint);
var distanceX:Number = navigator.mouseX-navigator.x;
var distanceY:Number = navigator.mouseY-navigator.y;

var rotationAxisY:Number3D = new Number3D();
var rotationAxisX:Number3D = new Number3D();
rotationAxisY = Number3D.UP;
rotationAxisX = Number3D.FORWARD;
rotationMatrix.rotationMatrix
(rotationAxisY.x,rotationAxisY.y,rotationAxisY.z,distance/100);
camera.transform.multiply4x4(rotationMatrix, camera.transform);
previousMousePoint = currentMousePoint;

} else
{
/////here is the thing
panangle = 0.5*(navigator.mouseX - lastMouseX) + lastPanAngle;
tiltangle = -0.5*(navigator.mouseY - lastMouseY) +
lastTiltAngle;
panTarget.x = 100 * Math.sin(panangle * toRADIANS) * Math.cos
(tiltangle * toRADIANS) + camera.x;
panTarget.z = 100 * Math.cos(panangle * toRADIANS) *
Math.cos(tiltangle * toRADIANS) + camera.z;
panTarget.y = 100 * Math.sin(tiltangle * toRADIANS) +
camera.y;
camera.lookAt(panTarget.position);

}

I thought that something wasn't updated but it comes from somewhere
else...

note:
I also tried with a rotationMatrix method (no target), works well but
havin a step too, that mean something in the camera rotation hasn't
been updated...

I know this is long question but thanks...

ben

unread,
May 7, 2009, 5:59:13 AM5/7/09
to away3d.dev
Rob, sorry for calling you Rib, above...
was thinking about Robby "Barbecue" Ribbs, who doesn't exist either
way... ;-)

Robert Thompson

unread,
May 7, 2009, 9:27:58 AM5/7/09
to away3...@googlegroups.com
Speaking of boiler templates [and btw, I'm not sure why nobody answers
me on this forum, are my messages getting through?]...

Does anyone have a good Flash CS3 or FLEX 3.0 Professional Starting
Point Template(s) such as:

1. Here is a Template for Away3D that can be used as a bare bones
starter for <this type of application>

2. And/or, here is a Template for Away3D that has various utility
functions within it, to assist in the development of <this type of
application, e.g. a cartesian orthogonal application with a background
and placement of Away3D builder environmental objects/buildings, and
characters rigged for animation and can be changed to non-orthogonal
view>

etc.

Thanks,
-r

ben

unread,
May 7, 2009, 9:41:48 AM5/7/09
to away3d.dev
Excuse me I'm French, but...
Robert,is this off topic or a kind of humour ???

Or do you really search for those kind of templates...?

;-)

Julien Barbay

unread,
May 7, 2009, 9:54:34 AM5/7/09
to away3...@googlegroups.com
If this can help, i'm using this snippet for most of my away3d. I only customize the camera if needed. The camera instanciation part should be outside the class definition, but i love so much orthogonal that it's set as default :)

{
import away3d.cameras.HoverCamera3D;
import away3d.cameras.lenses.OrthogonalLens;
import away3d.containers.View3D;
import away3d.core.base.Object3D;
import away3d.core.math.Number3D;
import away3d.lights.DirectionalLight3D;


import flash.events.Event;


public class Core extends View3D
{
private var _running:Boolean = false;
public function get running():Boolean { return _running; }
public function set running(value:Boolean):void { if (value) { start(); } else { stop(); } }


public function Core()
{
addEventListener(Event.ADDED_TO_STAGE, initialize);
}


private function initialize(e:Event):void
{
removeEventListener(Event.ADDED_TO_STAGE, initialize);


replace();
//renderer = Renderer.CORRECT_Z_ORDER;


camera = new HoverCamera3D();
camera.lens = new OrthogonalLens();
camera.position = new Number3D(100, 100, 100);
camera.lookAt(new Number3D(0, 0, 0));
camera.zoom = 100;


var light:DirectionalLight3D = new DirectionalLight3D();
light.position = new Number3D(1000, 1000, 1000);
light.color = 0xFFFFFF;
light.specular = 0;
light.diffuse = 0.5;
light.ambient = 0.25;


scene.addChild(light);


stage.addEventListener(Event.RESIZE, replace);
}


public function start():void
{
if (!_running)
{
_running = true;
stage.addEventListener(Event.ENTER_FRAME, enterFrame);
}
}


public function stop():void
{
if (_running)
{
_running = false;
stage.removeEventListener(Event.ENTER_FRAME, enterFrame);
}
}


public function addObject(object3d:Object3D):void { scene.addChild(object3d); }


private function enterFrame(e:Event):void { render(); }


private function replace(e:Event = null):void
{
x = stage.stageWidth / 2;
y = stage.stageHeight / 2;
}
}
}

Robert Thompson

unread,
May 7, 2009, 9:59:45 AM5/7/09
to away3...@googlegroups.com
Ben,

No it's not humor nor have I used any words to indicate such.

I'm simply looking into all the game engines at 3DFlashEngines.com

I'm not sure if the ;-) was necessary after questioning my motives on whether I'm on the lookout for templates.

To be clear, I'm looking for no more than what would be provided in an Apple SDK for iPhone, or to ADC Members, or by Microsoft in Visual Studio.

Why the subtle hostility?  What is really going on here.

Below is my e-mail and your response,

-r

My e-mail:

On May 7, 2009, at 9:27 AM, Robert Thompson wrote:
Speaking of boiler templates [and btw, I'm not sure why nobody answers me on this forum, are my messages getting through?]...

Does anyone have a good Flash CS3 or FLEX 3.0 Professional Starting Point Template(s) such as:

1. Here is a Template for Away3D that can be used as a bare bones starter for <this type of application>

2. And/or, here is a Template for Away3D that has various utility functions within it, to assist in the development of <this type of application, e.g. a cartesian orthogonal application with a background and placement of Away3D builder environmental objects/buildings, and characters rigged for animation and can be changed to non-orthogonal view>

etc.

Thanks,
-r

Your response:
Again, what is truly going on here to receive such a response.  Is there another, of more professional demeanor within this group that can provide a more neutral and less presumptuous response about my motives to a very clear and polite request?

-r

Robert Thompson

unread,
May 7, 2009, 10:00:58 AM5/7/09
to away3...@googlegroups.com
Thank you Julien, your response is appreciated greatly.

-r

ben

unread,
May 7, 2009, 11:11:02 AM5/7/09
to away3d.dev
Excuse me but they were no hostility at all in my answer !!!!!!!!
I thought that you were makin fun about my topic !
Sorry, for that.

Publish tjose kind of template is my TODO list.
Well, is there a place were I could share some kind of template with
you ??
I can only do it later because I have to clean it before.
or share any contact in sort that I can share it with you as soon as
I'll publish them in my blog :
http://www.agence-anonyme.com/blog

??

ben

unread,
May 7, 2009, 11:20:21 AM5/7/09
to away3d.dev
The fact is that this misunderstood never appened if you just ask for
it in another topic.
I'm shure a lot of people would be interested in helping you.

But they won't find you if your question is not in a revealant
topic...


makc

unread,
May 17, 2009, 3:18:17 AM5/17/09
to away3d.dev
And another one jumps in,

On May 7, 4:59 pm, Robert Thompson <rob...@activecommunity.com> wrote:
> I'm simply looking into all the game engines at 3DFlashEngines.com

how about making your list a little longer?
http://makc.coverthesky.com/FlashFX/ffx.php?id=10

and I am sure it is missing an engine or two already
Reply all
Reply to author
Forward
0 new messages