Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (499)
Games in Android Showcase (118)
games submitted by our members
Games in WIP (567)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Projection Matrix  (Read 4967 times)
0 Members and 1 Guest are viewing this topic.
Offline cborders

Junior Member





« Posted 2005-11-10 21:11:34 »

This is most likely the wrong place for this, but I couldn't think of a better one.  Does anyone know of any place that I can look for help in translating an equation into a matrix?  See, I have a set of equations for calculating a projection and I want to translate that into matrix form so I can lod it into the projection matrix, but my linear algebra is pretty week!
Offline arne

Senior Member




money is the worst drug- we should not let it rule


« Reply #1 - Posted 2005-11-11 06:33:21 »

simple:
if you have equations like
a1*x1+a2*x2+a3*x3+a4*x4=0
b1*x1+b2*x2+b3*x3+b4*x4=0
c1*x1+c2*x2+c3*x3+c4*x4=0
d1*x1+d2*x2+d3*x3+d4*x4=0

the matrix M looks like this:

             a1 a2 a3 a4
M=      b1 b2 b3 b4
             c1 c2 c3 c4
             d1 d2 d3 d4

If you want to test if your solution a row-vector x is the solution to your equation system, simply calculate
Mx
and if every element of the result is 0 you've found a solution.

Arne

EDIT: I hope I've understood this thing correctly..., but actually I'm pretty sure it's correct.

:: JOODE :: Xith3d :: OdeJava ::
Offline cborders

Junior Member





« Reply #2 - Posted 2005-11-11 16:10:20 »

I think that's correct too!  The problem is that the equation is not that simple!  It's meant to translate the current point of a map as a Latitude/Longitude pair into an (x, y) screen location based on a center point, also in Lat/Long.  Different center points are the same as spinning a globe to look at different points on the Earth.  Now we do the whole thing in software, so that any time someone wants to spin the world we have to go through the entire list of points (currently around 80,000) and apply the new projection.  The way it works currently is ok but I thought that if we could convert this equation into matrix form we could put it in the Projection Matrix and do it all in hardware.  That way when the user wanted to spin the globe all we would need to do would be to re-calculate that matrix and the rest would happen auto-magically.

Here are a couple of screenshots to show what I am talking about:
Here the center point is in the middle of the US


Here the center point is in Europe


And here is the equation that we use
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline K.I.L.E.R

Senior Member




Java games rock!


« Reply #3 - Posted 2005-11-13 08:12:33 »

Very easy to do.

Create several matrices with a meaning for x, y, z, and k.
Multiply the matrices but make sure you post multiply to get correct results in OpenGL.

EDIT:
Almost got it but the k is peeing me off.

EDIT2:
I'm having 2nd thoughts if it's even possible to do at my level of maths. Embarrassed

EDIT3:
It's possible to do but it's very wasteful calculation wise.
At least wasteful given the state I have it in.
It involves recalculating 'k' twice.

I'm removing the sqrt right now as I type.
If you're waiting it might be a bit of a while. Wink

It's killing me and so I went and used a search:
http://www.mathworks.com/access/helpdesk/help/toolbox/aeroblks/directioncosinematrixeceftonedtolatitudeandlongitude.html

Vorax:
Is there a name for a "redneck" programmer?

Jeff:
Unemployed. Wink
Offline cborders

Junior Member





« Reply #4 - Posted 2005-11-13 20:19:27 »

If you could post what you have I would LOVE to see it.  Even calculating k' twice per change is better than what we do now!  We have to go through and calculate k', x and y 80,000 times!
Offline K.I.L.E.R

Senior Member




Java games rock!


« Reply #5 - Posted 2005-11-14 10:28:56 »

I gave up. Paper => bin.
Sorry.

I couldn't get a good result so I gave up.

However I will try again after my exams end (end of this week).

Vorax:
Is there a name for a "redneck" programmer?

Jeff:
Unemployed. Wink
Offline cborders

Junior Member





« Reply #6 - Posted 2005-11-14 16:12:06 »

Just the fact that you tried is awesome!  Thank you!  Grin
Offline darkprophet

Senior Member




Go Go Gadget Arms


« Reply #7 - Posted 2005-11-15 02:04:19 »

another solution could be uploading that operation to a vertex shader. Should be very easy to do and should give you a good increase in frame rate too. If you are using an orthographic projection, then setting the gl_Position in the shader should directly map onto the x,y in screen space.

You could cheat and use spherical coordinates to map the points to X, Y and Z and the equations are no where near as complicated as that:

x = r cosA sinB
y = r sinA sinB
z = r cosB

where r = distance of point from centre of earth...Or does that not suit your needs?

<Offtopic>Man, UK is sooo tiny on that map! Its small in reality, but daaaam does it look small on that map!</Offtopic>

Friends don't let friends make MMORPGs.

Blog | Volatile-Engine
Offline cborders

Junior Member





« Reply #8 - Posted 2005-11-15 02:27:34 »

Do all cards support that?  We are already making a Java2D version and an OpenGL version incase the client machine is too out-dated.  Other than that concern it sounds like an awesome idea!  I am very keen to know how well vertex shaders are supported!
Offline darkprophet

