User:Igabriel85/Computer graphics/2014-2015/Laborator 9

USING COMPLEX OBJECTS
There are cases in which the objects we need to draw are to complex for us to draw them ourselves. In such cases (J)OGL allows us to load object models generated by using various tools such as 3D Studio Max (.3ds files). Other formats include .md2, .md3, .obj, etc.

Importing these custom made objects requires a parser. Usually the developer has to create himself or use an existing API (JOGL Utils). which transforms the file into a stream of OpenGL primitives -- points, lines and simple surfaces.

Installation

 * Download the .jar file from the project site: JOGL Utils
 * joglutils.jar -- platform independent run-time
 * Copy the .jar file inside your project lib folder
 * Add it to the class-path

Rendering the model
NOTE: You can find .3ds files on the internet by a simple search query: http://www.google.com/search?hl=en&q=free+3ds+models or try the examples from the following link: 3DS

NOTE: We could use the MyModel class also found in the same API and its load(GLAutoDrawable, String) and render(GLAutoDrawable) methods for loading and rendering objects with textures on them.

Alternatives?
Sure! You could use any of the classes found on the Internet for loading 3ds, obj or other format files.

A simple obj loader can be found at

Links:


 * NeHe tutorial
 * Java port of the NeHe tutorial

Billboards
A billboard is a 2D texture which always faces the camera. Its main use is for particles, simulating forests (trees), distant mountains, etc.

Steps for orienting the billboard towards the camera

 * recompute the vertices based on the distance between the billboard and the camera
 * use the updated vertices to draw the quad which will be used to draw the texture on

The following code shows an example on how we can rotate the coordinates to always face the camera. You will also need the TextureHandler class (and its dependencies) to see it work:

If we want to use the camera and navigate through the billboards we need to do several other steps:


 * Get the code for aimCamera and moveCamera
 * Make bbAngle=0 (in the previous example it was changing constantly inside the updateCoordinates method)
 * Change camCx, camCy and camCz variables to point to the actual camera coordinates

The following example shows all of the previous in detail:

Links:


 * NeHe billboards tutorial;
 * Lighthouse billboards about;

Exercise

 * Given the previous scene from the previous laboratory add some 3DS objects to the scene as follows:
 * add a comet like mesh to the scene and make it rotate around its OY axis and around the Sun
 * add a space ship mesh to the scene and place it around Earth's orbit
 * Add the Sun rays to the sphere representing it. Make it a billboard.

NOTE: search for corresponding textures and 3DS objects on the Internet. (http://www.celestiamotherlode.net/ is a good place to look into)

NOTE: the Sun ray billboard should slice the sun into two equal semi-spheres.