Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Point of pivot for 3d sprite - help

Author
Message
Daryn Alsup
16
Years of Service
User Offline
Joined: 5th Jul 2008
Location: In your head... dun dun DUN!!!!!!!!
Posted: 11th Nov 2009 23:40
So I have a sphere. On this sphere are locations on which the player can click. I am hoping to create a 3d sprite pointed towards the screen... but the sphere rotates and at times and depending on the location, some clickable areas will be come unclickable. Any Idea how to first set the pivot point of the 3d sprite relative to the sphere's center?

Jack and Jill went up a hill to fetch a pale of water... but Jill got tired of his s#%& so she shot him.
Kira Vakaan
15
Years of Service
User Offline
Joined: 1st Dec 2008
Location: MI, United States
Posted: 13th Nov 2009 03:40
A while ago I wrote some ideas for a Metroid Primeish-style menu. Does this help? Please feel free to ask about anything. I don't know what your math background is, but I use transform matrices to do a lot of the work. I'm perfectly willing to try to explain if that's an issue.

The panels change color when hovered over and when clicked on. Use either the middle or right mouse buttons to rotate the whole thing.

Daryn Alsup
16
Years of Service
User Offline
Joined: 5th Jul 2008
Location: In your head... dun dun DUN!!!!!!!!
Posted: 13th Nov 2009 07:45 Edited at: 13th Nov 2009 08:25
Actually - this is close to what I am seeking... after thinking about it, I think what I need is to raycast from the camera position to a location on a turning sphere. Then store that location and place a sprite using a function that converts the 3d rotating coordinates into 2d coordinates. I can hide the sprite when the coordinates aren't being cast to the screen... Any idea how to do this?

Jack and Jill went up a hill to fetch a pale of water... but Jill got tired of his s#%& so she shot him.
Kira Vakaan
15
Years of Service
User Offline
Joined: 1st Dec 2008
Location: MI, United States
Posted: 13th Nov 2009 10:40 Edited at: 13th Nov 2009 10:42
Edit: Oops, didn't see your edit. Hold on, lemme think
Daryn Alsup
16
Years of Service
User Offline
Joined: 5th Jul 2008
Location: In your head... dun dun DUN!!!!!!!!
Posted: 13th Nov 2009 12:12
I've already found a way to convert the coordinates back into 2d using a reverse pick function (like the pick commands in reverse ) now all I need to do is find a way to update the 3d position as the sphere rotates and store them, then using the anti-pick-functions turn those 3d positions back into 2d and place the sprite that way. Its just the updating of the position on the sphere (as it turns) that I need help with

Jack and Jill went up a hill to fetch a pale of water... but Jill got tired of his s#%& so she shot him.
Kira Vakaan
15
Years of Service
User Offline
Joined: 1st Dec 2008
Location: MI, United States
Posted: 13th Nov 2009 13:38
Alright, well there was a problem I encountered while trying to get the sphere to rotate like I got the panels to. For the panels, I rotated their centers in World space every time, but with an object like a sphere, any transformations done on its vertices are done in Object space. One way I got around this was to never rotate the actual object, but to treat each vertex of the sphere like a separate point in World space by editing vertex data in a mesh I made of the sphere. Then I'd switch out the root limb of the object for the edited sphere mesh. Of course, if you wanted the camera to move at all, you'd have to transform everything into View space and then rotate each vertex. It gets a little complicated.

Actually, I'm curious how you took the 3D coordinates and turned them into 2D coordinates. The first thing that comes to mind is touching DBPro's icky vectors and getting the view and projection matrices to work on it. We could both do some learning.

Here's an example demonstrating how to edit the vertex data of the sphere to get it to rotate the way we want it to:


To really understand what's going on requires a knowledge of trig, vectors, matrices, and vector spaces. I'm going to try to come up with a really, really abridged crash course. Of course, if you already know some of this stuff, that's just wonderful, but if not, and my course doesn't help enough, I can try to go more in-depth.

Trig gets covered in most high school algebra classes, so I won't go over that, but if it's new, just check wikipedia for Trigonometric Functions, and there's an in-depth article on it.

Vectors, for our purposes, are essentially a group of three coordinates (X,Y,Z). The vectors I use in the example have a fourth component, W, but that's used for other things. For these purposes, W should always contain 1.0. For example, we'd use the vector: [4,2,5,1] to represent the 3D coordinate (4,2,5).

Matrices are also covered in most high school algebra classes, and so I won't go over how to multiply them together, which is something you'll need to know how to do. The matrices I'm using here are 4x4 and are transform matrices, meaning they are intended to transform a vector in some way (Note: Transforming a vector with a matrix works the same as multiplying a 4x4 matrix by a 4x1 matrix, and a transformation can be a rotation, a translation, or a scaling of a vector).

A vector space is essentially represented by three axes, a Right vector, an Up vector, and a Look vector, or X, Y, and Z axes. In world space, the axis vectors are [1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1], or when drawn as a matrix, you can see
, which is the identity matrix you probably learned about, where the left most column (not row) is the Right vector, the next is the Up, and the next is the Look. When you use the position object function, you specify coordinates in world space. Each object has its own vector space, called object space, or model space. In this space, all of the vertices are given as coordinates in reference to the center of the object, and not the world. There's another space called view space, or camera space, in which everything is given in reference to the camera's position and orientation. There's even another space called clip space, or screen space, in which everything is still around the camera, but has been distorted to look like it shrinks with distance. This is the final output of the camera, and is the space you always look at the world through.

Now that I've kinda explained that, we can see how to use it all. We use transform matrices to transform vectors (coordinates) from one space to another. In 3D graphics lingo, an object's World Matrix is a transform matrix that will transform a vector from that object's space into world space when multiplied together. The View Matrix is a matrix that takes any world vector and transforms it into View space, and the Projection Matrix takes view coordinates and puts them into Clip space. You get the idea.

But a transform matrix doesn't always have to change spaces. You can use it to perform any rotation, translation, or scaling you want to (but for translation and scaling, it's much less computationally expensive just to add some number or multiply some number with the coordinates. Matrices are usually used just for rotation.). In the example, I rotate the panels' centers around the world's axes, by creating a matrix that represents the desired rotation. I've written little commands to do this simply. I also rotate the sphere's vertices directly in world space, so I don't have to deal with object space. In the example, these lines of code create the rotation matrix I use to do all this:

First, I create a matrix representing only the Y axis component of the rotation and then I multiply it by a matrix representing the X component. When you multiply matrices together, you create a kind of "matrix stack", in which the first matrix on the stack is the last to take effect on the vector you're transforming. In this case, the X rotation takes place before the Y.

Whew, I've written a lot, so I'm going to take a break and wait for your questions.
Daryn Alsup
16
Years of Service
User Offline
Joined: 5th Jul 2008
Location: In your head... dun dun DUN!!!!!!!!
Posted: 13th Nov 2009 15:23 Edited at: 13th Nov 2009 15:40
Okay so from what you're telling me (and from what I have had to read a few times ) I'll need to transform coordinates from object to world (vertexdata) and then raycast. If the mouse is clicked on a valid location (a vertex on the object) these coordinates will then be stored and then by using a for-next loop for the vertex positioning, I can then update the position of any 2d object by transforming the 3d world vector to a 2d screen vector? just a guess

that also means I need to grab a distance from a click (a radius around the mouse) so that the closest vertex (acting like a valid clickable area) is the one from which the 3d coordinates will be changed into 2d

Jack and Jill went up a hill to fetch a pale of water... but Jill got tired of his s#%& so she shot him.
Daryn Alsup
16
Years of Service
User Offline
Joined: 5th Jul 2008
Location: In your head... dun dun DUN!!!!!!!!
Posted: 14th Nov 2009 07:58
I'm afraid I have no clue where to start. Basically I gather that I need to make the vertexes as clickable areas. how do I do this. Then I need to convert this location back into 2d coor. the position of the vertexes must keep the location of the sprite while rotating. I have a terraforming demo out using vertexes, raycasting and vector commands. Maybe using some things from this strip of code could help.

Jack and Jill went up a hill to fetch a pale of water... but Jill got tired of his s#%& so she shot him.
Kira Vakaan
15
Years of Service
User Offline
Joined: 1st Dec 2008
Location: MI, United States
Posted: 14th Nov 2009 10:16 Edited at: 14th Nov 2009 10:21
Whew, I think I've accomplished just that.

Use the left mouse button to click on a vertex, the right or middle to rotate the sphere, and hold shift to display the sphere in wireframe.



There's a lot of math involved, such as knowing how to calculate a View, Projection, and a Screen matrix, and knowing how to determine whether or not a vector is pointing away from another using their dot product.

I've tried to write detailed comments in the code, but you can only do so much there. The rest I'll try to explain out here. Wow, this little project has really got me thinking! Thanks.

I've done all of this using vector and matrix functions that I wrote, but I'm sure you could come up with a way using DBPro's commands if you were so inclined. It might be a little faster that way, but I think this way's a whole lot easier.

If you have questions about certain calculations, please ask away.

Edit: Just a thought, I think you should use some kind of icosphere, or geodesic sphere on which all vertices are spaced out evenly, so you don't have a concentration of clickable areas at the top and bottom. Just about every modeling package out there has this kind of sphere as a primitive.
Daryn Alsup
16
Years of Service
User Offline
Joined: 5th Jul 2008
Location: In your head... dun dun DUN!!!!!!!!
Posted: 15th Nov 2009 07:24
Okay - this is it!!!! What I want to know is, how can I zoom in and out and this code work. Also, the turning of the planet should only happen when at the edges of the screen. Reason being the planet is/should be slowly rotating left at 0.015. How can I edit this code to allow that?

Jack and Jill went up a hill to fetch a pale of water... but Jill got tired of his s#%& so she shot him.

Login to post a reply

Server time is: 2024-11-24 22:53:38
Your offset time is: 2024-11-24 22:53:38