Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Advanced math functions

Author
Message
Jack
19
Years of Service
User Offline
Joined: 4th Oct 2004
Location: [Germany]
Posted: 9th May 2016 00:28 Edited at: 21st Nov 2017 01:08
Current Version: 0.7 - 21.11.2017

Hello together!

I try to build up some math functions, that are missing in AGK. I added a normalize command for vector3,
added some vector4 command and added a matrix4 create/delete/modify library. Over the time, the library grew to an enourmous 2d and 3d math library.
Over the time, a lot of improvements where made, so I post you a complete list of all commands.

This command set is already in use in the AppGameKit Game-Guru Loader and in the AppGameKit Shader Pack.
So there is already some good stuff based on it!

If you like the math lib, PM me, because I really get no feedback on this one, and don't know how fast improvements have to be built.


Enjoy!

What I have done so far

- >120Commands, including Vector2, Vector3, Vector4, Matrix4 and Quaternion commands
- Nearly complete 3dMath Library
- Extra Catmullrom functions
- Amazing Quaternion Stuff



WARNING: THIS LIBRARY NEEDS BETA-TESTERS RIGHT NOW! THE FUNCTIONS ARE WRITTEN DOWN, BUT ARE NOT VERIFIED YET!
PLEASE POST THE RESULTS OF YOUR TESTS IN THIS THREAD.






These math commands could help everyone by creating 3d scenarios and are extremly useful for shader control.
I have rewritten the Matrix4 library in 0.60, maybe it will run better now. I found some mistakes in the erlier versions


(Code got too big, Its attached as .agc right now)



Dev Notes: Please test me and verify me....
.. I may have bugs


░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░▄▄▄█▀▀▀▀▀▀▄▄▄░░░░░░░░░
░░░░░░░░░▄█▀▀░░░░░░░░░░░▀▀█▄▄░░░░░
░░░░░░░▄█▀░░░░░░▄▄▄░░░░░░░░▄▀█▄░░░
░░░░░░░█░░░░░░░░░░▀▀▄░░░░▄▀▀░░░█▄░
░░░░░░█░░░░░░░░░▄█▀▀▀█▄░▄█▀▀▀█▄░▀▄
░░░░░█░░░░░░░░░░██░▀░██░██░▀░██░░█
░░░░░█░░░░░░░░░░▀█████▀░▀█████▀░░█
░░░░░█░░░░░░░░░░░░░░░░▄░░░░█░░░░░█
░░░░░█░░░░░░░░░░░░░░░░██▀▀▀▀█░░░░█
░░░░░█░░░░░░░░░░░░░░░█░▄▀▄▄▄▀░░░░█
░░░░░█░░░░░░░░░░░░░░░▄█▀▀▀▀▄░░░░░█
░░░░░█▄░░░░░░░░░░░░░░█▄█▄█▄█░░░░░█
░░░░░░█▄░░░░░░░░░░░░▄▀█████▀░░░░▄▀
░░░░░░▄█▄░░░░░░░░░░░░░░░░░░░░░▄█▀░
░░░░▄█▀▄░░▀▄▄░░▄▄░░░░░░░▀▀▀▄▄▀▀░░░
░░▄█▀░░░▀▄░░░▀▀▀██▄▄▄▄▄▄█▀▀░░░░▄▄░
▄▀░░░░░░░░█░░░░░░░▄█▀▄░▄▄▄░░░░▀██▀
▀░░░░░░░░░░█▄░░░░▄█▄▄▄█████▄▄▄▀▀░░
░░░░░░░░░░░░░▀▀▀█▀▀▀▀▀░▀██▀░░░░░░░
░░░░░░░░░░░░░░░▄▀░░░░░░░░░░░░░░░░░

TGC, why U no math in AppGameKit???






Version 0.70 ... this version adds functions to draw vector2 and vector3 and whole new quaternion command set
============


Math Constants
==============
- Math_PI
- Math_Euler
- Math_GoldenRatio
- Math_PythagorasConstant
- Math_BernsteinConstant
- Math_ReciprocalFibonacciConstant
- Math_SierpinskisConstant
- Math_GregWalshConstant

Vector 2 Library
================
- CreateVector2 - Creates a 2d Vector
- DeleteVector2 - Deletes a 2d Vector
- SetVector2 - Set a 2d Vector
- PrintVector2 - Prints a 2d Vector to screen
- AddVector2 - Adds a 2d Vector to another one
- SubtractVector2 - Substracts a 2d Vector from another one
- GetVector2X - Get X Value of a 2d Vector
- GetVector2Y - Get Y Value of a 2d Vector
- CatmullRomVector2
- CopyVector2
- DivideVector2
- MultiplyVector2
- DotProductVector2
- BCCVector2
- SquaredLengthVector2
- LengthVector2
- HermiteVector2
- IsEqualVector2
- LinearInterpolateVector2
- MaximizeVector2
- MinimizeVector2
- NormalizeVector2
- ScaleVector2
- CCWVector2
- TransformCoordsVector2


"extended" Vector 3 Library
===========================
- PrintVector3
- AddVector3
- SubtractVector3
- CatmullRomVector3
- CopyVector3
- DivideVector3
- MultiplyVector3
- BCCVector3
- SquaredLengthVector3
- LengthVector3
- HermiteVector3
- IsEqualVector3
- LinearInterpolateVector3
- MaximizeVector3
- MinimizeVector3
- ScaleVector3
- ProjectVector3
- TransformCoordsVector3
- TransformNormalsVector3
- normalizeVector3
- GetForwardVector3FromQuat
- GetUpwardVector3FromQuat
- GetLeftVector3FromQuat
- DrawVector3


Vector 4 Library
================
- CreateVector4
- DeleteVector4
- SetVector4
- PrintVector4
- AddVector4
- SubtractVector4
- GetVector4X
- GetVector4Y
- GetVector4Z
- GetVector4W
- CatmullromVector4
- CopyVector4
- DivideVector4
- MultiplyVector4
- BCCVector4
- SquaredLengthVector4
- LengthVector4
- HermiteVector4
- IsEqualVector4
- LinearInterpolateVector4
- MaximizeVector4
- MinimizeVector4
- NormalizeVector4
- ScaleVector4
- TransformVector4


Matrix 4 Library
================
- CreateMatrix4
- DeleteMatrix4
- CopyMatrix4
- BuildLookAtLHMatrix4
- BuildLookAtRHMatrix4
- BuildOrthoLHMatrix4
- BuildOrthoRHMatrix4
- BuildFOVLHMatrix4
- BuildFOVRHMatrix4
- BuildPerspectiveLHMatrix4
- BuildPerspectiveRHMatrix4
- BuildReflectionMatrix4
- BuildRotationAxisMatrix4
- SetIdentityMatrix4
- IsEqualMatrix4
- IsIdentityMatrix4
- AddMatrix4
- SubtractMatrix4
- MultiplyMatrix4
- MultiplyMatrix4ByValue
- ScaleMatrix4
- TranslateMatrix4
- TransposeMatrix4
- RotateYPRMatrix4
- RotateXMatrix4
- RotateYMatrix4
- RotateZMatrix4
- WorldMatrix4
- ViewMatrix4
- ProjectionMatrix4
- DeterminantMatrix4
- DeterminantMatrix3
- SubMatrix3
- InverseMatrix4
- OrthographicProjectionMatrix4


Quaternion Library
==================
- CreateQuaternion
- DeleteQuaternion
- SetQuaternion
- GetQuaterionW
- GetQuaterionX
- GetQuaterionY
- GetQuaterionZ
- InverseQuaternion
- MultiplyQuaternion
- NormalizeQuaternion
- GetQuaternionFromDirectionVectors
- PrintQuaternion
- SlerpQuaternion


Tween Math Library
==================
- Hermite
- Sinerp
- Coserp
- Bounce
- Berp
- Lerp
- SmoothStep
- Approx
- Clerp
- Clamp

with 0.7, vectors can be displayed like that:

[/url]

