Files |  Tutorials |  Articles |  Links |  Home |  Team |  Forum |  Wiki |  Impressum

Aktuelle Zeit: Sa Jun 08, 2024 07:12

Foren-Übersicht » Programmierung » Mathematik-Forum
Unbeantwortete Themen | Aktive Themen



Ein neues Thema erstellen Auf das Thema antworten  [ 6 Beiträge ] 
Autor Nachricht
 Betreff des Beitrags: community matrix/vector math unit?
BeitragVerfasst: So Jan 03, 2010 19:00 
Offline
DGL Member
Benutzeravatar

Registriert: Di Jul 01, 2003 18:59
Beiträge: 887
Wohnort: (The Netherlands)
Programmiersprache: fpc/delphi/java/c#
For the opengl examples i converted i wrote some new matrix functions, also i my glmodel i have some quaternion vector matrix math things.
I think it would be nice to have vector/matrix math unit next to the dglopengl unit providing some basic vector/matrix math filling the gap that is caused by the depracted functionality in opengl3 and suppelement things that were not availeable in opengl (quaternions).

So my suggestion is that a community dglmath unit is made. I donate my math things for wat they are worth (personaly i think only the math functions in my openg3 examples are worthwile using, but they are not oop.).

So what should be in it and who is willing to maintain it?

Or is there already a good vector/matrix math lib availeable? If so where can i find it?

_________________
http://3das.noeska.com - create adventure games without programming


Nach oben
 Profil  
Mit Zitat antworten  
BeitragVerfasst: So Jan 03, 2010 19:15 
Offline
DGL Member
Benutzeravatar

Registriert: Do Sep 02, 2004 19:42
Beiträge: 4158
Programmiersprache: FreePascal, C++
Hmm … I think (hypothetically speaking, if this ever gets finished, you know) one should start off with the most basic things. Vector types (2f, 3f, 4f) and symmetrical matrices (2x2, 3x3, 4x4). And then the most often used operations (vector add, subtract, scaling, cross- and dot-product and component-wise multiplication, also matrix · vector and the operations between matrices).
More advanced things could be the inversion of matrices and the whole quaternion-thing.

And I do not think that OOP is the best to use for this. Because with classes and objects, you always need to take care of the references and free the objects when you do not need them anymore. I would rather use records or arrays, where scope checks are made by the compiler.

When using FreePascal, one could also use the operator overloading mechanism to implement the vector and/or matrix operations. This could be realized in a separate include-file which is only parsed when the compiler is the fpc, to ensure that Delphi is not disturbed by the operator declarations.

greetings

_________________
If you find any deadlinks, please send me a notification – Wenn du tote Links findest, sende mir eine Benachrichtigung.
current projects: ManiacLab; aioxmpp
zombofant networkmy photostream
„Writing code is like writing poetry“ - source unknown


„Give a man a fish, and you feed him for a day. Teach a man to fish and you feed him for a lifetime. “ ~ A Chinese Proverb


Nach oben
 Profil  
Mit Zitat antworten  
BeitragVerfasst: Mo Jan 04, 2010 01:24 
Offline
DGL Member
Benutzeravatar

Registriert: Di Okt 03, 2006 14:07
Beiträge: 1277
Wohnort: Wien
Hi Noeska,
I have made my own Math3D.pas, most of the things inside are tested. It consists only of procedures & functions and you can have it, if you want. And last not least there is the old <geometry.pas> of dglsdk which is practically a community mat lib.
kind regards
Traude


Nach oben
 Profil  
Mit Zitat antworten  
BeitragVerfasst: Mo Jan 04, 2010 19:06 
Offline
DGL Member
Benutzeravatar

Registriert: Di Jul 01, 2003 18:59
Beiträge: 887
Wohnort: (The Netherlands)
Programmiersprache: fpc/delphi/java/c#
Is the dglsdk also availeable in an other format then the .exe installer? E.g. in zip format. To be honest i did not bother to reinstall the dglsdk on my new pc.
In the same line is geometry.pas availeable as a separate download just like dglopengl? How complete is it?

[EDIT]
I downloaded the linux version of the dglsdk and looked at the geometry.pas, unfortunately it uses assembly code in it.
[/EDIT]

@Traude: Does your math lib handle matrices as flat arrays so they can easily be transferred to opengl like i do in the opengl3 examples? The hardest thing was to make a proper normal matrix even with the help of the dgl wiki article.

_________________
http://3das.noeska.com - create adventure games without programming


Nach oben
 Profil  
Mit Zitat antworten  
BeitragVerfasst: Mo Jan 04, 2010 20:04 
Offline
DGL Member
Benutzeravatar

Registriert: Di Okt 03, 2006 14:07
Beiträge: 1277
Wohnort: Wien
Yes. I work only with OpenGL and I do not use glTranslate/Rotate/Scale, I use only my own tools. I cannot guaratee that everything is allright, I can only say: I use it, and it seems to be OK. What I did not use so far is marked with "NOT YET TESTED", which occurs in the Quaternion section.

This is the type definition of my matrix data:

Code:
  1.    TStdVector4D = Record X,Y,Z,W: TFloat32; End;
  2.   TStdMatrix = Array[0..3] Of TStdVector4D;  // Vectors are coloumns
  3.  
Note: "TFloat32" is a Single

And here are the function/procedure headers of my lib:
Code:
  1. //--------------------------------------------------------------------
  2. // HIT (COLLISION)
  3. Function HitCorridorPoint(ASelectCorridor: TSelectCorridor;
  4.                           APoint: TStdVector4D): TBool8;
  5. Function HitRayPlane(APlane: TStdPlane; ARay: TStdRay): TStdVector4D;
  6. Function HitRayRay(Ray1,Ray2: TStdRay): TStdVector4D;
  7. Function HitRaySection
  8.      (Point1A,Point1B,Point2A,Point2B: TStdVector4D): TBool8;
  9. Function HitRaySphere(ASphere: TStdSphere; ARay: TStdRay): TBool8;
  10. //--------------------------------------------------------------------
  11. // MATRIX
  12. Function MatricesEqual(M1,M2: TStdMatrix): TBool8;
  13. Function MatrixDet(M: TStdMatrix): TFloat32;
  14. Function MatrixFromVectorToVector
  15.               (FromVector,ToVector: TStdVector4D): TStdMatrix;
  16. Function MatrixInvers(M: TStdMatrix): TStdMatrix;
  17. Function MatrixMultiply(M1,M2: TStdMatrix): TStdMatrix;
  18. Function MatrixProjection(PerspParams: TPerspParams): TStdMatrix;
  19. Function MatrixRotate(Angle: TFloat32;
  20.               Axis: TStdVector4D): TStdMatrix;
  21. Function MatrixRotateLocal(ACenter: TStdVector4D;
  22.               ARotation: TStdAngleAxis): TStdMatrix; Overload;
  23. Function MatrixRotateLocal(ACenter: TStdVector4D;
  24.               AQuat: TStdQuaternion): TStdMatrix; Overload;
  25. Function MatrixScale(AScale: TStdVector4D): TStdMatrix;
  26. Function MatrixShift(AShift: TStdVector4D): TStdMatrix;
  27. Function MatrixRotateShift(Angle: TFloat32;
  28.               Axis,AShift: TStdVector4D): TStdMatrix;
  29. Function MatrixShiftRotate(Angle: TFloat32;
  30.               Axis,AShift: TStdVector4D): TStdMatrix;
  31. Function MatrixTangentSpace
  32.               (AShift,AForward,AUpward: TStdVector4D): TStdMatrix;
  33. Function MatrixTransform(ARight,AUp,AForward,APos:
  34.               TStdVector4D): TStdMatrix;
  35. Function MatrixTranspose(AMatrix: TStdMatrix): TStdMatrix;
  36. // MATRIX - Conversion
  37. Function MatrixToAngleAxis(AMatrix: TStdMatrix): TStdAngleAxis;
  38. //--------------------------------------------------------------------
  39. // QUATERNION
  40. Function Quaternion(Angle,X,Y,Z: TFloat32): TStdQuaternion;
  41. Function QuaternionConjugate(AQuat: TStdQuaternion): TStdQuaternion;
  42. Function QuaternionDotProduct(Quat1,Quat2: TStdQuaternion): TFloat32;
  43. Function QuaternionInverse(AQuat: TStdQuaternion): TStdQuaternion;
  44. Function QuaternionMultiply
  45.                (ANormQuat1,ANormQuat2: TStdQuaternion): TStdQuaternion;
  46. Function QuaternionNormalize(AQuat: TStdQuaternion): TStdQuaternion;
  47. Function QuaternionSLerp(Quat1,Quat2: TStdQuaternion;
  48.                AFactor: TFloat32): TStdQuaternion;
  49. Function QuaternionValue(AQuat: TStdQuaternion): TFloat32;
  50.  
  51. // QUATERNION - Conversion
  52. Function AngleAxisToQuaternion(ARotation: TStdAngleAxis): TStdQuaternion;
  53. Function QuaternionToAngleAxis(AQuat: TStdQuaternion): TStdAngleAxis;
  54. Function QuaternionToMatrix(AQuat: TStdQuaternion): TStdMatrix;
  55. //--------------------------------------------------------------------
  56. // VECTOR
  57. Function Vector4D(AX,AY,AZ: TFloat32): TStdVector4D;
  58. Function VectorAdd(Vector1,Vector2: TStdVector4D): TStdVector4D;
  59. Function VectorAngle(Vector1,Vector2: TStdVector4D): TFloat32;
  60. Function VectorArcus(Vector1,Vector2: TStdVector4D): TFloat32;
  61. Function VectorAxis(Vector1,Vector2: TStdVector4D): TStdVector4D;
  62. Function VectorCrossProduct(Vector1,Vector2: TStdVector4D): TStdVector4D;
  63. Function VectorDeduct(FromPoint,ToPoint: TStdVector4D): TStdVector4D;
  64. Function VectorDotProduct(AVector1,AVector2: TStdVector4D): TFloat32;
  65. Function VectorDuplicate(AVector: TStdVector4D): TStdVector4D;
  66. Function VectorEqual(AVector1,AVector2: TStdVector4D): TBool8;
  67. Function VectorInvers(AVector: TStdVector4D): TStdVector4D;
  68. Function VectorMultiply(AVector: TStdVector4D;
  69.               AFactor: TFloat32): TStdVector4D;
  70. Function VectorNormalize(AVector: TStdVector4D): TStdVector4D;
  71. Function VectorRotate(AMatrix: TStdMatrix;
  72.               AVector: TStdVector4D): TStdVector4D;  Overload;
  73. Function VectorRotate(AQuat: TStdQuaternion;
  74.               AVector: TStdVector4D): TStdVector4D;  Overload;
  75. Function VectorRotation(FromVector,ToVector,
  76.               DefaultAxis: TStdVector4D): TStdAngleAxis;
  77. Function VectorTransform(AMatrix: TStdMatrix;
  78.               AVector: TStdVector4D): TStdVector4D;
  79. Function VectorValue(AVector: TStdVector4D): TFloat64;
  80. //--------------------------------------------------------------------
  81. // CYLINDER/SPHERE
  82. Function SphereX(AngleCol,AngleRow: TFloat32): TFloat32;
  83. Function SphereY(AngleCol,AngleRow: TFloat32): TFloat32;
  84. Function SphereZ(AngleRow: TFloat32): TFloat32;
  85. //--------------------------------------------------------------------
  86. // ELSE
  87. Function PointPlaneDistance(AVector: TStdVector4D;
  88.               APlane: TStdPlane): TFloat32;
  89. Function PointRayDistance(AVector: TStdVector4D;
  90.               ARay: TStdRay): TFloat32;
  91. Function RotationType(A,B,C: TStdVector4D): TRotationType;
  92. Function TriangleAngleAlpha
  93.               (SideA,SideB,SideC: TFloat32): TFloat32;
  94. Function TriangleAngleGamma
  95.               (SideA,SideB,SideC: TFloat32): TFloat32;
  96. Function Project(AX,AY,AZ: TFloat32; AViewPort: TInt32Array4;
  97.              AMatModel,AMatProj: TStdMatrix): TStdVector2D;
  98. Function UnProject(AScreenX,AScreenY: TFloat32; AViewPort: TInt32Array4;
  99.              AMatModel,AMatProj: TStdMatrix): TStdVector4D;
  100.  


