Heteroclinic.net logo

www.heteroclinic.net

Jgts Demo 1.0 Smooth Shading of GTS models
13

201608

We mentioned particularly about the camera setting. If you start a basic OpenGL project from scratch, normally tuning the camera needs some effort. For examples, we show the boudings of model bunny.gts and cube.gts as the following.

bunny.gts:

cube.gts:

If you can compare the boundings of these two models, the size of bunny is so small. In reality, many confused for such model failed to be rendered than scale the model or change settings of the camera. We will explain our approach.

Jgts Demo 1.0 Smooth Shading of GTS models
14

201608

First, we know for the given camera setting, model.OBJ_SIZE =10.0f, is a good size for the model being rendered. So far we only discuss the scenario to render only one model without any translation (displacement to where other than the origin). We use the following code to compute the scale to use, we can either scale up, or scale down.


Here we use division operation without any guard by assuming we can trust the model creator that their data will not cause exception by dividing zero. For mission critical system, or you just don't want the program crash without any clue, such assumption should not be made for granted. The scale computed is to make the largest length dimension to fit to OBJ_SIZE. Other dimensions scale together with this scale but may not fit to OBJ_SIZE.

Jgts Demo 1.0 Smooth Shading of GTS models
15

201608

After the scale is computed, we can use the following function to scale the model.

Jgts Demo 1.0 Smooth Shading of GTS models
16

201608

It is not a simple scale call, we also repostion the model to the origin (0f,0f,0f).


For model bunny, we have (ymin,ymax: 0.0,0.187321), if we don't reposition, the scaling will be incorrect. The following picture is proper scaling while setting the OBJ_SIZE be 1.5f.
jgtsdemo1d0_04_repostioned.png


If we change the offset function as the following:

The result will be the following:
jgtsdemo1d0_05_withoutrepostioning.png