Attachments

Login to view attachments
BatVink
Moderator
20
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 9th May 2016 10:38
Useful, thanks
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
GolWofael
8
Years of Service
User Offline
Joined: 15th Mar 2016
Location:
Posted: 10th May 2016 07:03
Great work !!
thanks ^_^
WickedX
15
Years of Service
User Offline
Joined: 8th Feb 2009
Location: A Mile High
Posted: 12th May 2016 02:23
Hello, Jack. In the snippet, I cover matrix rotations on the x, y, and z axis and matrix multiplication. Matrix multiplication is not the same as multiplication in general, where if you switch the multiplier and multiplicand you'll get the same product. In the snippet if MatA represents the x rotation and MatB the y rotation then the outcome will be a combined rotation in the xy order. if you then take the result and copy it to MatA and set MatB as the z rotation this will produce a combined rotation in xyz order. Now, if you have MatA set up to reflect on objects current rotation and MatB set up as a rotation on the z axis this will produce a global rotation. If you switch the matrices it will produce a local rotation. If I can find the time tomorrow, I will cover the view matrix and inverse matrix.

Jack
19
Years of Service
User Offline
Joined: 4th Oct 2004
Location: [Germany]
Posted: 12th May 2016 23:54
Whohoo you rock WickedX! I can't wait for more
I am going to implement your knowlege into the library right now. Once that's done, we have actually filled some of the advanced math void in AppGameKit!
Thank you!




[/url]
WickedX
15
Years of Service
User Offline
Joined: 8th Feb 2009
Location: A Mile High
Posted: 14th May 2016 01:25 Edited at: 14th May 2016 01:31
Sorry, it has been a hectic week. I am not too familier with AGK. DarkBasic Professional has functions to return the View Matrix and Inverse Matrix and other languages I use, I would just call the DirectX API. So, I am refreshing myself on the math behind these functions. Since AppGameKit doesn’t have the matrix functions, for a view matrix we will have to use a rotation matrix relating to the cameras x, y and z angles and the cameras position to build a left handed LookAt Matrix. The reason we build the rotation matrix based on the cameras angles is to find the at-vector and up-vector of the camera. The eye vector is just the cameras position. The snippet show the relation between these vectors and a rotational matrix. As you can see the first three values in the second and third row give the up and at vectors.

I just need to write some example code to verify my math for handedness and accuracy. The inverse matrix is a little more complicated, I have the math, I just need to see if I can simplify it through code. Hopefully, I can have this for you in the next couple days.

Stab in the Dark software
Valued Member
21
Years of Service
User Offline
Joined: 12th Dec 2002
Playing: Badges, I don't need no stinkin badges
Posted: 14th May 2016 13:33
AGK already has matrices in Tier2, just get Paul to expose them for Tier1.
Especially since they are needed for shaders.
The coffee is lovely dark and deep,and I have code to write before I sleep.
WickedX
15
Years of Service
User Offline
Joined: 8th Feb 2009
Location: A Mile High
Posted: 16th May 2016 22:22 Edited at: 16th May 2016 22:46
Meanwhile, this snippet shows how to set up a View Matrix based on the camera orientation. Given your join date on the forum, I'm assuming familiarity with DarkBasic Professional. I decided to go with the method used in DBPro's Update Camera internal function. This method uses Transform Coords Vector3, So, I included that function as well. The functions in the snippet - Radian and Set Matrix4 Element are from my plugin. The matrix rotation functions I gave are in degree's so, you don't need to worry about that. The other DBPro matrix functions used, you already know how to implement.

Jack
19
Years of Service
User Offline
Joined: 4th Oct 2004
Location: [Germany]
Posted: 17th May 2016 18:55 Edited at: 17th May 2016 19:08
Thank you WickedX!


I am implementing your knowlege into the math library right now. I hope, that I can release the next version tomorrow, it should be done once I finished the correct multiply matrix command.

Is it correct that:
Transform Normals Vector3 = TransformCoordsVector3 with a normalized vector in it?

Once the new implementations are done, there will only be following commands left:

