|
maximec, Newbie
Posted: 19 October 2011 03:56 PM Total Posts: 4
Hello
First of all I’d like to thank you all for the time you spend on these forums to help people out, and for developing such resources for us. It helped me a lot !
I hope that wasn’t asked yet, I’ve been searching for a whole day how to accomplish this without success. Here is my problem :
I would like to be able to create a mouse-controlled camera that would move around an item with movement easing, always looking at the same target. As the example on FlashMagazine, you can have a look if you want : http://www.flashmagazine.com/tutorials/detail/away3d_basics_the_cameras/ they call it “Orbiting your scene using the Mouse”, the latest chapter of this page.
Using this file worked fine on 3.6 for me, with a HoverCamera3D and its awesome properties (panAngle, tiltAngle, etc..). Lately I’ve upgraded to 4.0 and I saw these properties were gone, I searched a lot and did not find anything, then I’ve been trying to do this by myself with the camera coordinates and camera.position coordinates, but it did not work out..
I was hoping there was a unique and simple way to do this, or a tutorial somewhere. Are you aware of any ?
Thank you for your time
Maxime
|
Alex Bogartz, Sr. Member
Posted: 19 October 2011 04:38 PM Total Posts: 216
[ # 1 ]
I wrote a camera controller that does this, and I posted the details here:
http://away3d.com/forum/viewthread/1033/
There is a property called “rotation” which is the angle at which the camera moves to look at the target. You can update this value in a loop or based on mouse moves and this will get you what you want.
Hope this helps, and if you improve on the controller let me know!
|
Somokon, Member
Posted: 19 October 2011 04:51 PM Total Posts: 75
[ # 2 ]
Just a tip, when working with orbiting cameras, I find it much easier to work in a spherical coordinate system. Convert camera position to spherical coordinates -> Do your camera logic -> convert back to Cartesian coordinates and update the cameras position vector.
|
Alex Bogartz, Sr. Member
Posted: 19 October 2011 04:59 PM Total Posts: 216
[ # 3 ]
Oh? I’m pretty new to Away3D, so I just used 2D trig and added the 3rd dimension. Can you take a look at the class I wrote and explain what’s wrong with it? I’d love for this class to be added to the project, but only if it’s correctly implemented.
|
Somokon, Member
Posted: 19 October 2011 05:38 PM Total Posts: 75
[ # 4 ]
No no, I’m sure your class is fine
That was directed at the original poster, if he wanted to try to implement some sort of hovering/orbiting camera from scratch.
|
Alex Bogartz, Sr. Member
Posted: 19 October 2011 07:02 PM Total Posts: 216
[ # 5 ]
Heh, still, I’d love to see further explanation about using spheres, especially if that would improve performance?
|
maximec, Newbie
Posted: 20 October 2011 08:52 AM Total Posts: 4
[ # 6 ]
Hello
Thank you for your answers
Your camera class is great Alex and I’ll definitely keep it somewhere (I am always amazed to see how people manage to build such things..) But this is not exactly the kind of camera movement I’d like to build. I think I did not explain myself very well (I’m not too fluent in English).
Here it’s as if the camera was on a circular rail surrounding the target, and it can move on this rail always at the same distance from the ground, targetting the target at every frame.
What I’d like is to be able to move around the object at 360°, as if you were in the perspective view of a WYSIWYG 3D software interface like 3DSMax or Maya. I am actually trying to build a model viewer
I am also interested in knowing a bit more about those Spherical coordinates you’re talking about Somokon
Thanks guys !
|
Alex Bogartz, Sr. Member
Posted: 20 October 2011 02:38 PM Total Posts: 216
[ # 7 ]
Yes, the smooth follow class will work for this. There’s a property called “rotation” on the class. You can set this for any number, say 0. Then every frame, increase this number by .1. You will see the camera orbit the target at the specified height, which defaults to 1000.
on loop
cameraController.rotation+=.1;
cameraController.update();
view.render();
end loop
|
Somokon, Member
Posted: 20 October 2011 05:55 PM Total Posts: 75
[ # 8 ]
Alex Bogartz - 19 October 2011 07:02 PM Heh, still, I’d love to see further explanation about using spheres, especially if that would improve performance?
It wouldn’t improve performance, it just makes (in my opinion) the logic of moving the camera around easier.
maximec - 20 October 2011 08:52 AM am also interested in knowing a bit more about those Spherical coordinates you’re talking about Somokon
Basically instead of (x,y,z) representing a position in 3D space, you have (r,t,p), where r is the distance from (0,0,0), and t,p are two angles.
http://en.wikipedia.org/wiki/Spherical_coordinate_system#Cartesian_coordinates
So lets say you wanting an orbiting camera that was always certain distance from the target, and always at a certain height above the ground. If you work in spherical coordinates this is easy because you only have to change one angle.
(x,y,z) -> convert to spherical (r,t,p)
p = p +/- some amount
(r,t,p) -> convert back to (x,y,z).
Update camera position with new (x,y,z).
So you don’t have to manually find the changes you have to make to x,y,z, this is all captured in the conversion formula that you can find on wikipedia.
|
Rant, Newbie
Posted: 02 November 2011 06:50 AM Total Posts: 8
[ # 9 ]
Well i wrote this code for a camera controller I think that maybe this is what u are looking for. The code was based on the HoverDragController by David Lenaerts wich its in the examples for Away3D v4. I had to change the coordinate system because one of the angles ist limited to -90 to 90 angles so it was not fit for my app. You can turn arround the object with the mouse or keyboard. One problem tho it doenst autoscale so if ur object its to small or to big maybe u will need to change some part of the code to fit ur needs.
File Attachments
|
maximec, Newbie
Posted: 02 November 2011 09:21 AM Total Posts: 4
[ # 10 ]
Thank you Rant, I’m definitely going to check that out as soon as I have time !
|