You can help CodeWalrus stay online by donating here. | New CodeWalrus | Old (dark mode) | Old (light) | Discord server

c4's 3D Game Engine [3d][lwjgl][java]

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

0
b/PC, Mac & Vintage Computers publicado por u/c4ooo July 22, 2016, 07:40:10 PM
I first did 3D programming in java the summer of 2014, but haven't really made any 3D games. Anyways, i decided to pick it up again, don't really know what type of game to make.
Last Edit: July 28, 2016, 10:07:19 AM by c4ooo
Inicia sesión o crea una cuenta para dejar un comentario
u/Yuki July 22, 2016, 07:42:02 PM
Nice floor.
u/Dream of Omnimaga July 23, 2016, 06:52:29 AM
I'm definitively curious about what you'll come up with. Something themed around calc games would be cool actually (it doesn't have to be advanced, but for example a voxel version of Reuben 1 but with battles replaced with real time action like in Zelda)
u/c4ooo July 24, 2016, 05:47:40 PM
lolz math sucks

        longestLength = Math.max((float) Math.sqrt(Math.pow(x3 - x4, 2) + Math.pow(y3 - y4, 2) + Math.pow(z3 - z4, 2)),
                Math.max((float) Math.sqrt(Math.pow(x2 - x4, 2) + Math.pow(y2 - y4, 2) + Math.pow(z2 - z4, 2)),
                        Math.max((float) Math.sqrt(Math.pow(x2 - x3, 2) + Math.pow(y2 - y3, 2) + Math.pow(z2 - z3, 2)),
                                Math.max((float) Math.sqrt(Math.pow(x1 - x4, 2) + Math.pow(y1 - y4, 2) + Math.pow(z1 - z4, 2)),
                                        Math.max((float) Math.sqrt(Math.pow(x1 - x2, 2) + Math.pow(y1 - y2, 2) + Math.pow(z1 - z2, 2)),
                                                (float) Math.sqrt(Math.pow(x1 - x3, 2) + Math.pow(y1 - y3, 2) + Math.pow(z1 - z3, 2)))))));

(This is one line broken into 6 for readability, it finds the longest of all lines connecting 4 vertices of a quad.)

Edit: got downwards collision detection working:

It works by testing if a line segment, representing the direction of your movement, intersects with the plane of a face, and then testing if the point of intersection is within that face. I have to make it now so the angle of the face you're interacting with affects your movement (eg if you walk forward a ramp,  your body goes up, if you try walking up a really tall slope, like a wall, you move back. And of course i have to add collision detection in other direction :P
Last Edit: July 24, 2016, 06:30:52 PM by c4ooo
u/Dream of Omnimaga July 24, 2016, 06:42:09 PM
Hm glad you are getting some collision detection to work. :)

Supersonic Ball 3D?
u/Snektron July 24, 2016, 09:29:10 PM
Quote from: c4ooo on July 24, 2016, 05:47:40 PM
lolz math sucks

        longestLength = Math.max((float) Math.sqrt(Math.pow(x3 - x4, 2) + Math.pow(y3 - y4, 2) + Math.pow(z3 - z4, 2)),
                Math.max((float) Math.sqrt(Math.pow(x2 - x4, 2) + Math.pow(y2 - y4, 2) + Math.pow(z2 - z4, 2)),
                        Math.max((float) Math.sqrt(Math.pow(x2 - x3, 2) + Math.pow(y2 - y3, 2) + Math.pow(z2 - z3, 2)),
                                Math.max((float) Math.sqrt(Math.pow(x1 - x4, 2) + Math.pow(y1 - y4, 2) + Math.pow(z1 - z4, 2)),
                                        Math.max((float) Math.sqrt(Math.pow(x1 - x2, 2) + Math.pow(y1 - y2, 2) + Math.pow(z1 - z2, 2)),
                                                (float) Math.sqrt(Math.pow(x1 - x3, 2) + Math.pow(y1 - y3, 2) + Math.pow(z1 - z3, 2)))))));

(This is one line broken into 6 for readability, it finds the longest of all lines connecting 4 vertices of a quad.)

How about you break that up for readabillity:

double distance(float x0, float y0, float z0, float x1, float y1, float z1)
{
     float x = x0 - x1;
     float y = y0 - y1;
     float z = z0 - z1;
     return Math.sqrt(x*x + y*y + z*z);
}

double max(double... values)
{
    // Java 8
   return Arrays.stream(values).max().getAsDouble();

   // Java <= 7
   double max = Double.MIN_VALUE;
   for (double d : values)
       max = Math.max(d);
   return max;
}