Identity Matrix 4
Build Look at lh matrix

After that, everyone should be able to use advanced maths without waiting for Paul to implement them! For example I need them for some awesome shader stuff. I have posted some shaders in the useful shader thread, but recently, I came to the point in GLSL programming where I could create some stunning shaders, if I had control over the collision from AGK. Be prepared for some awesome shaders, once this lib is done
(With 2.019 Paul has enough to do right now, for example getting the fused sensor commands working on new devices like the S7 )

[/url]
WickedX
15
Years of Service
User Offline
Joined: 8th Feb 2009
Location: A Mile High
Posted: 17th May 2016 23:11
A Identity Matrix is simple. The first snippet illustrates an Identity Matrix. The second snippet is my DBPro code to build a LookAt LHMatrix.

Quote: "Is it correct that:
Transform Normals Vector3 = TransformCoordsVector3 with a normalized vector in it?"


Transform Normals Vector3 - transforms a normal using the transpose of the inverse of the given matrix. That is necessary so that normals don't get sheared or translated, only rotated. A transpose matrix is a matrix where each row is transposed to each column, i.e the first row becomes the first column, the second row becomes the second column, etc. A transpose matrix will change a left handed matrix to a right handed matrix. When I get the time I will write out the formula for an Inverse Matrix.




Jack
19
Years of Service
User Offline
Joined: 4th Oct 2004
Location: [Germany]
Posted: 3rd Jun 2016 01:18 Edited at: 3rd Jun 2016 02:02
Hello pals,
sorry for the late reply, I had work to be done very quick.
I returned with the newest update of the code.

WickedX, its more your snippet, because you did the brain stuff already =)
Thank you for your contribution! I hope we could get the last missing commands done,
then a quick debug round and we have advanced vector and matrix math in AppGameKit!


0.14:


EDIT:
0.2:
With the Build look at LHMatrix4 command


[/url]
WickedX
15
Years of Service
User Offline
Joined: 8th Feb 2009
Location: A Mile High
Posted: 3rd Jun 2016 03:57 Edited at: 3rd Jun 2016 04:22
Sorry, I haven't forgot about this. Been shorthanded at work, the long hours and crazy shifts have been kicking my butt. With all the cross multiplications, additions and subtractions, I have calculated the determinate and the values for the first row of the matrix. Next week should be back to normal. I will try to get this to you ASAP.

Quote: "Matrix multiplication is corrected (was wronger than wrong)"


