
12

I’m trying to following some OpenGL tutorials to learn the matrix transforms but I’m getting stuck because I don’t have the c++ GLM library which everyone is using. I see FPC has a matrix class but it doesn’t include all the helpers in GLM like rotation, transform, perspective transforms ( https://open.gl/transformations). If I knew enough I think I could just build these myself but I’ll likely introduce a bunch of errors at first.
Has anyone converted these to Pascal before or having some similar I could look at?
Regards,
Ryan Joseph
_______________________________________________
fpcpascal maillist  [hidden email]
http://lists.freepascal.org/cgibin/mailman/listinfo/fpcpascal

Administrator

> Has anyone converted these to Pascal before or having some similar I could look at?
I don't usually do the matrix calculation myself, I delegate that by calling OpenGL functions in proper order. However, just a few days ago I found this:
https://paginas.fe.up.pt/~paco/pmwiki/index.php?n=DynMatrix.DynMatrixwhich does seem to have enough matrix operations for most use cases.


> On May 27, 2017, at 4:20 PM, leledumbo via fpcpascal < [hidden email]> wrote:
>
> I don't usually do the matrix calculation myself, I delegate that by calling
> OpenGL functions in proper order. However, just a few days ago I found this:
> https://paginas.fe.up.pt/~paco/pmwiki/index.php?n=DynMatrix.DynMatrix>
> which does seem to have enough matrix operations for most use cases.
There are no such functions as part of the OpenGL API. I’m talking about functions that return a 4x4 rotation matrix or a perspective matrix, lookAt matrix etc… Everyone uses glm because it uses similar syntax as the shader language GLSL but you need to know how to construct these yourself otherwise.
Regards,
Ryan Joseph
_______________________________________________
fpcpascal maillist  [hidden email]
http://lists.freepascal.org/cgibin/mailman/listinfo/fpcpascal


> On May 27, 2017, at 4:30 PM, Graeme Geldenhuys < [hidden email]> wrote:
>
> I've implemented that by porting the Java Game Libirary code to Object Pascal. Give me a day or two and I'll share the OpenGL code I have on Github.
Thanks that would be great if someone had those common functions in Pascal. Not having glm::perspective or glm::lookAt is enough to really stop you in your tracks and running off to Google for hours.
Regards,
Ryan Joseph
_______________________________________________
fpcpascal maillist  [hidden email]
http://lists.freepascal.org/cgibin/mailman/listinfo/fpcpascal


On 27/05/17 09:40, leledumbo via fpcpascal wrote:
>> Has anyone converted these to Pascal before or having some similar I couldlook at?
> I don't usually do the matrix calculation myself, I delegate that by callingOpenGL functions in proper order.
But working from a hazy recollection of such things, it's possible to
merge the translation/rotation matrices so that the final transformation
can be reduced to a single operation.

Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk
[Opinions above are the author's, not those of his employers or colleagues]
_______________________________________________
fpcpascal maillist  [hidden email]
http://lists.freepascal.org/cgibin/mailman/listinfo/fpcpascal


> On May 27, 2017, at 5:16 PM, Mark Morgan Lloyd < [hidden email]> wrote:
>
> But working from a hazy recollection of such things, it's possible to merge the translation/rotation matrices so that the final transformation can be reduced to a single operation.
Oh I’m sorry, I’m using 3.x core and the fixed pipeline has been removed which glRotate etc… were part of. I’m using this now but I wanted to learn the “new” stuff some.
Regards,
Ryan Joseph
_______________________________________________
fpcpascal maillist  [hidden email]
http://lists.freepascal.org/cgibin/mailman/listinfo/fpcpascal


I've put some units of my still workinprogress UE4style SupraEngine on my root server, after I've read this mailing list thread =>
http://rootserver.rosseaux.net/stuff/supraengineunits/ where the SupraEngine.Math.pas + SupraEngine.Math.*.inc + SupraEngine.Types.Standard.pas will be maybe interesting for you.
It's a complete 3D Math unit based on overloaded operators, advanced records, etc. and even with GLSLstyle swizzle support, where you can type something like My3DVector.xzy := MyOther3DVector.yyx; My4DVector.zyx := TVector3.Create(3.0, 2.0, 1.0); or even My2DVector.yx := My3DVector.yz; etc.
Furthermore many routines are SSE optimized for the x8632 and x8664 targets.
This is the result of many years of evolutionbased work, starting from the original math routines of my old PAPPE physics engine, which I've always further developed over the years (incl. many refactorings and rewrites).
And if you will do using it, then you add the following line to your start of your code (where the Math unit must be in the uses clause):
SetExceptionMask([exInvalidOp, exDenormalized, exZeroDivide, exOverflow, exUnderflow, exPrecision]);
for disable some floating point exceptions, which could occur at 3D stuff, especially dividebyzero exceptions at speedSIMDoptimized normalization operations.
And credits would be nice :)
Regards, Benjamin 'BeRo' Rosseaux
_______________________________________________
fpcpascal maillist  [hidden email]
http://lists.freepascal.org/cgibin/mailman/listinfo/fpcpascal


> On May 28, 2017, at 1:54 PM, Benjamin Rosseaux < [hidden email]> wrote:
>
> I've put some units of my still workinprogress UE4style SupraEngine on my root server, after I've read this mailing list thread =>
Thanks for sharing. The GLM functions I wanted seem to be here so I’m going to try them.
Btw, I’m not sure Sven fixed this or is going to but we found out record constructors were not producing optimal instructions when compared to static inline class functions so you may want to change those. I had to go back and make changes to some lowlevel record constructors after I found this out also.
Regards,
Ryan Joseph
_______________________________________________
fpcpascal maillist  [hidden email]
http://lists.freepascal.org/cgibin/mailman/listinfo/fpcpascal


In reply to this post by Benjamin Jan Alexander Rosseaux2
I've put some units of my still workinprogress UE4style SupraEngine on my root server, after I've read this mailing list thread =>
Looks nice. Thanks for sharing. How about publishing it on Github with small readme to ease contributions?  Regards, Denis Golovan
_______________________________________________
fpcpascal maillist  [hidden email]
http://lists.freepascal.org/cgibin/mailman/listinfo/fpcpascal


Ryan Joseph wrote:
> I’m trying to following some OpenGL tutorials to learn the matrix transforms but I’m getting stuck because I don’t have the c++ GLM library which everyone is using. I see FPC has a matrix class but it doesn’t include all the helpers in GLM like rotation, transform, perspective transforms ( https://open.gl/transformations). If I knew enough I think I could just build these myself but I’ll likely introduce a bunch of errors at first.
>
> Has anyone converted these to Pascal before or having some similar I could look at?
>
> Regards,
> Ryan Joseph
I use my own vector/matrix library VectorUtils3, which is written in
plain C (thereby FPC friendly), and included in the common code of my
OpenGL demo library:
http://computergraphics.se/demopage/Actually, there is also an FPC version of VectorUtils, FPC interfaces to
most of my common code, and even a bunch of demos that I made FPC for.
(Modern OpenGL, not oldstyle code, no immediate mode.) I never uploaded
them anywhere, since there didn't seem to be much interest, but if
someone wants them, no problem.
/Ingemar
_______________________________________________
fpcpascal maillist  [hidden email]
http://lists.freepascal.org/cgibin/mailman/listinfo/fpcpascal


I know that issue, so that the record constructors in the SupraEngine.Math.pas are fully optional, so therefore you do must not using these :) It's just a optional option for keytaplazy peoples, since all record member fields are also free directly accessible and public visible.
_______________________________________________
fpcpascal maillist  [hidden email]
http://lists.freepascal.org/cgibin/mailman/listinfo/fpcpascal


On GitHub I've already some SupraEngine subprojects, for example: But the SupraEngine main core project itself is still closed source (as long as it is not yet ready), except these already excerptuploaded (for users of this mailing list) zliblicensed Math units, because SupraEngine will have a UE4style licensing model, say, when it will be released, it will be free and quasiopensource for free projects (it does not matter whether it are open source or closed source projects), but it will be revenuesharebased for nonfree paid projects. A lawyer (a corresponding lawyer I have already in the selection) will formulate the appropriate license text for it, but this will be the last task, just before the release.
And I've testwise partlyreverse.engineered and partlyreimplemented the first two Original WipeOut titles (in ObjectPascal of course): https://youtu.be/MI_jtU2kiQk and https://youtu.be/zKpAWaByyyc for to test my newer physics engine in a real test game, as preparation for usage in my Supraleiter game project with the then new Vulkanbased SupraEngine.
_______________________________________________
fpcpascal maillist  [hidden email]
http://lists.freepascal.org/cgibin/mailman/listinfo/fpcpascal


In reply to this post by Benjamin Jan Alexander Rosseaux2
> On May 28, 2017, at 10:33 PM, Ryan Joseph < [hidden email]> wrote:
>
> projTransform := TMatrix4x4.CreatePerspective(60.0, 500 / 500, 0.1, 10.0);
> modelTransform := TMatrix4x4.CreateTranslation(0, 0, 3.0) * TMat4.CreateRotateX(54);
I found out the problem. I was expecting the multiply to work like with GLM where you could do:
translation * rotation
but with the operator overloads I need to do protation * translation. Anthony’s multiply matrix 4 operators did this in the order I expected and how I figured it out. Not sure why and it’s probably not safe to swap the parameters because it would likely break other parts of the unit.
Regards,
Ryan Joseph
_______________________________________________
fpcpascal maillist  [hidden email]
http://lists.freepascal.org/cgibin/mailman/listinfo/fpcpascal


> On May 29, 2017, at 8:24 AM, Anthony Walter < [hidden email]> wrote:
>
> And these matrices are compatible with OpenGL functions.
>
Thanks for sharing. I got your matrix multiplication functions to work in the order I expected and helped me find a bug.
Btw, given what we just learned about loops in FPC I would remove the nested for..loops in your matrix overloads.
Regards,
Ryan Joseph
_______________________________________________
fpcpascal maillist  [hidden email]
http://lists.freepascal.org/cgibin/mailman/listinfo/fpcpascal


All SupraEngine.Math matrices are also compatible with OpenGL (and Vulkan, of course). SupraEngine.Math's TMatrix3x3 and TMatrix4x4 implementation have also advanced stuff as such as lerp, nlerp, slerp interpolation method functions, decomposing (into Perspective, Translation, Scale, Skew and Rotation components), recomposing (from Perspective, Translation, Scale, Skew and Rotation components). And SupraEngine.Math have also GLSLstyle and in the most cases GLSLFunctionParametercompatible functions as such as Cross, Dot, Normalize, FaceForward, Reflect, Refract, Clamp, Mix, Step, SmoothStep, etc.
Example usages:
FaceNormal := (p2  p0).Cross(p1  p0).Normalize; // or alternatively also: FaceNormal := Normalize(Cross(p2  p0,p1  p0)); if FaceNormal.Dot((Normals[NormalIndices[0]]+ Normals[NormalIndices[1]]+ Normals[NormalIndices[2]]).Normalize) < 0.0 then begin FaceNormal := FaceNormal; end;
TriangleTangent:=((p2p0)*(uv1.vuv0.v))((p1p0)*(uv2.vuv0.v)); TriangleBitangent:=((p2p0)*(uv1.uuv0.u))((p1p0)*(uv2.uuv0.u)); TriangleTangent:=(TriangleTangent(TriangleNormal*TriangleTangent.Dot(TriangleNormal))).Normalize; TriangleBitangent:=(TriangleBitangent(TriangleNormal*TriangleBitangent.Dot(TriangleNormal))).Normalize; if (TriangleBitangent.Cross(TriangleTangent)).Dot(TriangleNormal)<0.0 then begin TriangleTangent:=TriangleTangent; TriangleBitangent:=TriangleBitangent; end;
Matrix := Transform.Matrix * Matrix;
Vector := Matrix * Vector; (like at GLSL) Vector := Vector * Matrix; (in the other way transposed mul like at GLSL)
Vector := Quaternion * Vector; Vector := Vector * Quaternion; (with the same transposedmatrixlike effect)
Vector := DualQuaternion * Vector; Vector := Vector * DualQuaternion; (with the same transposedmatrixlike effect)
Matrix := Matrix.Normalize; Matrix := Matrix.OrthoNormalize; Matrix := Matrix.RobustOrthoNormalize;
Quaternion := Matrix.ToQuaternion;
QTangent := Matrix.ToQTangent;
Matrix3x3 := Matrix4x4.ToMatrix3x3;
ModelMatrix := Matrix4x4Identity; ViewMatrix := TMatrix4x4.CreateTranslation(0.0, 0.0, 4.0); ProjectionMatrix := TMatrix4x4.CreatePerspective(45.0, Width / Heighz, 1.0, 1024.0); ModelViewMatrix := ModelMatrix * ViewMatrix; InverseModelViewMatrix := ModelViewMatrix.Inverse;
ModelViewProjectionMatrix := ModelMatrix * ViewMatrix * ProjectionMatrix;
InverseModelViewProjectionMatrix := ModelViewMatrixProjection.Inverse; TangentSpaceRotationMatrix := ModelViewMatrix.Inverse.Transpose; InverseTangentSpaceRotationMatrix := TangentSpaceRotationMatrix.Transpose;
ClipMatrix := CreateProjectionMatrixClip(ProjectionMatrix, ClipPlane);
etc.
_______________________________________________
fpcpascal maillist  [hidden email]
http://lists.freepascal.org/cgibin/mailman/listinfo/fpcpascal

12
