3d dice roller

Showcase your libraries, tools and other projects that help your fellow love users.
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: 3d dice roller

Post by kikito »

wait ... you mean that the background isn't pre-rendered???

...

(Notices the camera changes and the mouse over detection in 3D)

Holy fucknut. This is serious business.

I've tried to browse the code. I could not follow most of it, but at least I could gather the "main objective" of each file.

Key point: when it says "star" it means "3d physical object", and when it says "die" it means "dice". Understanding this was essential; the code made no sense without that insight.
  • base.lua defines some top-level functions, such as clone (used for pseudo-oo, it seems)
  • vector.lua defines vectors and quaternions.
  • view.lua seems to control the camera
  • geometry.lua seems to contain definitions of the different 3-d shapes of dices
  • stars.lua seems to be a "generic 3d shape manager", handling mostly collisions.
  • loveplus adds some functions to love.
  • render.lua has all the rendering functions - for the ground tiles, the light bulb, the dice ("dies") and their shadows. This is the file that does the "3d texturing" of faces. In order to do it, it mainly uses a new function called love.graphics.transform (defined in loveplus.lua)
  • main.lua is interesting because that's where the mouse interaction is handled
I liked that the vectors definition was quite succint.

I didn't like the naming of "stars" and "die" - made it quite difficult to understand. Also, since I come from an object-oriented world, I would have preferred reorganizing the files "in groups of objects" instead of "in groups of functionality". For example, I would have had a D6.lua with all the geometry and rendering for a D6, and so on for D4.lua, Lightbulb.lua, Ground.lua, Shadow.lua, etc. But that's pretty much personal taste.
When I write def I mean function.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: 3d dice roller

Post by Robin »

kikito wrote:when it says "die" it means "dice".
FYI, die is singular of dice. (One die, two dice.)
Help us help you: attach a .love.
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: 3d dice roller

Post by kikito »

hah. I didn't know that. I allways used "dice" ... come to think of it, I have never used a single die in English.

I retire what I said about dice and die.

While we are on the subject, does "star" has any 3d-object-related definition I should know about? Appart from the fact that real stars (the astronomical objects) are physical and three-dimensional, I mean.
When I write def I mean function.
way
Prole
Posts: 8
Joined: Thu Apr 29, 2010 3:18 pm

Re: 3d dice roller

Post by way »

Hello!

Yeah, well following the code might not be the easiest, I am learning Lua while doing this. kikito's assessment is correct on the main objectives of the individual files.

I chose the name "star" in order to avoid "object" as it is way too loaded in a software context. I call it a star because in the simulation part dice are treated as a set of points connected rigidly to a center, like a hedgehog or the rays shining from a star. "hedgehog" would sound kinda silly, wouldn't it? There are no faces or anything else complicated in the physics part.

There are severe limitations in this "engine", in the simulation, in the lighting model and also in the rendering. I think that this scenario (a few dice in a box, maybe up to 1000 polygons total plus a single light source) is all that Lua+Löve can handle with this approach.

Physics:
The engine handles a set of stars, ie. dice, as explained above. There is some collision handling going on with the walls of a box around the scene. To ease on collision detection, walls are just infinite, immovable planes, and dice bounce off them. Die-die collision is working at my desktop, but it treats dice as solid balls bouncing off each other with some friction. There is no sensible way to do collision detection on polyhedra or do proper edge-edge or resting contacts. It's just way too calculation intensive.

Lighting:
It is a per-polygon lighting model, as any more advanced per-pixel calculations are prohibitively expensive and there is no way to do pixel manipulation in Löve anyways. It is quite a toll on performance, i think half of the time is spent on calculating incidence angles and such. Also shadows are somewhat of a cheat here, you can see that shadows are not cast on another die; only onto the background, drawn as semitransparent polygons.

Rendering:
The only tricky part in rendering is the love.graphics.transform function: it rotates and shears an image until it fits onto any parallelogram. If we had access to the transformation matrix proper, these tricks would not be necessary. What it cannot do is perspective projection: you cannot use big textures. Perspectivic "shortening" can not be done in a single texture, as the perspectivic projection of a rectangle in general is not a parallelogram, but an irregular quadrilateral. If you look at the background closely, you can see that the rectangles are not aligned properly. If you use bigger rectangles, this effect is very noticeable. So it is good for mostly transparent textures, like a number, but not good for "full" textures.

