HoverController around a Mesh included in a rotated ObjectContainer3D

Software: Away3D 4.x

Dr Schizo, Newbie
Posted: 20 March 2012 01:09 AM   Total Posts: 11

Hi everybody,

I’m trying to make a solar system representation.

Earth is made of an ObjectContainer3D on (0,0,0) that contains a spheric Mesh on (1000,0,0). To make the sphere to rotate around the sound, I simply change the rotationY of the ObjectContainer3D on every frame. So far, it is working pretty good but I have a problem with the HoverController.

The HoverController is looking at the Mesh that is included in the ObjectContainer3D. When there is no rotation, I can look around the planet with no problem and the camera always stay at the same distance of the target. But when I rotate the ObjectContainer3D, the camera doesn’t turn anymore around the target and the distance changes continuously.

Since I have a hard explaining this in english, I made a simple example below with the following parameters:
- container is on (0,0,0)
- container.mesh is on (1000,0,0)

You can rotate the camera around the mesh by pressing the left mouse button and dragging.

On test1.swf, container.rotationY is equal to 0
On test2.swf, container.rotationY is equal to -45

On test1.swf, the rotation around the sphere is correct (the distance stay still)
On test2.swf, the rotation around the sphere is not correct.

What did I do wrong? Does anyone knows what to do?

Thank you a lot for reading this post and maybe to answer to it.

Dr Schizo

 

File Attachments
test2.swf  (File Size: 269KB - Downloads: 291)
test1.swf  (File Size: 269KB - Downloads: 274)
   

John Brookes, Moderator
Posted: 20 March 2012 11:01 AM   Total Posts: 732   [ # 1 ]

The hoverCam expects the object its looking at to be in world space.

You could set the lookAtposition to the objects scene position in the enterframe.

//ENTER_FRAME
yourHoverController.lookAtPosition = yourObject.scenePosition;

   

Avatar
Fabrice Closier, Administrator
Posted: 20 March 2012 12:05 PM   Total Posts: 1265   [ # 2 ]

or yourHoverController.lookAtPosition = yourObject.scenePosition.clone();
The lookAtcontroller takes the vector3D over, so if its updated, so does the lookat. By cloning or using another Vector3D that is not updated, the hover will not attempt to follow when update method is invoked.

Not saying it fits the actual case, just pointing out the diff.

   

John Brookes, Moderator
Posted: 20 March 2012 01:12 PM   Total Posts: 732   [ # 3 ]

@Fabrice

“The lookAtcontroller takes the vector3D over, so if its updated, so does the lookat.”
Brain melt.

Sort of understand what your saying but can’t think of where it would make a difference cloned or not.

If the object is moving in enterframe and either cloned or non cloned lookAt is also in enterframe both will constantly update the lookat and follow the moving object.

If either lookAt are out of enterframe and the object is set to move in enterframe both will give same restult and just lookAt that last set position.
Little sudo code?
Sorry just confused on the difference

   

Avatar
Fabrice Closier, Administrator
Posted: 20 March 2012 02:49 PM   Total Posts: 1265   [ # 4 ]

well say you do:
private var _lookAtVector:Vector3D = new Vector3D(0,0,0);
_hoverController.lookAtPosition = _lookAtVector;

and on enterFrame you do _lookAtVector.x+=2;

once you invoke the hover update method, it uses the ref vector, which is your _lookAtVector. This updated coordinate becomes the position that the code will use. This is ideal if you want to tween “dummies” or even have great following camera behavior.

In Prefab for instance, I do use a similar approach to the clone. I have a “lookAtVector” (to prevent make new instances), when you say you want to rotate around a given object. I read the selection.center and pass this value to the vector. Unlike version 1.x, if the target(mesh) moves, the target(hovercontroller) remains at the coordinates defined by the lookAtVector, not the updated position of the object.

Hope this will help lower your brain temperature smile

   

Dr Schizo, Newbie
Posted: 20 March 2012 04:23 PM   Total Posts: 11   [ # 5 ]

Thanks a lot. It is working perfectely.

   

John Brookes, Moderator
Posted: 20 March 2012 04:40 PM   Total Posts: 732   [ # 6 ]

I really should just pretend to understand,but this is bugging me smile

Its the difference between

_hoverController.lookAtPosition = someObject.scenePosition.clone()
and
_hoverController.lookAtPosition = someObject.scenePosition

Theres no difference between the two
If someObject is moved after setting the lookAt position theres still no difference. It just looks at the previous position before it was moved. (cloned or not).


Or even say

//...
pivot = new ObjectContainer3D();
scene.addChild(pivot);

planet = new Mesh(new SphereGeometry(150), new ColorMaterial(0xff0000));
planet.1000;
pivot.addChild(planet);

planet.scenePosition
//or
//v = planet.scenePosition.clone()
camController.lookAtPosition v
}

private function handleEnterFrame(e:Event):void 
{
pivot
.rotationY++
v.Math.sin(getTimer() / 1000) * 1000;

camController.update();
//... 

No difference again. It just looks at the v (0,y,1000)
Im sure Im being dumb on this but cant see it.

   

Avatar
Fabrice Closier, Administrator
Posted: 20 March 2012 10:10 PM   Total Posts: 1265   [ # 7 ]

you show a flaw in code (thx for that)
just runned a test, it works because I hover and alter other props.

http://www.closier.nl/awaytests/BasicViewportTest.html

I just apply the above _lookAtVector.x+= 2; as you can see it stops after a delay (steps) if not updated invalidated again.

It is not visible in my case, as I do not need to update it. I’ll fix the invalidation issue asap.

   

John Brookes, Moderator
Posted: 20 March 2012 10:21 PM   Total Posts: 732   [ # 8 ]

yeah noticed that while doing a demo.
If you don’t do camcontroller.update() it stops moving. (camcontoller being the hovercam)
Even if autoupdate is set to true.

   

Avatar
Fabrice Closier, Administrator
Posted: 20 March 2012 10:40 PM   Total Posts: 1265   [ # 9 ]

Anyway, you see my point now I think. Its basically the same diff as having a follow feature, but for vector3d objects instead of object3D’s.

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X