Your first multiplication, before the else is fine. This is multiplying a matrix by a scalar and will be used to calculate the inverse matrix.
Stab in the Dark software
Valued Member
21
Years of Service
User Offline
Joined: 12th Dec 2002
Playing: Badges, I don't need no stinkin badges
Posted: 3rd Jun 2016 19:21
Just get Paul to expose them to Tier 1, then you will not have to worry about errors.
The coffee is lovely dark and deep,and I have code to write before I sleep.
Jack
19
Years of Service
User Offline
Joined: 4th Oct 2004
Location: [Germany]
Posted: 4th Jun 2016 01:29 Edited at: 4th Jun 2016 01:29
I have problems with the fused sensor rate, it works on 5fps and not with the screen fps.
.DAE objects can't be loaded on android anymore, and the AppGameKit shader code does also need some work.
These problems where mentioned before in different threads, and they still exist, and since 2.019 there are new bugs aswell.
I think it is not a good time for me to ask for new implementations, I will be happy if Paul debugs
the current features. So, I can`t see how I could achieve this right now.
We can't rewrite the T1 sensor reading method from AppGameKit, but at least the Matrix4 library can be done by us.
For me, It's also a very interesting project and I have learned a lot of theory from WickedX codes.

We are done pretty soon right now, at least with the matrix4 stuff.
I see you are pretty deep in coding, Stab in the Dark software
could you give me a hint what mathematical functions would be urgent for T1 and are not covered yet?

[/url]
Stab in the Dark software
Valued Member
21
Years of Service
User Offline
Joined: 12th Dec 2002
Playing: Badges, I don't need no stinkin badges
Posted: 8th Jun 2016 12:55 Edited at: 8th Jun 2016 12:58
I still think that Paul can expose all the vector and Matrix commands to Tier1 very quickly.
The Vector and Matrix commands are part of the core of AppGameKit and should have been exposed before
the 3D commands were started. If Tier1 users have to rewrite code that is already part of AGKs core
that is just plain stupid.

I copied these from DBPro Source. They are not in AppGameKit and I needed them for a free flight camera.


The coffee is lovely dark and deep,and I have code to write before I sleep.
WickedX
15
Years of Service
User Offline
Joined: 8th Feb 2009
Location: A Mile High
Posted: 10th Jun 2016 06:03 Edited at: 10th Jun 2016 06:06
Things are no better this week. Sorry, a graphical representation of the formula for an Inverse Matrix is the best I can offer.

Attachments

Login to view attachments
janbo
15
Years of Service
User Offline
Joined: 10th Nov 2008
Location: Germany
Posted: 1st Jul 2016 17:20 Edited at: 1st Jul 2016 20:03
Oh wow... how could I miss it out
It would have saved me much time probably.
I needed it for a shader.
I would be happy to contribute !

Maybe add the Orographic Projection matrix ?
I'll see what I can do...

[Edit]
This one should construct an Orthographic Projection Matrix using your syntax

[/Edit]

Using AGKv2 Tier1
janbo
15
Years of Service
User Offline
Joined: 10th Nov 2008
Location: Germany
Posted: 3rd Jul 2016 14:55 Edited at: 3rd Jul 2016 14:55
I have done a bit and tested some functions.

A Multiply Matrix function (row * column)
don't know what the others are (scalar multiplication ?)


A subtraction function where you use the build in Vector3 functions


I didn't got the view matrix to work properly
But I tested my orthographic projection matrix function with the look at matrix function and had to make some changes to work...here they are
maybe it was that left-handed thing

Using AGKv2 Tier1
Uncle Martin
17
Years of Service
User Offline
Joined: 9th Jul 2006
Location: Tampa, Florida, USA
Posted: 4th Jul 2016 03:19 Edited at: 4th Jul 2016 03:30
Very nice effort all.

Side Note: I believe the last helper function (radian(eul#) is incorrect or misnamed. Although the name & description indicate it is for generating an angle in Radians, clearly the code is generating in Degrees, since it multiplies by 180.

Jack, WickedX & all, I have contributed some coding for the Inverse 4x4 Matrix function. Note that the snippet hasn't been compiled or tested in any way, but I hope it will save you some time/trouble.



Enjoy. ~Uncle Martin
Code every line like it might be your last...
Someday it will be.
BatVink
Moderator
20
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 11th Nov 2016 22:39
unlocking as requested
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
Phaelax
DBPro Master
20
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 11th Nov 2016 23:10
This should be stickied!

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds
Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 12th Nov 2021 18:30 Edited at: 13th Nov 2021 01:24
Unlocked and added to the queue. thanks, Jack!
PartTimeCoder
AGK Tool Maker
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 12th Nov 2021 18:34 Edited at: 12th Nov 2021 18:35
Quote: "If you like the math lib, PM me, because I really get no feedback on this one....."


@Jaxck, @WickedX , Thank you, I was struggling for hours trying to get the right calculations and within an hour of downloading this lib everything was working just as I wanted, these function are just pure magic, thank you so much.

And thanks VN for unlocking.
Open Source plugins
Cl - DnD Plugin
Buy Me A Coffee
Phaelax
DBPro Master
20
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 14th Nov 2021 16:26
Glad this post popped back up, catmullrom and hermite were exactly what I was trying to look up last week but couldn't for the life of me remember the names!
Tiled TMX Importer V.2
XML Parser V.2
Base64 Encoder/Decoder
Purple Token - Free online hi-score database
Legend of Zelda

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds

Login to post a reply

Server time is: 2024-03-28 09:08:52
Your offset time is: 2024-03-28 09:08:52