Jump to content
  • Advertisement
Sign in to follow this  
Stimpy83

OpenGL [Stage3D] Simple Target Camera / PointAt

This topic is 2084 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

Hi,

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.

Target:

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

camera.png
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 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
Advertisement
[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

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!