Jump to content
  • Advertisement
Sign in to follow this  

OpenGL [Stage3D] Simple Target Camera / PointAt

This topic is 2177 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts


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:

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 = 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 sad.png 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 smile.png

Share this post

Link to post
Share on other sites
[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.drawRect( -200, -200, 400, 400);

//draw bottom face
var dn:Sprite = new Sprite();
g = dn.graphics;
g.drawRect( -200, -200, 400, 400);
//draw arrow pointing up on screen (Y-)
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;
up.z = 200;

//add object to view

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();
//add view to stage

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);

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

//center view
view.transform.matrix3D.appendTranslation(stage.stageWidth / 2, stage.stageHeight / 2, 1);
}[/source] Edited by DLabz

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!