public class SpringCamTest extends Sprite { // private var view : View3D; private var springCam:SpringCam = new SpringCam(null); private var c:Cube = new Cube();
public function SpringCamTest() { if (stage) { init(); } else { addEventListener(Event.ADDED_TO_STAGE, init); } }
private function init(e : Event = null) : void { removeEventListener(Event.ADDED_TO_STAGE, init); view = new View3D(); view.antiAlias = 4; this.addChild(view);
springCam.positionOffset = new Vector3D(0,5,-50); springCam.lookOffset = new Vector3D(0, 2, 10); view.camera = springCam;
private function keyDownHandler(event : KeyboardEvent) : void { switch(event.keyCode) { case Keyboard.UP: c.y += 10; break; case Keyboard.DOWN: c.y -= 10; break; case Keyboard.LEFT: c.x -= 10; break; case Keyboard.RIGHT: c.x += 10; break; } }
private function handleEnterFrame(e : Event) : void { view.render(); }[/size][/size]
} }
opie, Newbie Posted: 22 November 2011 09:47 PM Total Posts: 2
[ # 1 ]
I don’t know how you can tell if it’s being followed in this code as there’s no static reference point. Anyway, that’s not your issue. You just have the offset too close so your cam is springing into the center of your cube.
Try this instead;
springCam.positionOffset = new Vector3D(0,50,-150);
Stephen Hopkins, Sr. Member Posted: 22 November 2011 10:39 PM Total Posts: 110
[ # 2 ]
I think this may be a bug. I recently updated my project’s away3d reference and my springcamera no longer follows target.
For whatever reason, the public override function get viewProjection():Matrix3D
only gets called once at the very beginning of my game, and then does nothing else. Not really sure what api changes went on behind the scenes,
Just did some searching, has SpringCam been officially removed? It’s still in the trunk, but it no longer seems to work. Richard made a comment about the new Controller System.
Are there plans to make a SpringCam Controller or whatever needs to be done? I would like to use the newest version of away3d but my project depends on the springcam, and reverting back requires fixing api changes (although not too many).
Stephen Hopkins, Sr. Member Posted: 22 November 2011 11:49 PM Total Posts: 110
[ # 3 ]
heres a temporary SpringCamController I made, although I was disappointed that my SpringCamController did not behave exactly the same as the old SpringCam… I had to adjust the stiffness and mass, but its still not quite the same :(
To use it, create a camera:Camera3D, and a target:Object3D
var springCamController:SpringCamController = new SpringCamController(camera); springCamController.cameraTarget = target; springCamController.autoUpdate = false; //springCamController contains all the properties that the orignal SpringCam has, such as stiffness, damping, etc.. in your enterFrame Loop springCamController.update();
public class SpringCamController extends ControllerBase{ public var cameraTarget:Object3D; /** * [optional] Target object3d that camera should follow. If target is null, camera behaves just like a normal Camera3D. */ //spring stiffness /** * Stiffness of the spring, how hard is it to extend. The higher it is, the more "fixed" the cam will be. * A number between 1 and 20 is recommended. */ public var stiffness:Number = 1; /** * Damping is the spring internal friction, or how much it resists the "boinggggg" effect. Too high and you'll lose it! * A number between 1 and 20 is recommended. */ public var damping:Number = 4; /** * Mass of the camera, if over 120 and it'll be very heavy to move. */ public var mass:Number = 40; /** * Offset of spring center from target in target object space, ie: Where the camera should ideally be in the target object space. */ public var positionOffset:Vector3D = new Vector3D(0,5,-50);
/** * offset of facing in target object space, ie: where in the target object space should the camera look. */ public var lookOffset:Vector3D = new Vector3D(0,2,10);
//zrot to apply to the cam private var _zrot:Number = 0;
//private physics members private var _velocity:Vector3D = new Vector3D(); private var _dv:Vector3D = new Vector3D(); private var _stretch:Vector3D = new Vector3D(); private var _force:Vector3D = new Vector3D(); private var _acceleration:Vector3D = new Vector3D();
//private target members private var _desiredPosition:Vector3D = new Vector3D(); private var _lookAtPosition:Vector3D = new Vector3D();
//private transformed members private var _xPositionOffset:Vector3D = new Vector3D(); private var _xLookOffset:Vector3D = new Vector3D(); private var _xPosition:Vector3D = new Vector3D();
private var _viewProjection : Matrix3D = new Matrix3D(); private var _up:Vector3D = new Vector3D(); public function SpringCamController(targetObject:Entity=null){ super(targetObject);
}
public override function update():void{ if(cameraTarget != null){ _xPositionOffset = cameraTarget.transform.deltaTransformVector(positionOffset); _xLookOffset = cameraTarget.transform.deltaTransformVector(lookOffset); var p:Vector3D = cameraTarget.position; _desiredPosition = p.add(_xPositionOffset); _lookAtPosition = p.add(_xLookOffset);
John Wilson, Member Posted: 23 November 2011 08:28 AM Total Posts: 62
[ # 4 ]
Hi,
Thanks for the advice and and thanks very much for the sample code. I was also a little confused as to whether springCam.as should still be in the trunk or not.
John Wilson, Member Posted: 23 November 2011 09:39 AM Total Posts: 62
[ # 5 ]
Hi Stephen,
Sorry to be a pain I can only get your SpringCamController to work if I comment out the call to rotate() as follows: