Sign in to follow this  
Narf the Mouse

SimpleRTS (In which I get sick of the theoretical)

Recommended Posts

Most of my programming has been hobbyist-theoretical-prototyping and reading more blogs than is probably healthy. I'm sick of it. I wanna make a game.

I'm going to make a game, using my current game engine.

[url=http://www.gamedev.net/blog/1444/entry-2254443-simplerts-update-1/]Link[/url] to journal.

I'm asking for advice, help, comments and critique.

Thanks.

Share this post


Link to post
Share on other sites
Good luck! Making a finished game is a great way to achieve personal satisfaction and keep moving forward [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img]
I will bookmark your journal to follow it.

Share this post


Link to post
Share on other sites
[quote name='Bacterius' timestamp='1333851367' post='4929210']
Good luck! Making a finished game is a great way to achieve personal satisfaction and keep moving forward [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img]
I will bookmark your journal to follow it.
[/quote]

you can bookmark such things?
Then i will to!

Share this post


Link to post
Share on other sites
[quote]you can bookmark such things?
Then i will to![/quote]
I just meant bookmarking the link to the journal on my browser to remind to have a look at it every now and then. I don't know if there is a more advanced "follow" feature on gamedev.

Share this post


Link to post
Share on other sites
Thanks. Up to this point, most of what I've done (even the games) have been exercises. For example, "What if I wrote a roguelike based on the idea of compositing simple VIs?"

For this one, I'm not going to experiment. Simplest methods all the way.

But first, I have to figure out [url=http://www.gamedev.net/topic/623087-gah-windows-whats-windows-message-0x031f/page__p__4929196__fromsearch__1#entry4929196]what's up with my Window class[/url] in my engine...

Share this post


Link to post
Share on other sites
Ok, according to Google, an unproject can be accomplished by multiplying a vector containing the mouse XPos and YPos, plus a depth value for the Vector.Z, by the inverse of your ViewProjection matrix.

That is to say, Transform( Vector3( Mouse.XPos, Mouse.YPos, Depth), Camera.ViewProjection.Inverted() ), to use psuedocode.

Is this a Normal transform, or a Point transform? And what do I use for Depth values to get the rayBegin (I'm trying to intersect with the ground plane) and rayEnd vectors?

Google keeps on wanting to tell me about UN projects when I do a search for unproject, even if I add DirectX to the search.

Thanks.

Share this post


Link to post
Share on other sites
Hmm...If I multiply by the inverse projection, I get really small vectors that don't reflect object space at all. OTOH, just multiplying by the inverse View isn't fully accurate.
[code]
Vector4 mouseVector = new Vector4(input.Mouse.State.XPos - display.ScreenRectangle.Left, input.Mouse.State.YPos - display.ScreenRectangle.Top, 0F, 1);
mouseVector.X = (mouseVector.X - (display.ScreenRectangle.Width / 2)) / 2;
mouseVector.Y = (mouseVector.Y - (display.ScreenRectangle.Height / 2)) / 2;
Vector4 rayBegin2 = new Vector4(mouseVector.X, -mouseVector.Y, 0, mouseVector.W) * scene.GetCamera(mainCameraName).View.Inverted();
Vector4 rayEnd2 = new Vector4(mouseVector.X, -mouseVector.Y, 10000, mouseVector.W) * scene.GetCamera(mainCameraName).View.Inverted();
Vector3 rayBegin = new Vector3(rayBegin2.X / rayBegin2.W, rayBegin2.Y / rayBegin2.W, rayBegin2.Z / rayBegin2.W);
Vector3 rayEnd = new Vector3(rayEnd2.X / rayEnd2.W, rayEnd2.Y / rayEnd2.W, rayEnd2.Z / rayEnd2.W);
[/code]

Share this post


Link to post
Share on other sites
[quote]Google keeps on wanting to tell me about UN projects when I do a search for unproject, even if I add DirectX to the search.[/quote]
Hmm for me hitting "directx unproject" brings up a bunch of results about how to unproject vectors in DirectX :P

What are you trying to do here? Are you trying to calculate a camera ray according to where the mouse is? In that case you just need to multiply your screen point as a [color=#ff0000][b]normalized coordinate between -1 and +1[/b][/color] with depth equal to 1, with the inverse of the view matrix. This gives you the location in screen space of the "virtual screen pixel". Now you just subtract the camera position to it, then normalize and that gives you the ray direction.

Note that since the virtual screen is always a plane in screen space, you can optimize this by calculating the four corners of the screen and doing a simple bilinear interpolation to obtain any other point. Also, because a standard view (lookat) matrix is always orthogonal, its inverse is equal to its transpose, i.e. M^-1 = M^T.

[color=#ff0000]Remember that math functions typically have *no* notion of what resolution/aspect ratio you are using, and so assume normalized coordinates, normalized distances, normalized vectors, normalized everything, so that they can operate in the most general way possible.[/color]

If this is your problem I can give you the camera code of my path tracer (ray tracer) for you to look at. It's in Free Pascal but it should be easily understandable.

Share this post


Link to post
Share on other sites
No worries; I got it working. :)
[code]
Vector4 mouseVector = new Vector4(input.Mouse.State.XPos - display.ScreenRectangle.Left, input.Mouse.State.YPos - display.ScreenRectangle.Top, 0F, 1);
mouseVector.X = (mouseVector.X - (display.ScreenRectangle.Width / 2)) * 2;
mouseVector.Y = (mouseVector.Y - (display.ScreenRectangle.Height / 2)) * 2;
mouseVector.X = mouseVector.X / display.ScreenRectangle.Width;
mouseVector.Y = mouseVector.Y / display.ScreenRectangle.Height;
Vector4 rayBegin2 = new Vector4(mouseVector.X, -mouseVector.Y, 0, mouseVector.W) * scene.GetCamera(mainCameraName).Projection.Inverted();
Vector4 rayEnd2 = new Vector4(mouseVector.X, -mouseVector.Y, 1, mouseVector.W) * scene.GetCamera(mainCameraName).Projection.Inverted();
rayBegin2 *= scene.GetCamera(mainCameraName).View.Inverted();
rayEnd2 *= scene.GetCamera(mainCameraName).View.Inverted();
Vector3 rayBegin = new Vector3(rayBegin2.X / rayBegin2.W, rayBegin2.Y / rayBegin2.W, rayBegin2.Z / rayBegin2.W);
Vector3 rayEnd = new Vector3(rayEnd2.X / rayEnd2.W, rayEnd2.Y / rayEnd2.W, rayEnd2.Z / rayEnd2.W);
[/code]
Now, to stick the code in a function...

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

Sign in to follow this