Java-Gaming.org
 Featured games (81) games approved by the League of Dukes Games in Showcase (497) Games in Android Showcase (114) games submitted by our members Games in WIP (563) games currently in development
 News: Read the Java Gaming Resources, or peek at the official Java tutorials
Pages: [1]
 ignore  |  Print
 Projection Matrix  (Read 4952 times) 0 Members and 1 Guest are viewing this topic.
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!
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 ::
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
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.

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.

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

Junior Member

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

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

Senior Member

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

Senior Member

 « 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

DP

Friends don't let friends make MMORPGs.

Blog | Volatile-Engine
cborders

Junior Member

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

That's cool, I actually miss asm! Thank you for the tip!  I am very excited to see how it goes!
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()?
Orangy Tang

JGO Kernel

Medals: 56
Projects: 11

 « 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. 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 ]
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!
Orangy Tang

JGO Kernel

Medals: 56
Projects: 11

 « 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 ]
cborders

Junior Member

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

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

Senior Member

Java games rock!

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

My maths exam is tomorrow which leaves me a lot of time after that to help you in that regard.

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

Jeff:
Unemployed.
darkprophet

Senior Member

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

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

Friends don't let friends make MMORPGs.

Blog | Volatile-Engine
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.

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

Jeff:
Unemployed.
cborders

Junior Member

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

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.
 BurntPizza (22 views) 2014-09-19 03:14:18 Dwinin (35 views) 2014-09-12 09:08:26 Norakomi (62 views) 2014-09-10 13:57:51 TehJavaDev (90 views) 2014-09-10 06:39:09 Tekkerue (44 views) 2014-09-09 02:24:56 mitcheeb (65 views) 2014-09-08 06:06:29 BurntPizza (48 views) 2014-09-07 01:13:42 Longarmx (35 views) 2014-09-07 01:12:14 Longarmx (40 views) 2014-09-07 01:11:22 Longarmx (37 views) 2014-09-07 01:10:19
 BurntPizza 37x Riven 18x Rayvolution 18x princec 17x basil_ 16x ags1 16x KevinWorkman 15x LiquidNitrogen 12x kevglass 12x nsigma 11x theagentd 11x deathpat 9x HeroesGraveDev 9x The Lion King 7x Gibbo3771 6x cylab 6x
 List of Learning Resources2014-08-16 10:40:00List of Learning Resources2014-08-05 19:33:27Resources for WIP games2014-08-01 16:20:17Resources for WIP games2014-08-01 16:19:50List of Learning Resources2014-07-31 16:29:50List of Learning Resources2014-07-31 16:26:06List of Learning Resources2014-07-31 11:54:12HotSpot Optionsby dleskov2014-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