lcass
|
 |
«
Posted
2013-11-07 19:34:56 » |
|
Ive been working on a 3d game engine written in pure java and I have a version Im happy to show. current support: basic shapes such as squares drawing vertexs functional camera 3d line renderer infinate 3d plane Full bitmap texture support future support: More complex shapes such as tetrahedrons optimising rendering algorithms and determining weather and object is behind the camera (working on currently) support for a map array to store blocks The updated code will happily render 4000 cubes (no line removing algorithms for things like behind block) at 30 fps when the camera is focusing on a few a constant 200 fps can be expected here is the picture! http://gyazo.com/d40e865eb0bace45c9c47fb70f529729a wall of 2000 blocks (using a slightly more optimised code) at 50 fps  More progress to come in the future! #######update!####### So I have been considering merging my old 2DGE project some of you might remember. However they will both be rewritten from scratch ( on the 3DGE just optimisation will occur) This will be released as a full graphics engine sometime in the future quite far in the future as I have a large amount of school work. Also a quick note, I have finalised the algorithm for rendering textures on the side of object (it will support custom image sizes in the future) For now its 32 by 32 for simplicity. More features such as a cameracontroller and an actual release will come soon when basic support for cubes and face rendering only if visible. LATEST UPDATE: TEXTURES! fully supporting all size textures I would like to thank this genius over here ----> http://www.java-gaming.org/index.php?topic=25271.0 Of course the code isnt perfect when implemented in mass so im doing some optimisations but I was struggling to understand it until I saw that so big thanks. Welp time for the pics!   With a few more frame tests I have massive improvements. the ability to render 500,000 textured and scaled triangles at 10 fps.
|
|
|
|
saucymeatman
|
 |
«
Reply #1 - Posted
2013-11-07 19:42:35 » |
|
This is really cool!  Are you using any engines to make it, JOGL or LWJGL? In the distant future will there be physics?
|
|
|
|
lcass
|
 |
«
Reply #2 - Posted
2013-11-07 19:45:36 » |
|
Nope pure java no external engines. Possibly its mainly just a graphics test
|
|
|
|
Games published by our own members! Check 'em out!
|
|
saucymeatman
|
 |
«
Reply #3 - Posted
2013-11-07 19:54:20 » |
|
Thats really sick. How do you plan for objects to no longer be rendered once they get behind the camera?
|
|
|
|
lcass
|
 |
«
Reply #4 - Posted
2013-11-07 20:22:26 » |
|
Honestly I have no clue I need something that could figure this out it would be a real help.
|
|
|
|
Opiop
|
 |
«
Reply #5 - Posted
2013-11-07 21:41:33 » |
|
I was going to to say, if you're using OpenGL, 2000 x 4 = 8000, and 8000 vertices isn't that much when rendering, and 50 FPS seems kind of low. Come to think of it, that seems a little low for Java2D, also. What kind of rendering are you using? A bufferedImage or are you literally calling drawSquare in the Java graphics library?
|
|
|
|
lcass
|
 |
