Page 1 of 3 123 LastLast
Results 1 to 10 of 29

Thread: Matrix unit

  1. #1

    Matrix unit

    Two years ago I did add a 2d,3d,4d matrix unit to FPC, and one of my targets was game developers. I studied some games written in FPC and they use their own matrix unit.

    So my questions are:
    * Are you aware that FPC has a matrix unit?
    * Do you think it suits the needs of games?
    * If you implemented one yourself, why did you do so?

  2. #2

    Matrix unit

    Hi,

    I am not a FPC user so i would say no to your first question, if you matrix unit handle most needed matrix operations then yes it should suit for game development.

    * If you implemented one yourself, why did you do so?

    I found interesting this question, why some one would implement somthing from scracht if somthing already exist?...

    I did most my own vector, matrix units first, i think those are stuf that you learn how to do it at the same time you learn for what they are good for; i mean i did not know that i needed to google for an unit that does dot and cross product in vectors until the day i read an article about vector math which teach why those calcs are needed and it also include how to do those calcs; so i think part of the procces of learning those stuf including actually coding those stuff too; i am sure that is why everytime i saw a source coded project released i found they most the time use his own vector and matrix units.

    By the way, there is a well know unit called geometry.pas which include matrix and vector procedures but coded in assembler, so most people (like me) could think that should be run lot faster!, so maybe it could be a good idea to copy/paste those version, :roll:

    Another reason why i should preffer to code somthing my self is becouse somtimes programmers ARE SO LAZZY for document properly the units they release to the public; they like to give program examples instead; they say "please learn how to use my unit from this ready to run example" instead of of documenting exactly what the procedures are for and what the parameters mean. I preffer to expend two months coding for somthing my self but i will know fully how it works than expend 15 days figuring out more or less how works someone else code but not knowing fully if i am using it properly.

    tp

  3. #3

    Matrix unit

    No, I didn't know! I can't believe I never noticed it before. I will have to try it out.
    [size=10px]"In science one tries to tell people, in such a way as to be understood by everyone, something that no one ever knew before. But in poetry, it's the exact opposite." -- Paul Dirac[/size]

  4. #4

    Matrix unit

    So if I declare a matrix like so...

    [pascal]var mat: Tmatrix2_single;[/pascal]

    ...then I would access elements like so...

    [pascal]x := mat.data[1, 1];[/pascal]

    Is that right? It would be nice if you could do mat[1, 1], but I understand why you decided to go with objects. Also, being able to typecast with similar types is a nifty feature. And I like the cross product operator:

    [pascal]A := B >< C[/pascal]
    [size=10px]&quot;In science one tries to tell people, in such a way as to be understood by everyone, something that no one ever knew before. But in poetry, it&#39;s the exact opposite.&quot; -- Paul Dirac[/size]

  5. #5

    Matrix unit

    Quote Originally Posted by cragwolf
    So if I declare a matrix like so...

    [pascal]var mat: Tmatrix2_single;[/pascal]

    ...then I would access elements like so...

    [pascal]x := mat.data[1, 1];[/pascal]

    Is that right? It would be nice if you could do mat[1, 1], but I understand why you decided to go with objects.
    Yes, this is correct. I tried to make the elements directly accessible with a default property, but it is not possible to define a default property this way.

  6. #6

    Matrix unit

    Quote Originally Posted by tpascal
    Hi,
    By the way, there is a well know unit called geometry.pas which include matrix and vector procedures but coded in assembler, so most people (like me) could think that should be run lot faster!, so maybe it could be a good idea to copy/paste those version, :roll:
    This is exactly the point of having a matrix unit shipped with the compiler, if people write their own matrix unit, usually they don't have the time and resources to implement everything in assembler. By working together the effort needed to implement everything in assembler is well spent.

    Quote Originally Posted by tpascal
    Another reason why i should preffer to code somthing my self is becouse somtimes programmers ARE SO LAZZY for document properly the units they release to the public; they like to give program examples instead; they say "please learn how to use my unit from this ready to run example" instead of of documenting exactly what the procedures are for and what the parameters mean. I preffer to expend two months coding for somthing my self but i will know fully how it works than expend 15 days figuring out more or less how works someone else code but not knowing fully if i am using it properly.
    I agree 100%. The documentation for the matrix unit is currently 280kb of source which translatetes to 2,6 MB of HTML. However, I still haven't finished. It is a monk work, because every routine needs to be documented 9 times; three matrix dimensions times three precisions.

  7. #7

    Re: Matrix unit

    Quote Originally Posted by dmantione
    So my questions are:
    * Are you aware that FPC has a matrix unit?
    * I was not aware of it.

    * Do you think it suits the needs of games?
    * If you implemented one yourself, why did you do so?
    Partly I understand the question as: "Why no games use it?"
    Let's see what came to mine mind after some looking at unit:
    * It's not cross-compiler, i.e. it's not possible to use it in Delphi
    * matrix-matrix multiply implemented using cycles
    * no SSE handtuned version of functions
    * most of graphic libraries already cames with they own "native" vector types, so why one need to struggle with type conversion between them FPC matrix types.
    There are only 10 types of people in this world; those who understand binary and those who don't.

  8. #8

    Matrix unit

    wouldnt a single matrix [x,y] be the same as a 2-dimensional array in delphi?
    [pascal]
    var
    Player: Array of Array of TPlayer;

    Player[x,y].Name := 'NewPlayer';
    [/pascal]

    can make more dimensians also, if you make a type that is either a single array or a two-dimensional...

    [pascal]
    type
    TPlayerArray = Array of TPlayer;

    var
    Players: Array of Array of TPlayerArray;

    Player[x,y,z].Name := 'NewPlayer';
    [/pascal]

  9. #9

    Matrix unit

    Quote Originally Posted by Diaboli
    wouldnt a single matrix [x,y] be the same as a 2-dimensional array in delphi?
    Absolutely not. A vectors and matrices are all about geometry. If you have a 3D game, you need them. For example you rotate an object by multiplying all its points with a rotation matrix. A matrix unit takes care of this multiplication, for example.

  10. #10

    Re: Matrix unit

    Quote Originally Posted by Clootie
    Quote Originally Posted by dmantione
    So my questions are:
    * Are you aware that FPC has a matrix unit?
    * I was not aware of it.

    * Do you think it suits the needs of games?
    * If you implemented one yourself, why did you do so?
    Partly I understand the question as: "Why no games use it?"
    Let's see what came to mine mind after some looking at unit:
    * It's not cross-compiler, i.e. it's not possible to use it in Delphi
    * matrix-matrix multiply implemented using cycles
    * no SSE handtuned version of functions
    * most of graphic libraries already cames with they own "native" vector types, so why one need to struggle with type conversion between them FPC matrix types.
    Thanks for the feedback. Delphi compatibility is a bit hard with the operator overload stuff, which is IMHO what it makes elegant. It could be made GNU-Pascal compatible, since that compiler uses the same syntax as FPC. Unfortunately nobody uses GPC. I agree that to make it really attractive it needs optimized routines, which includes unrolled multiplies and SSE. The binary format is intentionally just a two-dimensional array, which hopefully maximizes the chance that you can use it in a library without difficult conversion.

Page 1 of 3 123 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •