OpenGL Matrices

This is a discussion on OpenGL Matrices within the Game Programming forums, part of the General Programming Boards category; You're really going to use that algo Bob? I thought you would use depth-first or some form of stack system ...

  1. #16

    Join Date
    May 2005
    Posts
    1,041
    You're really going to use that algo Bob? I thought you would use depth-first or some form of stack system we discussed to find paths, or even a node-based system
    My algorithm is node based. The nodes are placed in the map by map makers. The map gets loaded in, and a ray trace line of sight interaction is performed to get the initial 1's and 0's of the first matrix, then, using my code, it raises the matrices to powers to find the connectivity matrices (then saves the data to file). I am familiar with the other methods (I was at the time of that discussion). I have rejected every other method of pathfinding because mine is faster realtime (you do not have to find the whole path in order to move to the next node along the path, and it never has to back up or retry anything) and I knocked down the compilation time so the compile process is roughly O(n) (it calculates the 'matrices' using data structures that aren't really matrices, and doesn't really do any math to do it).

    I'm especially proud of it because it's very difficult to get something even remotely original to work, and have it be fast enough and use a low enough amount of memory to be acceptable. After I implemented it, I had found a math topic and floyd's all pairs algorithm that is sort of like what I had implemented, but I have yet to see anything else like this in modern games (I wouldn't be surprised if it already is in use though ).

    The problem with my demo that I posted before was that I was having the computer randomly generate a maze, and they came out looking retarded (no offense shamino).

    Well since I've not had calculus in school and am totally self taught.....it looks to me as if I learned linear algebra before calculus
    Yeah, you did. I believe a lot of both theory and practical knowledge is healthy, but gaining practical knowledge through experience is a much more difficult process than taking a university class. Even in theory classes a lot of it is just trusting the processor that the ideas being presented work (as opposed to grappling with the ideas yourself, in whatever arena). Then, once you'ge got a healthy vocabulary of ideas that you accept as valid, you then build upon more abstract ones (bull........ that piles up upon bull........ and always works in the arena of textbooks).

    I had actually failed my first calculus 3 test, with a 55, because I had gone and done it too quickly. I went in to talk to the professor and solved a problem he could not do in class. Then I started talking to him about some of my game programming topics, he realized exactly where I stood in terms of my knowledge, and he raised my test grade by 30 points (even though I technically didn't deserve it). True story (look up Jerry Farlow on umaine's website).
    Last edited by BobMcGee123; 03-15-2006 at 02:53 PM.
    I'm not immature, I'm refined in the opposite direction.

  2. #17
    Absent Minded Programmer
    Join Date
    May 2005
    Posts
    964
    offense? did I miss something ?
    Sometimes I forget what I am doing when I enter a room, actually, quite often.

  3. #18
    User
    Join Date
    Jan 2006
    Location
    Canada
    Posts
    498
    Linear algebra?

    Have you ever gone to high school?

    Don't mean to sound harsh or anything..

    But Cramer's rule isn't exactly linear

    that is algebra 2 material, almost college level algebra :d
    OK, you guys, stop arguing. The reason I haven't studied linear algebra in high school is because I'm not in high school yet. I'm only in middle school, so I think it's normal not to know linear algebra.

    I started programming when I was really young, and so a few years ago I took up game programming. The only reason I know how to use matrices is because I read an article on the internet a few weeks ago on how to use them.

  4. #19
    Registered User
    Join Date
    Mar 2006
    Posts
    3
    http://math.fullerton.edu/mathews/n2...MatrixMod.html

    It has pseudo-code for how to do gaussian-jordan elimination, and an example of how to use that to find the inverse matrix.

    I seem to recall having to write a program to find the inverse of a matrix in september... but that was in september. And it could have just been the matrix transpose. If I find my program (and it looks semi-useful) I'll post it


    EDIT: Ran across this in the 'links' thread.

    http://www.geocities.com/SiliconVall.../matrices.html

    ~Mith
    Last edited by MithTS; 03-15-2006 at 06:40 PM.

  5. #20
    User
    Join Date
    Jan 2006
    Location
    Canada
    Posts
    498
    Thanks. I think I should be able to invert a matrix now.

  6. #21

    Join Date
    May 2005
    Posts
    1,041
    >>OK, you guys, stop arguing.

    I was actually somewhat defending you. And he started it
    I'm not immature, I'm refined in the opposite direction.

  7. #22
    Absent Minded Programmer
    Join Date
    May 2005
    Posts
    964
    Razzle frazzle frigga fraggle!

    *goes to mumble back in his sleep*

    I love this message board.
    Sometimes I forget what I am doing when I enter a room, actually, quite often.

  8. #23
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,590
    Well in D3D you can invert a matrix by doing this:

    Code:
    D3DXMATRIX matInv;
    
    //Create translation matrix as source for testing inverse
    D3DXMATRIX matTrans;
    //100 on x, 200 on y, and 300 on z
    D3DXMatrixTranslation(&matTrans,100.0f,200.0f,300.0f);
    
    
    D3DXMatrixInverse(&matInv,NULL,&matSource);
    Gotta love the D3DX library.

    The NULL is where the determinant variable goes, if you have one which in this case I do not.

    And yes, Bob, it is very hard to create something that has not been done before (and better?) and is equally as efficient and useful. Most game programming problems usually end up using similar algos to solve them. Perhaps this is because games have to be both fast and efficient so there isn't much room for error.

    And now as far as pathfinding it is good to have an algorithm that can do this well, but sometimes I feel it is not. Don't give the AI more information than a normal human player would have at any one point. Sometimes it's not bad to take the wrong path. If we were all running through a maze, it would be very hard to find each other without some type of communication system. If Bob and I were driving somewhere and he didn't know how to get there, if Bob loses sight of me......guess what, he either is screwed, must call me and tell me to slow down and wait, or he can ask for directions which will probably land him nowhere close to where he wants to be. Sometimes game AI is too smart. They have too much knowledge and as such, it makes the game much harder than the same situation would be in real life. Now when you make your AI fallible then the player doesn't mind not being found or shot at every 5 minutes no matter where they go.
    Having superhuman AI really sucks, but having complete idiots also sucks. A happy medium is needed.

    Too smart: Half Life 1, GTA: Vice City (cheaters actually - police spawn at nearest intersection).
    Too dumb: Rainbow Six, No One Lives Forever 1

    Just about right: Mafia.
    Last edited by VirtualAce; 03-16-2006 at 02:06 AM.

  9. #24
    vae victus! skorman00's Avatar
    Join Date
    Nov 2003
    Posts
    594
    A while ago somebody said "don't invert a matrix, it's an expensive operation." That is very true, if you use the algorithm that was given by another poster. That algorithm will get the inverse for any matrix.

    Luckily, you're probably working with a matrix whos axes are 90 degrees of each other. If that is true, then the inverse is equal to the transpose. Don't do that with the position component of your matrix though, because he's not part of the orthogonality (I'm not sure if that's a real word). You can scale him by -1 though to fix that.

    edit: BTW, that's what the D3DX function that Bubba mentioned does.

  10. #25
    Supermassive black hole cboard_member's Avatar
    Join Date
    Jul 2005
    Posts
    1,709
    >> GTA: Vice City (cheaters actually - police spawn at nearest intersection).

    I just started playing that again and the level of AI cheating is thoroughly peeing me off. I'd like to know how the engine works, with so much going on at once. Well I guess not much is happening where you aren't in the map, but you know what I mean.
    Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.

    - Mike McShaffry

  11. #26

    Join Date
    May 2005
    Posts
    1,041
    Don't give the AI more information than a normal human player would have at any one point. Sometimes it's not bad to take the wrong path
    I understand what you are saying. It's just as easy to take the wrong path in my implementation as it is with any of 'the others.' In my opinion, to get pathfinding to really work in a realistic manner, we'd have to ditch all of the current constructs that we have for pathfinding. No A*, none of my implementation, or breadth/depth first etc. Instead, you'd have to implement a low-level cognitive model that recognizes geometry in the world and can perceive it in relation to what it already recognizes (memory and recollection), and in relation to the last time it saw a bad guy. This would be too difficult and inefficient for a simple computer game such as mine. But, what you've been talking about is faking it so that it seems 'just right,' as in Mafia (and I do remember half life 1's pathfinding to be too perfect.)

    Granted, I'm still experimenting and learning, and we'll see how good it really works when I've got a playable demo to release. In fact, I'll probably have a release just to play with the pathfinding.
    I'm not immature, I'm refined in the opposite direction.

  12. #27
    User
    Join Date
    Jan 2006
    Location
    Canada
    Posts
    498
    Yeah, how I used to get the inverse of the modelview matrix was really cheap: if my code was
    Code:
    glRotatef(degree, xvalue, yvalue, zvalue);
    etc, etc
    Then I would do the opposite of my rotations and translations and then grab the modelview matrix, and then do a glLoadIdentity(). But that's only possible if your matrix isn't too complicated.

  13. #28

    Join Date
    May 2005
    Posts
    1,041
    Cheap isn't bad...the only thing that's bad is something that doesn't work.
    I'm not immature, I'm refined in the opposite direction.

  14. #29
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,590
    You are right Bob. All of the present pathfinding algorithms start at the big picture and then narrow it down to the AI actor or player. This is totally incorrect. When you enter a new building, your mind doesn't auto-download the floorplan as soon as you step inside. So in essence, you are a noob in the building and will probably need to ask a lot of people how to get where you want to go. But after repetition, familiarity, and exploration you would soon figure out everything in the building.

    But games do this. If you run into a building to hide from the enemy or setup a trap, the AI characters automatically seem to understand the layout of the building, best places to take cover, and best places to seal the building off. Not very accurate. Part of the intensity of combat simulation is the 'unknown' factor and most, if not all, games have removed this unknown from the AI making the whole thing come off as superhuman.

    Lots of games do this because the core AI code is very sparse and very stupid. So they make pathfinding superhuman so as to cover up the gaping holes in their AI code. After all if you die quickly you won't be able to make fun of the AI when they get stuck in the stairwell, or the nearest door.

    Wanna know how far we've come in AI? On any FPS, tick the enemy dudes off and then run into a room with a door. As the AI approaches the door, close it, open it and fire, close it, etc. etc. Or you can stand behind the door and gun them down as they come rushing in like buffoons. Most games can't even deal with doorways, stairwells, ladders (another fun one to test), geography features (I've seen a lot of AI just leap off of huge cliffs hoping to get to you - leading to their own demise.), etc., etc.

    I'm not impressed with any AI in current games. It just sucks.

    And as for the matrix issue, inverting a matrix is expensive but a lot of 3D situations require it. Inverting a matrix essentially 'undoes' the transformation. So if you are in camera space and you invert the matrix, you will be in world space, etc., etc.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Linking OpenGL in Dev-C++
    By linkofazeroth in forum Game Programming
    Replies: 4
    Last Post: 09-13-2005, 10:17 AM
  2. OpenGL Window
    By Morgul in forum Game Programming
    Replies: 1
    Last Post: 05-15-2005, 12:34 PM
  3. OpenGL .dll vs video card dll
    By Silvercord in forum Game Programming
    Replies: 14
    Last Post: 02-12-2003, 06:57 PM
  4. OpenGL and Windows
    By sean345 in forum Game Programming
    Replies: 5
    Last Post: 06-24-2002, 10:14 PM
  5. opengl code not working
    By Unregistered in forum Windows Programming
    Replies: 4
    Last Post: 02-14-2002, 09:01 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21