Jump to content
  • Advertisement
Josheir

C++ OpenGL, Translating a Sphere

Recommended Posts

Posted (edited)

All orbital cameras are orbiting, while not all orbiting cameras are in orbit ...

Or so. Or differently. Or vice versa. Random thoughts, it is time quit. Til tomorrow.

🙂

Edited by Green_Baron

Share this post


Link to post
Share on other sites
Advertisement
Posted (edited)

Okay, here is a link to what I mean, I have a suspicion that no one really understood me!

I am trying to get this code too.  However, the code is in Java.


Sincerely, 

Josheir

Edited by Josheir

Share this post


Link to post
Share on other sites

The video you linked to (thanks for providing that by the way) shows a camera that's always directly behind and above the target. Is that really what you want? Do you want the sphere itself to rotate, like the character in the video? Or do you want the sphere to remain stationary (until it's propelled of course), and for the camera to rotate around it?

Share this post


Link to post
Share on other sites
Posted (edited)

It really is what I want.  The character in the video doesn't rotate.  The ball remains stationary and than the camera just follows it like it's doing.  It really is simple, I guess.

 

The camera doesn't rotate.

Edited by Josheir

Share this post


Link to post
Share on other sites
3 minutes ago, Josheir said:

The character in the video doesn't rotate.

Hm, well, the character in the video does rotate (or at least that would seem to be the most parsimonious interpretation), so it seems we may be at a bit of an impasse here 😶

Anyway, there are multiple ways you could get the behavior in that video. For example, you could transform an appropriate offset by the sphere's model/world transform to yield a camera position in world space, and then use a 'look at' transform to place the camera at that position and aim it at the sphere.

Share this post


Link to post
Share on other sites
2 hours ago, Josheir said:

The character in the video doesn't rotate.

 

1 hour ago, Zakwayda said:

the character in the video does rotate

Depends on what space you're talking about, which is where I believe the confusion comes from. In world space, both the camera and the character rotate. In camera space, however, the character doesn't rotate.

You can see the intended result here, I believe -- look for when the player adjust their character's putting direction:

 

When the player taps to change direction, the character orbits the hole, always rotating to face it (or well, be perpendicular to it, for putting purposes), and the camera is behind the player (imagine a line that goes from the hole and extends through the player).

With this setup, it looks like the character isn't rotating -- in camera space. If one were to swap to a stationary camera, one would see the character orbiting and rotating around the hole.

 

Share this post


Link to post
Share on other sites
3 minutes ago, Lactose said:

Depends on what space you're talking about, which is where I believe the confusion comes from. In world space, both the camera and the character rotate. In camera space, however, the character doesn't rotate.

Sure, since in the video the camera is fixed relative to the player, it's trivially true that the player doesn't rotate relative to the camera. It's world space I was referring to.

The reason I was referring to world space is that everything Josheir has described (e.g. this being a golf game or golf-like game involving a ball, but with no mention - so far at least - of any sort of player character) would suggest an object that doesn't rotate in world space, and an orbital camera that moves around it. The video in question however shows the opposite of that: an object that does rotate in world space, with a camera that doesn't rotate around it. As such, I was skeptical that the video in question actually represents the desired behavior.

In any case, I did offer a suggestion as to how to get the behavior in the video, in case that is in fact what Josheir is after, so maybe that'll be of some help.

Share this post


Link to post
Share on other sites

Well, when the world is created it uses a view projection.  When I try to move the ball straight it doesn't, it moves where the original forward direction was.  This seems to suggest to use the view projection again but perhaps it's inverse.

Sound right?

Josheir

Share this post


Link to post
Share on other sites

Let's call it a third person camera (orbiting or not). The most simple way to do it I can imagine is taking the sphere model matrix and invert it (let's call it inv_mdl) and take this as a base. Then for rotating your camera all you need is yaw because the camera is automatically rotated with the model already. And you need to go some distance away from the sphere otherwise you'll end up inside it. You can do that before rotating by translating along the negative z-axis. Then you apply the rotation matrix and last the inv_mdl matrix.

mat_view = inv_mdl * cam_rot * cam_transl; // This should be your camera matrix

Share this post


Link to post
Share on other sites

To me it seems you should first read a bit about matrices and transforms and play with them in a simple application. You have usually three kind of matrices (there can be more but let's keep it simple). World, View and Projection matrix. They each use a different coordinate system with a different origin. This is meant with space. So a vector ( 0, 0, 1 ) in camera space is different from the same vector in world space. You can ignore the projection matrix for now and just keep in mind that it projects the 3D world on your 2D screen and needs to be applied in the end. So my advice is you should get familiar with the other two spaces. There is also object space which you need in this case. Have a look at the link in my first post. What applies to the view matrix in terms of the axes (which is the camera space) applies to any other matrix as well.

Share this post


Link to post
Share on other sites

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

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