«
Reply #6 - Posted
2013-11-07 22:02:30 » |
|
using a buffered image here is the rendering algorithm I use. This is unoptimised code like seriously unoptimised 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
| public void drawline(int x, int y, int xx, int yy) {
double grad = Math.atan2(xx - x, yy - y); double cx = x; double cy = y; double dist = Math.sqrt((Math.abs(xx - x)) * (Math.abs(xx - x)) + (Math.abs(yy - y)) * (Math.abs(yy - y))); double nx = Math.sin(grad); double ny = Math.cos(grad); for (int i = 0; i < dist; i++) { cx = (i*nx)+x; cy = (i*ny)+y; if (cx < core.WIDTH && cy < core.HEIGHT) { if (cx > 0 && cy > 0) { core.screen.map[(int) cx][(int) cy] = 0xFF00FF; } } }
}
public void drawnet(vertex v1, vertex v2, vertex v3, vertex v4, Camera c) { vertex[] v = new vertex[4]; Positionalobject[] po = new Positionalobject[4]; for (int i = 0; i < 4; i++) { po[i] = new Positionalobject(); } v[0] = v1; v[1] = v2; v[2] = v3; v[3] = v4; for (int i = 0; i < 4; i++) { double tx = v[i].x - c.x; double ty = v[i].y - c.y; double tz = v[i].z - c.z; if (tz < 500) { double sinex = Math.sin(c.rotx); double cosx = Math.cos(c.rotx); double cosy = Math.cos(c.roty); double siny = Math.sin(c.roty); double dx = 0; double my = 0; double mz = 0; double dz = 0; dx = tz * siny + tx * cosy; dz = tz * cosy - tx * siny; my = ty * cosx - dz * sinex; mz = dz * sinex + dz * cosx; double nx = (dx) * (scalex / mz) + (core.WIDTH / 2); double ny = (my) * (scaley / mz) + (core.HEIGHT / 2); nx = (scalex * dx / mz) + (core.WIDTH / 2); ny = (scaley * my / mz) + (core.HEIGHT / 2); double mmz = ((mz-c.z)+(nx-c.x)); po[i].x = nx; po[i].y = ny; po[i].z = mmz; }
} if (po[0].x < core.WIDTH && po[0].y < core.HEIGHT && po[0].x > 0 && po[0].y > 0) { drawline((int) po[0].x, (int) po[0].y, (int) po[1].x, (int) po[1].y); drawline((int) po[1].x, (int) po[1].y, (int) po[2].x, (int) po[2].y); drawline((int) po[2].x, (int) po[2].y, (int) po[3].x, (int) po[3].y); drawline((int) po[3].x, (int) po[3].y, (int) po[0].x, (int) po[0].y); } } |
edit just to note its not 8000 verticies its 22000 lines. as its not faces im drawing its full cube nets so rougly 16000 verticies.
|
|
|
|
wessles
|
 |
«
Reply #7 - Posted
2013-11-08 00:46:45 » |
|
This is amazing! Are you modelling this after lwjgl, with matrices and such?
|
|
|
|
kingroka123
|
 |
«
Reply #8 - Posted
2013-11-08 01:46:27 » |
|
Ah good old 3d math  gotta love it! This is pretty cool. can I ask where exactly you got the math from?
|
|
|
|
trollwarrior1
|
 |
«
Reply #9 - Posted
2013-11-08 06:49:33 » |
|
The only question I have is where did you get those fancy Eclipse colors?
|
|
|
|
Games published by our own members! Check 'em out!
|
|
lcass
|
 |
«
Reply #10 - Posted
2013-11-08 08:04:38 » |
|
HAh go onto youtube and look for something like darkmoon eclipse color. vanzeeban did one. To be honest I have never really used an external library. The math is from a site called gamdev.net.
Im thinking of upgrading the renderer though so instead of rendering as full shapes or lines I do sides this will allow facing comparison alot like minecrafts render technique. If a tile is facing another tile directly it is not drawn vice versa.
|
|
|
|
lcass
|
 |
«
Reply #11 - Posted
2013-11-08 08:12:50 » |
|
Quick test: in eclipse it seems 4000 blocks or rather 48000 lines is 30 fps 
|
|
|
|
rv3392
|
 |
«
Reply #12 - Posted
2013-11-08 08:43:44 » |
|
Amazing piece of work!
|
|
|
|
xsvenson
|
 |
«
Reply #13 - Posted
2013-11-08 09:37:19 » |
|
|
“The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson
|
|
|
saucymeatman
|
 |
«
Reply #14 - Posted
2013-11-08 11:55:39 » |
|
"To be honest I have never really used an external library. " I havent ever either. I like doing things myself.
|
|
|
|
lcass
|
 |
«
Reply #15 - Posted
2013-11-08 15:18:30 » |
|
Sorry its not 48000 lines it 96000 this is because it overlaps when drawing faces at the moment. Also I tested this on a computer with only standard intel graphics, double buffering and a core2duo (the cheaper range of them) I got 25fps as average for 96000 lines.
Also I have evaluated the use of the two mesh rendering techniques I came up with. the 1st choice which is to render lines across would be more efficient as its not rotating every single pixel in the shape.
|
|
|
|
lcass
|
 |
«
Reply #16 - Posted
2013-11-08 15:31:25 » |
|
Thanks for that link im going to try out a few methods including some more abstract ones that draw immediately.
|
|
|
|
lcass
|
 |
