Jump to content
  • Advertisement
Sign in to follow this  
giugio

orbit camera math

This topic is 1046 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
Advertisement

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


ps. and what is the name of this operation?

I don't know whether this has an own name at all. If I would have to name it, I would probably use something like "(linear) range mapping".

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

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.

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