Main Page | Namespace List | Class Hierarchy | Compound List | File List | Compound Members | File Members

skybox.cpp

Go to the documentation of this file.
00001 #include "skybox.h"
00002 #include <plib/ssg.h>
00003 
00004 #define SKYBOX_CALCULTIONTIME 1
00005 #define SKYBOX_RED   0.0f
00006 #define SKYBOX_GREEN 0.6f
00007 #define SKYBOX_BLUE  0.9f
00008 #define SKYBOX_VERTICES 100
00009 
00010 #include <stdio.h>
00011 
00012 skybox::skybox(float glFar) {
00013   ssgVtxTable* lower;
00014   ssgVtxTable* upper;
00015   ball = NULL;
00016   _init_geometry(glFar);
00017   ssgSimpleState* sstate = new ssgSimpleState;
00018   sstate -> setTexture ( "dummy_sky.rgb" ) ;
00019   sstate -> enable     ( GL_TEXTURE_2D ) ;
00020   sstate->enable(GL_LIGHTING);
00021   sstate->enable(GL_COLOR_MATERIAL);
00022   sstate->setShadeModel(GL_SMOOTH);
00023   sstate -> enable ( GL_CULL_FACE      ) ;
00024   sstate -> setColourMaterial ( GL_AMBIENT_AND_DIFFUSE ) ;
00025   sstate -> setMaterial ( GL_EMISSION, 0, 0, 0, 1 ) ;
00026   sstate -> setMaterial ( GL_SPECULAR, 0, 0, 0, 1 ) ;
00027   sstate->setShininess(0);
00028   sstate->setOpaque();
00029   sstate->disable(GL_BLEND);
00030 
00031 
00032   ball->setKidState(sstate);
00033 }
00034 
00035 skybox::~skybox() {
00036   delete ball;
00037 }
00038 
00039 void skybox::_init_geometry(float glFar) {
00040   sgVec3 vert;
00041   float mysize;
00042   if (ball != NULL)
00043     delete ball;
00044   ball = new ssgaSphere(SKYBOX_VERTICES);
00045   
00046   mysize = (glFar > 1.0f) ? glFar : SKYBOX_SIZE;
00047   printf("%i num kids\n", ball->getNumKids());
00048   ball->setSize(mysize);
00049   ball->removeKid(0);
00050   ball->removeKid(0);
00051   ball->removeKid(0);
00052   //ball->removeKid(0);
00053   upper = (ssgVtxTable*) ball->getKid(1);
00054   lower = (ssgVtxTable*) ball->getKid(0);
00055   lower->setCullFace(false);
00056 
00057   lower = (ssgVtxTable*) ball->getKid(2);
00058   
00059   lower->setCullFace(false);
00060 
00061   lower = (ssgVtxTable*) ball->getKid(3);
00062 
00063   upper->setCullFace(false);
00064   lower->setCullFace(false);
00065 
00066 }
00067 
00068 void skybox::update(sgVec3* anchor) {
00069   sgVec3 t;
00070   sgCopyVec3(t, *anchor);
00071   t[2] += 10.0f;
00072   ball->setCenter(t);
00073    ball->removeKid(0);
00074    ball->removeKid(0);
00075    ball->removeKid(0);
00076   for (int i=0; i < 4;i++) {
00077     lower = (ssgVtxTable*) ball->getKid(i);
00078     lower->setCullFace(false);
00079   }
00080 }
00081 

Generated on Sat Jul 12 04:29:21 2003 for glPirates by doxygen 1.3.2