|
mario, Newbie
Posted: 09 November 2013 10:16 AM Total Posts: 7
Hello,
I have a problem with I think easy movement of the camera.
I have a huge sphere(radius =1024) where inside there is a camera with HoverController(distance 512) look at 0,0,0 point. Now I want to force camera to go to the mouseX,mouseY position after I click the sphere/scene/view/stage. The movement of the camera looks like that:
private function update(e : Event) : void {if (move) { cameraController.panAngle = cameraSpeed * (- stage.mouseX + lastMouseX) + lastPanAngle; cameraController.tiltAngle = cameraSpeed * (- stage.mouseY + lastMouseY) + lastTiltAngle; } view.render();} private function MouseDown(e : MouseEvent) : void { lastPanAngle = cameraController.panAngle; lastTiltAngle = cameraController.tiltAngle; lastMouseX = stage.mouseX; lastMouseY = stage.mouseY; move = true;
}
This is obviously works but not as I want to. Could anyone help me?
Sorry for me English :]
|
mario, Newbie
Posted: 14 November 2013 12:41 PM Total Posts: 7
[ # 1 ]
Does anyone know how to do that? Please help me I am struggling to solve that issue almost a week.
How to translate mouseX, mouseY coords to panAngle and tiltAngle?
|
alihm, Jr. Member
Posted: 14 November 2013 01:44 PM Total Posts: 49
[ # 2 ]
From what I understood you want to rotate the camera to a point in space that you click?
Then you will need to unproject the mouse coords to get a 3D point in space where the cam is going to look at, the easiest way to animate it is to have a dummy object lookAt() to that point, and then use quaternions to slerp to that orientation:
//in loop, this code animates the camera to dummy's orientation var qCam:Quaternion = new Quaternion(); var qTarget:Quaternion = new Quaternion();
qTarget.fromMatrix(dummy.transform); qCam.fromMatrix(camera.transform); qCam.slerp(qcam,qtarget,0.1); camera.transform = qCam.toMatrix3D().clone();
|
mario, Newbie
Posted: 14 November 2013 03:29 PM Total Posts: 7
[ # 3 ]
alihm - 14 November 2013 01:44 PM From what I understood you want to rotate the camera to a point in space that you click?
Exactly.
I have tried with placing the dummy object and read event.localPositions but something was wrong.
Will try what you’re suggesting and I hope it will rotate as I want to.
|
alihm, Jr. Member
Posted: 14 November 2013 03:52 PM Total Posts: 49
[ # 4 ]
You need to do something like this:
var dummy:ObjectContainer3D = new ObjectContainer3D();
on MouseDown():
dummy.position = camera.position.clone(); dummy.lookAt(view.unproject(stage.mouseX,stage.mouseY,1000));
on Update():
var qCam:Quaternion = new Quaternion(); var qTarget:Quaternion = new Quaternion();
qTarget.fromMatrix(dummy.transform); qCam.fromMatrix(camera.transform); qCam.slerp(qCam,qTarget,0.1); camera.transform = qCam.toMatrix3D().clone();
|
mario, Newbie
Posted: 14 November 2013 04:26 PM Total Posts: 7
[ # 5 ]
It works very nicely. Exactly as I wanted! Many, many thanks. I would never find that solution. I have tried manipulate coords with sin&cos; and other mathematical formulas.
However I have changed camera from HoverController to just simple camera and now I have another problem that camera is to close to the inside surface of my sphere. I have tried to set camera.z, moveBack but the camera still is in 0,0,0 point(I think).
*edit
Ok I have found one of your posts where the code of positioning of the camera should take place.
once again many thanks!
|
alihm, Jr. Member
Posted: 14 November 2013 05:04 PM Total Posts: 49
[ # 6 ]
*Glad it worked :)
If the camera and sphere are both at 0,0,0 it shouldn’t look close, maybe camera is zoomed in? you can change the FOV(lens zoom) like this:
(camera.lens as PerspectiveLens).fieldOfView = 30;
|