PDA

View Full Version : Flex Camera pivot in Papervision, and Overiding



Myung
January 8th, 2009, 07:47 PM
Hi.

I'm trying to set a DisplayObject3D as a parent to a Camera3D.
the addChild(Camera) won't work...

So I tried to make a new class: cCameraPivot that is inherited from DisplayObject3D, but there seems to be a problem with the overriding of the properties (x, y, z, rotationX, etc. etc...)

In the overiding setter I have no access to the defined camera of the pivot.

Here is the code:



package
{
import org.papervision3d.cameras.Camera3D;
import org.papervision3d.objects.DisplayObject3D;
import org.papervision3d.core.proto.GeometryObject3D;


public class cCameraPivot extends DisplayObject3D
{
public var Cam :Camera3D;
private var camPos :DisplayObject3D;

public function cCameraPivot(camera:Camera3D, name:String = "pivot", geometry: GeometryObject3D = null)
{
super(name, geometry);
Cam = camera;
camPos = new DisplayObject3D();
camPos.copyTransform(Cam);
this.addChild(camPos);

}

public override function set x(value:Number):void {
camPos.copyTransform(Camera);
super.x = value;
Camera.copyTransform(camPos);
}

}

}



I get this message on running:

TypeError: Error #1009: Cannot access a property or method of a null object reference.
at cCameraPivot/set x()[C:\Data\Projects\Treepodia\PV Test 3\src\cCameraPivot.as:27]

whice is the first line in the setter of X.

What can be done???

TNX

speedok
January 9th, 2009, 05:52 AM
Aloha not sure what you are trying to do but normally you have a scene, camera, objects.
then you add a object to the scene not to the camera. If you want to use a object as the target of the camera you set it as camera.target = targetObject (which change the camera from freemode to targetcamera).

Join irc #papervision3d at freenode or use http://pv3dchat.flashbookmarks.com/ (webchat to the channel) to meet other pv3d developers.

Hope it helps.

Myung
January 9th, 2009, 09:36 AM
Hola!

Well, What I'm trying to do is another pivot point (DisplayObject3D) for the camera, so that if it rotates - the camera will automatically orbit around it, when it moves - the camera will move with it, and when I animate (Tween) it - the camera will animate accordingly.
It doesn't have to be a target since the camera might look at some other object,
like when you do define hierarchy between two or more DisplayObject3Ds.


TNX very much