Join us on Discord!
You can help CodeWalrus stay online by donating here.

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

Started by c4ooo, July 22, 2016, 07:40:10 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

c4ooo

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.

Yuki

  • Calculators owned: TI-83+ (dead?), Casio Prizm (also dead???)
  • Consoles, mobile devices and vintage computers owned: A lot
Read Zarmina!
YUKI-CHAAAANNNN
In the beginning there was walrii. In the end there will be walrii. All hail our supreme leader :walrii: --Snektron

if you wanna throw money at me and/or CodeWalrus monthly it's here

Dream of Omnimaga

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)
  • Calculators owned: TI-82 Advanced Edition Python TI-84+ TI-84+CSE TI-84+CE TI-84+CEP TI-86 TI-89T cfx-9940GT fx-7400G+ fx 1.0+ fx-9750G+ fx-9860G fx-CG10 HP 49g+ HP 39g+ HP 39gs (bricked) HP 39gII HP Prime G1 HP Prime G2 Sharp EL-9600C
  • Consoles, mobile devices and vintage computers owned: Huawei P30 Lite, Moto G 5G, Nintendo 64 (broken), Playstation, Wii U

c4ooo

#3
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

Dream of Omnimaga

Hm glad you are getting some collision detection to work. :)

Supersonic Ball 3D?
  • Calculators owned: TI-82 Advanced Edition Python TI-84+ TI-84+CSE TI-84+CE TI-84+CEP TI-86 TI-89T cfx-9940GT fx-7400G+ fx 1.0+ fx-9750G+ fx-9860G fx-CG10 HP 49g+ HP 39g+ HP 39gs (bricked) HP 39gII HP Prime G1 HP Prime G2 Sharp EL-9600C
  • Consoles, mobile devices and vintage computers owned: Huawei P30 Lite, Moto G 5G, Nintendo 64 (broken), Playstation, Wii U

Snektron

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 ;)
  • Calculators owned: TI-84+
Legends say if you spam more than DJ Omnimaga, you will become a walrus...


c4ooo

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 :(

Snektron

I won't be able to test it since im running Linux on this laptop :(
  • Calculators owned: TI-84+
Legends say if you spam more than DJ Omnimaga, you will become a walrus...


E37

  • Consoles, mobile devices and vintage computers owned: Ti83,Ti84!
I've never finished a project, there is always a way to improve!
What's my calc's name? Convert $37 to decimal. Look up that element in the periodic table. Then take the abbreviation of that element and you have it!
Look! A slime!    <(^.^)>

Snektron

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 :(
  • Calculators owned: TI-84+
Legends say if you spam more than DJ Omnimaga, you will become a walrus...


c4ooo

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 :) ?

Dream of Omnimaga

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)
  • Calculators owned: TI-82 Advanced Edition Python TI-84+ TI-84+CSE TI-84+CE TI-84+CEP TI-86 TI-89T cfx-9940GT fx-7400G+ fx 1.0+ fx-9750G+ fx-9860G fx-CG10 HP 49g+ HP 39g+ HP 39gs (bricked) HP 39gII HP Prime G1 HP Prime G2 Sharp EL-9600C
  • Consoles, mobile devices and vintage computers owned: Huawei P30 Lite, Moto G 5G, Nintendo 64 (broken), Playstation, Wii U

c4ooo

#12
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.

Dream of Omnimaga

Ah I see now. And yeah I thought the file name was wrong at first.
  • Calculators owned: TI-82 Advanced Edition Python TI-84+ TI-84+CSE TI-84+CE TI-84+CEP TI-86 TI-89T cfx-9940GT fx-7400G+ fx 1.0+ fx-9750G+ fx-9860G fx-CG10 HP 49g+ HP 39g+ HP 39gs (bricked) HP 39gII HP Prime G1 HP Prime G2 Sharp EL-9600C
  • Consoles, mobile devices and vintage computers owned: Huawei P30 Lite, Moto G 5G, Nintendo 64 (broken), Playstation, Wii U

c4ooo


Powered by EzPortal