Nach oben
 Profil  
Mit Zitat antworten  
BeitragVerfasst: Di Jan 05, 2010 21:03 
Offline
DGL Member

Registriert: Do Jun 28, 2007 17:58
Beiträge: 193
Programmiersprache: Pascal, C
Why not take the following Andorra Commons units as a common base?

AcTypes.pas (contains vector and matrix type definitions):
http://andorracommons.svn.sourceforge.n ... iew=markup

AcMath.pas (contains mathematical functions, partially with 3DNow! support):
http://andorracommons.svn.sourceforge.n ... iew=markup

The license is the MPL.

_________________
http://audorra.sourceforge.net//http://andorra.sourceforge.net


Nach oben
 Profil  
Mit Zitat antworten  
Beiträge der letzten Zeit anzeigen:  Sortiere nach  
Ein neues Thema erstellen Auf das Thema antworten  [ 6 Beiträge ] 
Foren-Übersicht » Programmierung » Mathematik-Forum


Wer ist online?

Mitglieder in diesem Forum: 0 Mitglieder und 2 Gäste


Du darfst keine neuen Themen in diesem Forum erstellen.
Du darfst keine Antworten zu Themen in diesem Forum erstellen.
Du darfst deine Beiträge in diesem Forum nicht ändern.
Du darfst deine Beiträge in diesem Forum nicht löschen.
Du darfst keine Dateianhänge in diesem Forum erstellen.

Suche nach:
Gehe zu:  
cron
  Powered by phpBB® Forum Software © phpBB Group
Deutsche Übersetzung durch phpBB.de
[ Time : 0.010s | 14 Queries | GZIP : On ]