This site requires JavaScript, please enable it in your browser!
Greenfoot back

Report as inappropriate.

SPower
SPower presents ...

2019/8/20

3D cubes demo

This scenario can render 3D objects consisting of polygons (instead of only triangles) of different colours. It is fully 3D, meaning that its camera can be turned in any direction, and have the program render the world appropriately.

To illustrate its capabilities, a demo is included, showing 400 small cubes (of a random colour), along with a larger one that misses two sides, and which has a triangle inside of it. Note that the downloaded version runs much faster (consistent 61 FPS in this demo) than the online HTML5 version.

Controls for the demo are:
- wasd to move the camera forward/backward or sideways;
- arrow keys to turn the camera
- z and x to rotate the camera around its axis.

The source code is available and documented.

Some details on how it works: it renders by thinking of the screen as an object in 3D space itself. This is achieved by giving the camera a location (which can be thought of as the 'focal point'), a direction that the player is looking at, and two directions which tell what looks like the 'left-right' direction on screen, and the 'up-down' direction. These last two directions must always be orthogonal.

To illustrate, the z and x keys rotate the 'left-right' and 'up-down' around the direction of the player, whereas the arrow keys change the direction of the player.

The rendering is done from back to front: all objects are sorted from back to front, first drawing those furthest away.

The controls can be fully modified to create many different effects, such as an airplane-like behaviour, walking behaviour, etc.

The FPS counter is taken from mjrb4 (see https://www.greenfoot.org/scenarios/261).

538 views / 76 in the last 7 days

5 votes | 0 in the last 7 days

Tags: demo with-source

This scenario is a member of: Reusable actors & support classes, 3D


open in greenfoot
Your browser does not support the canvas tag.
This is beautiful, well done
soccer28JGsoccer28JG

2019/8/29

I like how you change colors.

Want to leave a comment? You must first log in.

Who likes this?

soccer28JG Super_Hippo secretbackupboss danpostismyhero valdes