Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: eri0o on Wed 16/10/2019 23:11:38

Title: Doing 3D math in AGS
Post by: eri0o on Wed 16/10/2019 23:11:38
(https://user-images.githubusercontent.com/2244442/66962262-ef9e0b80-f046-11e9-8555-71ea8495bc07.gif) (https://streamable.com/vyrp4)

Recently I've been inclined to learn the math that enables doing 3D stuff. In the long past I guess people have looked into it (I found this thread (https://www.adventuregamestudio.co.uk/forums/index.php?topic=20842.0) from 2005!), and more recently a very impressive demo was put here (https://www.adventuregamestudio.co.uk/forums/index.php?topic=50178.0)...

So I decided to look into what could be done in similar manner, as a module, to help with such endeavors. From a different unreleased, unfinished, project, I cobbled up some code here in this GitHub repository (https://github.com/ericoporto/math3d). The README is barely a sketch, I will try to figure out the concepts and put them there as I learn.

You can get math3d.scm here (https://github.com/ericoporto/math3d/releases/download/0.0.1/math3d.scm). You can experiment with it.

I could really use some help understanding this stuff, if you have better ideas for the API and things to have, fire up. If you find a bug, please PR on GitHub if you know how to fix.

I intend to provide a triplet vector (which may have a fourth element), quaternions, matrix and helpful transformation functions.

Also I like discussing this and will try to update this thread as I learn. The gif above links to a video showing me playing with a virtual camera.
Title: Re: Doing 3D math in AGS
Post by: Jack on Thu 17/10/2019 00:15:41
Thanks, this is cool.
Title: Re: Doing 3D math in AGS
Post by: eri0o on Thu 17/10/2019 00:50:21
Thanks Jack! the AGS project can be downloaded here as .zip (https://github.com/ericoporto/math3d/archive/master.zip). Fair warning, expect bugs and me failing to grasp concepts! XD

One cool addition is being able to create a Matrix like this:

Code (ags) Select
Matrix* m = Matrix.CreateFromString("{{4,8},{2,3}}");
Title: Re: Doing 3D math in AGS
Post by: eri0o on Wed 07/10/2020 02:21:36
I had an error in my code for the projection. I fixed.

There's still something wrong there but I could not tell... I updated the demo with a bit more stuff.

I don't know how to project a point in the screen back into the virtual world, so the block following the mouse is not working yet. Added a lamp to indicate the direction the block is facing. hold W to swim in the mouse direction and S to swim against it

(https://i.imgur.com/hFvtR1q.gif)

(https://i.imgur.com/YamCAfJ.gif)

Title: Re: Doing 3D math in AGS
Post by: Crimson Wizard on Wed 07/10/2020 02:23:20
Quote from: eri0o on Wed 07/10/2020 02:21:36
I don't know how to project a point in the screen back into the virtual world

Similarily, only using inverse matrix/formulas in reverse order.
Title: Re: Doing 3D math in AGS
Post by: eri0o on Wed 07/10/2020 02:49:25
AH, it must  be the order then! Thanks! I will try to add this next.
Title: Re: Doing 3D math in AGS
Post by: KyriakosCH on Wed 07/10/2020 22:01:34
Yay, this looks great :)
So, how can I use it with the latest AGS?