Sign in to follow this  

orbit camera math

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

hello.
I would create a unit sphere coord in my orbit camera.
i use this:
 

float s = glm::min<float>(m_width, m_height);
float xp = ((m_deltax - (m_width/2 )) / s);
float yp = ((m_deltay -( m_height/2 )) / s);


this works fine , but it have a max of 0.6 for x and 0.4 for the y i would the max to 2pi for the x and pi for y.
now i ask if the creation of the sphere coords is correct and how i can fit the values to 0-360 for x and 0-180 for y.
now is a semisphere , but i would a sphere
Thanks

Share this post


Link to post
Share on other sites

my question is generic, but how i can convert a value for ex from -10 ,15 to 0-360?
i must divide by something?

is possible?
What is the name of this operation ? clamp?is there in the glm math library?

Share this post


Link to post
Share on other sites

this works fine , but it have a max of 0.6 for x and 0.4 for the y i would the max to 2pi for the x and pi for y.

Please look into the other thread.

 


my question is generic, but how i can convert a value for ex from -10 ,15 to 0-360?

Assuming you want to map this linearly, you need to do

1. subtract the lower limit, here -10, so that the new lower limit is at 0

     ( -10 .. 15 ) - (-10) => 0 .. 25 

2. normalize the range by dividing by the difference of lower and upper limits, here 15-(-10)=25, so that

     ( 0 .. 25 ) / 25 => 0 .. 1

3. multiply by the desired range, here 360-0=360, so that

     ( 0 .. 1 ) * 360 => 0 .. 360

4. add the desired lower limit, here 0, so that

     ( 0 .. 360 ) + 0 => 0.. 360

Edited by haegarr

Share this post


Link to post
Share on other sites

thanks headgar i confirm xp and yp is correct , also the rotation works fine, the only error is that when i go to the center the mesh rotate around itself is the gimbal lock?

i try with quaternon.

I do not know how to thank you, thanks ,thanks,thanks because i have understand another thing and not only copy paste the code

Share this post


Link to post
Share on other sites


the only error is that when i go to the center the mesh rotate around itself is the gimbal lock?

It is not exactly an error. When the center is crossed during mouse movement, the value of phi jumps by 180 degree. That is intentional, because it gives you the same result as when moving from the start position to the end position in a half-circle. Remember that this implements an absolute control scheme, hence driving the mouse to a specific position should, for that position, yield in a result that is independent on the way you have used to reach the position.

 

As I said earlier, the inherent problem is that a 2D input device is used to control a 3D camera device. The 2 ways I've suggested above describe basic control schemes. To overcome shortcomings where possible, more a sophisticated control scheme need to be developed.

 


a question , is possible to do it with an a sphere and add the roll?
if you say yes i try.
for view the target object in all position.

Roll is not needed to see the object from all orbit positions. I would even say that adding roll to a manually controlled camera makes things "wonky". I would not do so. So now that we are finally speaking about the control scheme itself, what I could envision is a control scheme that

a) uses the current camera position as start,

b) constantly enforces a look-at to the object,

c) creates a heading with a little more than [-180°,+180°], using the horizontal mouse position for this,

d) creates a pitch with a little less than [-90°,+90°], using the vertical mouse position for this,

e) forces roll to be 0,

f) allows to change the orbit radius, e.g. when moving the up/down and pressing a key while doing so,

g) perhaps draws a little circle on the screen that serves as draggable gadget and indicator where the current orbiting is located in the phi/theta parameter space (and in the end also that orbiting mode is activated).

 

Question is still: What control scheme do you want?

Share this post


Link to post
Share on other sites

i think that the existing camera plus g) does all the work,

but how i can see all the object in all position if there is a semisphere?how i can see the back of the object for see all the object in all position if when i reach 90 for ex finish the screen and the semisphere? this for me is important

 

by.

Share this post


Link to post
Share on other sites

for see all the object  can i accumulate little movement of the mouse from when i press to when i release?
so i can see all the object
i add the little step on a sphere and mantain a member variable with the current orientation (a quaternion or matrix4x4)

Share this post


Link to post
Share on other sites


but how i can see all the object in all position if there is a semisphere?how i can see the back of the object for see all the object in all position if when i reach 90 for ex finish the screen and the semisphere? this for me is important

I'm not sure what angle you use for heading right now, phi or theta. phi should go full circle and hence can be used for heading, so then theta would be in [0°,90°] with 0 in the center of the screen and 90° at the circumference of the circle, isn't it? The simplest way is perhaps doing a "linear range mapping" (yippie!) to, I think, [-90°,+90°]. But notice that this means that the center of the screen becomes a "look from downside", a circle with half radius of the hemisphere means a pitch of 0, and the circle around the hemisphere means "looking from above". You may want to exclude the circumference and pole of the hemisphere then. If you want to swap "looking from bottom" and "looking from top" then you need to map to [+90°,-90°]. In the end, when doing such a thing, you pitch as twice as fast as before but use the available space to rotate as twice as far as before.

Share this post


Link to post
Share on other sites

for see all the object  can i accumulate little movement of the mouse from when i press to when i release?
so i can see all the object
i add the little step on a sphere and mantain a member variable with the current orientation (a quaternion or matrix4x4)

an for this what you mean?

Share this post


Link to post
Share on other sites


ps. and what is the name of this operation?

 

linear interpolation. IE: LERP

 

to map a value x in the range x1 through x2 inclusive to a value y in the range y1 through y2 inclusive, the formula is:

 

y = (x-x1)/(x2-x1)*(y2-y1)+y1

 

as shown by Haegarr.

Share this post


Link to post
Share on other sites

 

for see all the object  can i accumulate little movement of the mouse from when i press to when i release?
so i can see all the object
i add the little step on a sphere and mantain a member variable with the current orientation (a quaternion or matrix4x4)

an for this what you mean?

 

Can be done. Would be a bit like a virtual trackball.

Share this post


Link to post
Share on other sites

but with the semisphere i can't do that because if the user click on a point the phi and theta are calculated and are big then i must use a simple delta of the mouse and set it to zero when i the mouse is released.

but i think that i use lerp from the other post.
can you confirm?
what do you think?

I have used your lerp for interpolate in y from 0,600 to 90 -90 and in the x from 0 to 180 all works fine thanks for your formula.

the problems are two:

1)when i press and drags the camera work fine , but when  release the mouse and press again in a new position and drag i have a jump to the new coord from the old where i released and this is an artifact because i see move instantly to new position.

2)i not understand how evitate the gimbal lock or the switch of coords when i pass to 0 0 coords.

Edited by giugio

Share this post


Link to post
Share on other sites

This topic is 827 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this