«
Reply #17 - Posted
2013-11-12 19:00:51 » |
|
Just a quick update: Finally supporting x and y axis rotation along with starting rendering of faces still trying to find a fast algorithm for that but lots of playing with it 
|
|
|
|
saucymeatman
|
 |
«
Reply #18 - Posted
2013-11-13 03:17:08 » |
|
Sweet! When is the texture update coming? 
|
|
|
|
lcass
|
 |
«
Reply #19 - Posted
2013-11-13 07:35:00 » |
|
When I can finally get my head around the line algorithm  .
|
|
|
|
lcass
|
 |
«
Reply #20 - Posted
2013-11-18 18:12:33 » |
|
OK so ive set a few goals for this project. 1: Fully develop a functioning 3d rendering that allows for quads and triangles to be rendered along with support for textures. 2: Integrate a fully functional maths api containing complex algorithms for handling line rendering , areas of complex shapes and other things that may be useful. 3: Support immediate and buffer based rendering techniques. 4: support 2d and 3d states allowing switching between both states without any hastle 5: Implement large amounts of optimisation to give the most performance. 6: Include advanced face culling algorithms to lower the amount of objects that need to be rendered.
* Things below here are most likely going to happen very late in the development 7: a dynamic lighting api and system. 8: 3d & 2d animation api 9: Advanced input support.
If there is anything you guys would think would be great then post them below!
|
|
|
|
lcass
|
 |
«
Reply #21 - Posted
2013-11-22 22:49:05 » |
|
TEXTURES ARE FINALLY ADDED!
|
|
|
|
hwinwuzhere
|
 |
«
Reply #22 - Posted
2013-11-23 15:35:33 » |
|
Great! Looking forward to more updates. Keep on the good work.
|
There are two kinds of people in this world: Those who can extrapolate from incomplete data,
|
|
|
lcass
|
 |
«
Reply #23 - Posted
2013-11-23 19:10:55 » |
|
Thanks the code I have needs massive optimisation now that I know how it works im going to rewrite it entirely.
|
|
|
|
lcass
|
 |
«
Reply #24 - Posted
2013-11-25 00:10:41 » |
|
so I've just done a few performance tests. The code is now optimised a little bit more there is a lot that can still be done however currently 256*256 textured 32 by 32 squares runs at 10 fps which is about 250000 squares or 500000 triangles.
|
|
|
|
Opiop
|
 |
«
Reply #25 - Posted
2013-11-25 01:12:20 » |
|
Well, it seems your engine runs just a little slower than immediate mode in OpenGL! Good job 
|
|
|
|
lcass
|
 |
«
Reply #26 - Posted
2013-11-25 13:57:22 » |
|
Still tonnes of optimisation to go. Also just to note ive fixed the anomolies turns out I was having to input the vertex coordinates of the objects on the screen as ints not doubles. I am going to give out a demo of the code that renders 256 * 256 squares controls are WASD to move around Shift to go up and SPACE to go down use the arrow keys to rotate the camera around. Download the demo just here. https://drive.google.com/file/d/0B48ywWBymi3OWmpVOXNMdHZLWms/edit?usp=sharingJust to note this current version does not support removing squares that are behind the camera so its a bit of an issue just havent been able to implement it. Managed to improve performance a lot by reducing the number of trig calls by about 99%
|
|
|
|
kpars
|
 |
«
Reply #27 - Posted
2013-12-31 09:48:38 » |
|
I love seeing a good-ol' Pseudo-3D engine nowadays. I'm developing one right now myself! (But in Python!)
Wonderful Work!
- Jev
|
|
|
|
HeroesGraveDev
|
 |
«
Reply #28 - Posted
2013-12-31 20:20:27 » |
|
Whenever I see the thread title pop up on the unread topics list I get excited at the idea of a 32D graphics engine  Anyway, this looks quite cool, and even though it's never going to be worth using when we have OpenGL, it's an awesome way to learn more about what OpenGL is actually doing. I'll have to try making one of these myself some time.
|
|
|
|
lcass
|
 |
«
Reply #29 - Posted
2013-12-31 21:35:31 » |
|
well actually, with future gpu access I will be able to make this hardware accelerated. for now though it is just an experiment as I would like to know the math.
|
|
|
|
|