Jump to content

  • Log In with Google      Sign In   
  • Create Account

Calling all IT Pros from Canada and Australia.. we need your help! Support our site by taking a quick sponsored surveyand win a chance at a $50 Amazon gift card. Click here to get started!

[Stage3D] Simple Target Camera / PointAt

Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 Stimpy83   Members   -  Reputation: 155


Posted 20 September 2012 - 09:30 AM


i'm having a really big problem to understand the pointAt function from stage3d. I think that pointAt does the same like lookAt in OpenGL - But i don't get it right.


I need a simple Camera with a target, like a target camera in 3D Max or Blender... something like this:

Posted Image
And my Code is - So i understand the function:

[source lang="java"]view.identity();target.x = position.x;target.y = position.y;target.z = 0;view.appendTranslation( -position.x, -position.y, -position.z);view.pointAt( target, at, up); view.invert();// at = 0,1,0// up = 0,0,1// Because Z is my UpVector[/source]

So - When i move the camera i don't have a target camera - my map rotates and fly away Posted Image I really don't understand the parameters for pointAt - Can somebody explain me how pointAt works? The Adobe Docu don't say many....

Big Thanks and sry for my bad english Posted Image


#2 DLabz   Members   -  Reputation: 103


Posted 08 October 2012 - 02:33 PM

[source lang="jscript"]package{ import flash.display.Graphics; import flash.display.Sprite; import flash.events.Event; import flash.geom.Matrix3D; import flash.geom.Point; import flash.geom.Vector3D; /** * ... * @author Petrovic Veljko <designlabz@gmail.com> */ public class Main extends Sprite { public var target:Sprite = new Sprite(); public var cam:Matrix3D = new Matrix3D(); public var view:Sprite = new Sprite(); public function Main():void { var g:Graphics; //draw top face var up:Sprite = new Sprite(); g = up.graphics; g.beginFill(0x7878FF,.5); g.drawRect( -200, -200, 400, 400); //draw bottom face var dn:Sprite = new Sprite(); g = dn.graphics; g.beginFill(0xFF00FF,.8); g.drawRect( -200, -200, 400, 400); g.endFill(); //draw arrow pointing up on screen (Y-) g.lineStyle(2); g.moveTo(-200, 0); g.lineTo(0, 200); g.lineTo(200, 0); //draw axes g = view.graphics; // X g.lineStyle(2, 0xff0000); g.moveTo(-500, -1000); g.lineTo( -500, 1000); g.moveTo(0, -1000); g.lineTo(0, 1000); g.moveTo(500, -1000); g.lineTo( 500, 1000); // Y g.lineStyle(2, 0x00FF00); g.moveTo( -1000, -500); g.lineTo(1000, -500); g.moveTo( -1000, 0); g.lineTo(1000, 0); g.moveTo( -1000, 500); g.lineTo(1000, 500); //add faces to 3D object dn.z = -200; target.addChild(dn); up.z = 200; target.addChild(up); //add object to view view.addChild(target); if (stage) init(); else addEventListener(Event.ADDED_TO_STAGE, init); } private function init(e:Event = null):void { removeEventListener(Event.ADDED_TO_STAGE, init); addEventListener(Event.ENTER_FRAME, tock); //activate 3D mode on view view.transform.matrix3D = new Matrix3D(); view.transform.matrix3D.identity(); //add view to stage addChild(view); } private function tock(e:Event = null):void { //get mouse offset from the center var o:Point = new Point(); o.x = (stage.stageWidth / 2 - mouseX); o.y = (stage.stageHeight / 2 - mouseY); //move cam cam.position = new Vector3D(5* -o.x, 5* o.y, 1000); cam.pointAt( new Vector3D( 0, 0, 0), //point in world space to look at Vector3D.Z_AXIS, //side of 3D objec facing up in world space Vector3D.Y_AXIS //where should our arrow point ); //reset view view.transform.matrix3D.identity(); //cam view.transform.matrix3D.append(cam); view.transform.matrix3D.invert(); //center view view.transform.matrix3D.appendTranslation(stage.stageWidth / 2, stage.stageHeight / 2, 1); } }}[/source]

Edited by DLabz, 08 October 2012 - 03:06 PM.

Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.