(...)
    longestLength = (float) max
    (
        distance(x1, y1, z1, x2, y2, z2),
        distance(x2, y2, z2, x3, y3, z3),
        distance(x3, y3, z3, x4, y4, z4),
        distance(x4, y4, z4, x1, y1, z1),
    );
(...)


instead of the new max() fucntion you could also just use multple Math.max's. This should be a tiny bit faster due to less casting (though you could remove those in your version too). But its a lot more readable ;)
u/c4ooo July 27, 2016, 12:16:10 PM
Ok so, i want some volunteers to do some boring testing :)
So here's what to do: download the attachment, extract the zip, and double click on run.bat. The program should start! Don't touch any of the controls yet except the mouse yet! Your player should be falling down. You will either land on the pink thing or fall right through it. It will be nice if you could reply saying whether you fall through or land on it, as well as a copy of the output.txt file that should be created in the folder in which you extracted the zip. Sorry, so far its windows only :(
u/Snektron July 27, 2016, 12:32:22 PM
I won't be able to test it since im running Linux on this laptop :(
u/E37 July 27, 2016, 12:39:24 PM
I'll test it this evening!
u/Snektron July 27, 2016, 12:45:40 PM
Okay i managed to get it working. You have to download lwjgl 2.9.3 (https://sourceforge.net/projects/java-game-lib/files/Official%20Releases/LWJGL%202.9.3/)
Then extract lwjgl.jar, lwjgl_util.jar and jinput.jar to a folder called 'lib' next to 3D.jar. Then you copy the folder natives/<your platform> to a folder called 'natives' next to 3D.jar.
Then you can run it with

java -Djava.library.path="natives" -jar 3D.jar


The first time i landed on the platform, but the second and third time i fell through the world :(
u/c4ooo July 27, 2016, 01:10:35 PM
Ohh, i packaged the whole thing into a fat jar so the natives and libs should be inside the farjar?!?!?! ??? But lol i take pride in the fact that you actually got it to work xD (That sentence seems weird <_< )
Well, can you paste the output.txt of several tries please :) ?
u/Dream of Omnimaga July 27, 2016, 03:39:43 PM
Quote from: c4ooo on July 27, 2016, 12:16:10 PM
Ok so, i want some volunteers to do some boring testing :)
So here's what to do: download the attachment, extract the zip, and double click on run.bat. The program should start! Don't touch any of the controls yet except the mouse yet! Your player should be falling down. You will either land on the pink thing or fall right through it. It will be nice if you could reply saying whether you fall through or land on it, as well as a copy of the output.txt file that should be created in the folder in which you extracted the zip. Sorry, so far its windows only :(
When I try to run run.bat, I get the following error:

QuoteError: Unable to access jarfile 3dtest.jar
Press any key to continue . . .

Looks like you got the file name wrong. ANyway I renamed the jar file and now I get this error @c4ooo

QuoteError: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.NoClassDefFoundError: org/lwjgl/LWJGLException
        at java.lang.Class.getDeclaredMethods0(Native Method)
        at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
        at java.lang.Class.privateGetMethodRecursive(Unknown Source)
        at java.lang.Class.getMethod0(Unknown Source)
        at java.lang.Class.getMethod(Unknown Source)
        at sun.launcher.LauncherHelper.validateMainClass(Unknown Source)
        at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
Caused by: java.lang.ClassNotFoundException: org.lwjgl.LWJGLException
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        ... 7 more
Press any key to continue . . .

Windows 10 Pro (64-bits)
Intel Core i7 2.80 GHz
8 GB RAM
Nvidia GeForce GT 710 (2 GB video memory)
u/c4ooo July 27, 2016, 04:36:19 PM
Yea looks like i forgot to add the whole dam library  :-\ Why were you unable to access the jar though ???

Edit: yea, looks like i put the wrong jar file in the zip, hold on i'll fix it.
Last Edit: July 27, 2016, 04:38:18 PM by c4ooo
u/Dream of Omnimaga July 27, 2016, 04:58:23 PM
Ah I see now. And yeah I thought the file name was wrong at first.
u/c4ooo July 27, 2016, 05:07:00 PM
This one should work: http://s000.tinyupload.com/?file_id=40630677022870276995
(File was to big to uploud to CW)
Start a Discussion

b/PC, Mac & Vintage Computers

Computer programming discussion and project showcase

132
Topics
Explore Board
Website statistics


MyCalcs | Ticalc.org | Cemetech | Omnimaga | TI-Basic Developer | MaxCoderz | TI-Story | Casiocalc.org | Casiopeia | The Museum of HP Calculators | HPCalc.org | CnCalc.org | Music 2000 Community | TI Education | Casio Education | HP Calcs | NumWorks | SwissMicros | Sharp Calculators
Powered by EzPortal