# 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.

## 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 on other sites
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 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 on other sites
fyi I used the mouse wheel to control the radius- makes it super easy to see loaded models

##### 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 on other sites
My own orbit camera is based on the following XNA wiki : http://www.xnawiki.c...Arc-Ball_Camera

Translating it to Directx was a very trivial task so I hope this can helps!

##### 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 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 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 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

1. 1
2. 2
Rutin
16
3. 3
4. 4
5. 5

• 11
• 26
• 10
• 11
• 9
• ### Forum Statistics

• Total Topics
633721
• Total Posts
3013537
×