Senior Member




Go Go Gadget Arms


« Reply #9 - Posted 2005-11-15 10:24:30 »

Do all cards support that?  We are already making a Java2D version and an OpenGL version incase the client machine is too out-dated.  Other than that concern it sounds like an awesome idea!  I am very keen to know how well vertex shaders are supported!

Thats the thing...no they dont. Only the most recent cards support vertex shaders, but NV's OpenGL support is immaculate and you can probably find that older cards do support them. Shaders are part of the GLSL specificiation and you need OpenGL 1.5 for them. However, there are vertex programs which are basically asm files to do the same as the shaders and those are more widely supported (even by ati cards!). So it looks like your going to have to dig into some asm coding then Wink

DP

Friends don't let friends make MMORPGs.

Blog | Volatile-Engine
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline cborders

Junior Member





« Reply #10 - Posted 2005-11-15 13:05:17 »

That's cool, I actually miss asm! Wink Thank you for the tip!  I am very excited to see how it goes!
Offline cborders

Junior Member





« Reply #11 - Posted 2005-11-15 15:01:27 »

I read that vertex programs bypass the standard transform and lighting instructions.  What exactly does that mean?  For example if I wrote a vertex program to perform the projection calculations that I need would I still be able to move the projected drawing around using glTranslate()?
Offline Orangy Tang

JGO Kernel


Medals: 56
Projects: 11


Monkey for a head


« Reply #12 - Posted 2005-11-15 15:25:50 »

Vertex shaders completely replace the existing fixed function transformation, so you have to do the projection of vertices from world to screen space yourself. Fortunatly this is rather easy. Smiley glTranslatef etc. all operate on the current matrix (usually the modelview matrix for glTranslatef). You can access this (and the other matrices) in your vertex shader so if you want to you can still use it.

If you know your users will have semi-recent hardware you can use GLSL, which is a vertex/fragment shader language which looks rather like C. This tends to be somewhat easier than those (rather limited) asm-style shader languages. GLSL requires a GF FX or equivilent, which is about 3 or so years old now so should be pretty common.

[ TriangularPixels.com - Play Growth Spurt, Rescue Squad and Snowman Village ] [ Rebirth - game resource library ]
Offline cborders

Junior Member





« Reply #13 - Posted 2005-11-15 15:59:36 »

Unfortuantely I can't guarantee anything about the hardware so it looks like I am off to asm land!  I have a lot of reading to do! Smiley
Offline Orangy Tang

JGO Kernel


Medals: 56
Projects: 11


Monkey for a head


« Reply #14 - Posted 2005-11-15 16:03:43 »

If you can't guarantee anything about the hardware you're pretty much out of luck - even asm shaders require a level of hardware support which isn't present in all cards, so you need a fixed function fallback anyway.

[ TriangularPixels.com - Play Growth Spurt, Rescue Squad and Snowman Village ] [ Rebirth - game resource library ]
Offline cborders

Junior Member





« Reply #15 - Posted 2005-11-15 16:31:06 »

 Sad Ok, so I guess it's back to trying to figure out how to convert that equation into a matrix!
Offline K.I.L.E.R

Senior Member




Java games rock!


« Reply #16 - Posted 2005-11-17 10:40:07 »

Don't feel bad.
My maths exam is tomorrow which leaves me a lot of time after that to help you in that regard. Smiley

Vorax:
Is there a name for a "redneck" programmer?

Jeff:
Unemployed. Wink
Offline darkprophet

Senior Member




Go Go Gadget Arms


« Reply #17 - Posted 2005-11-17 13:40:35 »

Dam Intel graphics cards! Otherwise, everything in the world would be merry... Roll Eyes

Friends don't let friends make MMORPGs.

Blog | Volatile-Engine
Offline K.I.L.E.R

Senior Member




Java games rock!


« Reply #18 - Posted 2005-12-05 05:59:11 »

I just have to say that I've re-tried this again and have come to the conclusion that you need a new equation that is mathematically equivalent.
Find yourself a mathematician. Smiley

Vorax:
Is there a name for a "redneck" programmer?

Jeff:
Unemployed. Wink
Offline cborders

Junior Member





« Reply #19 - Posted 2005-12-05 15:21:25 »

 Grin  Thank you for trying!!  I really do appreciate it!  We have decided that it is beyond us too, so we are just going to make the math as efficient as possible and try to buy speed everywhere else!!
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Pippogeek (39 views)
2014-09-24 16:13:29

Pippogeek (30 views)
2014-09-24 16:12:22

Pippogeek (19 views)
2014-09-24 16:12:06

Grunnt (43 views)
2014-09-23 14:38:19

radar3301 (25 views)
2014-09-21 23:33:17

BurntPizza (62 views)
2014-09-21 02:42:18

BurntPizza (32 views)
2014-09-21 01:30:30

moogie (37 views)
2014-09-21 00:26:15

UprightPath (50 views)
2014-09-20 20:14:06

BurntPizza (54 views)
2014-09-19 03:14:18
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!