Jump to content
  • Advertisement
Sign in to follow this  
XVincentX

Camera auto positioning

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

Good morning to all!

I really like play Direct3D 11 making few examples and having fun with effects, but i have a problem.
Since i work manly with free 3D models found on the web, not all are well formed. Someone are centred in axes origins, some one not.
It's a problem for Camera, becouse i usually place it looking at 0,0,0 point, looking from some near place.

Each time i try a new model, i'm forced to make camera movements and try and retry unitil i find right position.
Can you suggest me a way to, reading model vertices, have a EyeVector and LookAtVector that will let me auto position camera?

Thank you a lot for your support,

Vincenzo.

Share this post


Link to post
Share on other sites
Advertisement
Are you hard coding your camera?

If yes you might want to control it with mouse and keyboard. This is the easiest solution I found in my own test projects. I usually use a kind of orbit camera that let me rotate arround a target and zoom in/out.

Share this post


Link to post
Share on other sites


public static function update(camera:Camera3D, stage:Stage, radius:Number = 50):void
{
var xmouse:Number = (stage.mouseX - (stage.stageWidth/2))/stage.stageWidth;
var ymouse:Number = (stage.mouseY - (stage.stageHeight/2))/stage.stageHeight;
var angleX:Number = Math.PI*2 * (xmouse)- Math.PI;
var angleY:Number = Math.PI * (ymouse) - Math.PI/2 ;

var xPos:Number = Math.sin(angleX)*radius;
var zPos:Number = Math.cos(angleX)*radius;
var yPos:Number = Math.cos(angleY)*radius;

xPos = Math.sin(angleY)*xPos;
zPos = Math.sin(angleY)*zPos;

camera.position.x = camera.target.x+xPos;
camera.position.z = camera.target.z-zPos;
camera.position.y = camera.target.y-yPos;
}


a little function to use mouse coords to orbit a camera.
stageWidth and stageHeight are the width and height of your window (this is an AS 3.0 example)

Share this post


Link to post
Share on other sites
Thank you for your code, i'm trying to use it!

Wha't the stage[color="#666600"].mouseX and mouseY rapresents? Absolute position? Relative to last point?

Share this post


Link to post
Share on other sites
find the extreme points of the vertices of the mesh, and center those, additionally scale them down by the radius, this way you'll always see it nicely.

adjusting the camera might be somehow cumbersome, as some artist model with 10000 the scale of other artist (sometimes this is also just an export issue, e.g. when they said the exporter units mm vs inch). In those cases, flying around might sometims seem to not move you at all and sometimes you reach speed of light ;), another issue is, in perspective view, that your near/far plane settings would need to be adjusted.

honestly, rescaling the mesh (even if you just patch the object matrix) is waaaaay simpler.

Share this post


Link to post
Share on other sites

Thank you for your code, i'm trying to use it!

Wha't the stage[color="#666600"].mouseX and mouseY rapresents? Absolute position? Relative to last point?


mouseX and mouseY are the mouse coordinates on screen (from 0 - window width for x and 0 - window height for y)
the position is a simple 3dVector representing the physical position of the camera
the target is the 3d point the camera is looking at (defaults to 0, 0, 0)

b

Share this post


Link to post
Share on other sites
hi Krypt0n
Can you please elaborate on the method you had mentioned.
are there any references can you give to implement the same.

Thanks
surya

Share this post


Link to post
Share on other sites

hi Krypt0n
Can you please elaborate on the method you had mentioned.
are there any references can you give to implement the same.

Thanks
surya

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!