For the physics part I've used http://www.cs.cmu.edu/~baraff/sigcourse/ as the main reference, you might want to look at it. Maths, lighting and rendering is my own stuff, wikipedia and other random sources helped. The source code is maintained at http://bitbucket.org/way/dice3d, take a look at some improvements. I am doing some wild experiments though so do not expect anything to be in a working condition :).

I think that doing 3D rendering+physics in Löve is probably not the way to go, this is more of a learning project than some engine that can be reused later. There are some optimizations I can see here and will do later, but in general you should not base your 3d engine on this. However, it is much fun.


way
User avatar
Jasoco
Inner party member
Posts: 3655
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: 3d dice roller

Post by Jasoco »

I didn't realize the transform stuff was for single images as well. I thought it only manipulated the whole screen. Looks like there's still a lot I need to learn. lol

I need to look at this code more closely. Do some fooling around and see if I can get something working myself. I had started on a 3D project a few months ago and gave up on it. This is so much more advanced. I wonder if this could be modified into a Star Fox clone too. Guess it depends on the limits. How much faster does it get if you disable lighting calculations? In my engine, turning off backfaces, disabling lighting and just using pre-shaded polygons made my engine much faster. (Since Star Fox never used that fancy stuff anyway.)
pekka
Party member
Posts: 206
Joined: Thu Jan 07, 2010 6:48 am
Location: Oulu, Finland
Contact:

Re: 3d dice roller

Post by pekka »

This demo is impressive in many ways, but trying to make 3D games like this is foolish and terribly limited. What's more, doing a little web searching one easily finds potentially usable 3D engines with Lua scripting, like Luxinia and Cafu. Let's use Löve for games Löve is most suitable for, and let's use other tools when we want to do other things.

http://www.luxinia.de/
http://www.cafu.de/

(Disclaimer: I picked these two from the list of search results based on them having their news pages updated this year. I haven't actually used or even downloaded either one of them.)
User avatar
vrld
Party member
Posts: 917
Joined: Sun Apr 04, 2010 9:14 pm
Location: Germany
Contact:

Re: 3d dice roller

Post by vrld »

pekka wrote:This demo is impressive in many ways, but trying to make 3D games like this is foolish and terribly limited.
I believe this is not the point. Just sit back and enjoy this awe inspiring hack ;)
I have come here to chew bubblegum and kick ass... and I'm all out of bubblegum.

hump | HC | SUIT | moonshine
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: 3d dice roller

Post by kikito »

Being awesome is a very valid reason.

Also, the Cafu About "Us" page is quite entertaining.

I am now a fan of Carsten Fuchs.
When I write def I mean function.
User avatar
Jasoco
Inner party member
Posts: 3655
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: 3d dice roller

Post by Jasoco »

way wrote:Rendering:
The only tricky part in rendering is the love.graphics.transform function: it rotates and shears an image until it fits onto any parallelogram. If we had access to the transformation matrix proper, these tricks would not be necessary. What it cannot do is perspective projection: you cannot use big textures. Perspectivic "shortening" can not be done in a single texture, as the perspectivic projection of a rectangle in general is not a parallelogram, but an irregular quadrilateral. If you look at the background closely, you can see that the rectangles are not aligned properly. If you use bigger rectangles, this effect is very noticeable. So it is good for mostly transparent textures, like a number, but not good for "full" textures.
Yeah, I just noticed that while playing around. I colored the tiles to show what it actually does here:
Screen shot 2010-07-16 at 8.59.30 PM.PNG
Screen shot 2010-07-16 at 8.59.30 PM.PNG (48.43 KiB) Viewed 4557 times
It's not seamless. This would be a moot point if we could simply warp an image over any 4-sided shape. Distort it. Place the four corners anywhere. Or even some simple 3D transforms like CSS3 can do.

Obviously this means the engine you created wouldn't work for real textured 3D games, but like mine, could still be used for some simple 3D games with solid polygons. Like so:
Screen shot 2010-07-16 at 9.17.52 PM.PNG
Screen shot 2010-07-16 at 9.17.52 PM.PNG (55.73 KiB) Viewed 4557 times
I will have a lot of fun with this project. Maybe my dream of a Star Fox shoot-em-up clone might still come true.
User avatar
Luiji
Party member
Posts: 396
Joined: Mon May 17, 2010 6:59 pm

Re: 3d dice roller

Post by Luiji »

Jasaco made a LÖVE Starfox clone, I believe.
Good bye.
Post Reply

Who is online

Users browsing this forum: No registered users and 9 guests