RSS

Source Code (AcnodeLabs 3D Planets)

#include "../../Util/CBaseV1_2.h"

#define BTN_CLOSE 7

#define ANIMSEQ_SPHERE 1
#define ANIMSEQ_SURFACE 2
#define ANIMSEQ_LAND 3
#define ANIMSEQ_SLINGSHOT 4

//PLANETS APP

#define NUMSTARS (160)
#define ID_STARDOME (10)
#define ID_FONTS (ID_STARDOME+3)

#define SOUND_COSMOS 0
#define SOUND_SPHERE 1
#define SOUND_SURFACE 2
#define SOUND_LAND 3
#define SOUND_SLINGSHOT 4

class App {

public:

char pl9[9][256];
FontMap16x16 fonts;

static const short USER_ALXFILENAME=1;

GLfloat xrot; // X Rotation
GLfloat yrot; // Y Rotation
GLfloat xspeed; // X Rotation Speed
GLfloat yspeed; // Y Rotation Speed
GLfloat z; // Depth Into The Screen

short light;
short blend;
short depth;

//TextureImage texture[1];

CResourceManager rm;

GLfloat LightAmbient[4];//= { 0.5f, 0.5f, 0.5f, 1.0f };
GLfloat LightDiffuse[4];//= { 1.0f, 1.0f, 1.0f, 1.0f };
GLfloat LightPosition[4];//= { 0.0f, 0.0f, 2.0f, 1.0f };

public:
PEG output;
PEG input;

char szP1[256];
char alxfilename[256];
float zmax;
short planetNum;
short starpos[3][NUMSTARS];

float boundz(CModel* m) {
zmax = 0;
for (int i=0; in_vertices*3;i++) {
zmax =(m->vertex_array[i]>zmax?m->vertex_array[i]:zmax);
}
xspeed = 0;
yspeed = 0;

return zmax;
}

Controls controls;
short numv;

float eye[3];
float eyerot[3];
float tgt[3];
CAnimator can;

float animstep;

short keyframe;

void AnimDo() {
float bz = boundz(rm.models[planetNum]);
float pointAz = bz*5;

if (nseq==ANIMSEQ_SPHERE) {

static float tgt0, tgt1, tgt2,eye0,eye1,eye2,eyerot2;

if (keyframe==1) {
tgt0 = tgt[0] ;tgt1 = tgt[1];tgt2 = tgt[2];eye0 = eye[0] ;eye1 = eye[1];eye2 = eye[2];eyerot2=eyerot[2];
animstep = 0;
keyframe = 2;
}

if (keyframe==2) {
tgt[0] = can.QuadraticEaseIn(animstep, tgt0, 0.0f);
tgt[1] = can.QuadraticEaseIn(animstep,tgt1, 0.0f);
tgt[2] = can.QuadraticEaseIn(animstep,tgt2,0.0f);
eye[0] = can.QuadraticEaseIn(animstep,eye0,0.0f);
eye[1] = can.QuadraticEaseIn(animstep,eye1,0.0f);
eye[2] = can.QuadraticEaseIn(animstep,eye2,- pointAz);
eyerot[2] = can.QuadraticEaseIn(animstep,eyerot2,0.0f);
animstep += 0.01f;
if (animstep>1 ) {animstep =0; nseq = 0;}
}

}

if (nseq==0) {
tgt[0] = tgt[1] = tgt[2] = 0;
eye[0] = 0;
eye[1] = 0;
eye[2] = -bz*5;
eyerot[2] = 0;
keyframe = 1;

}

if (nseq==ANIMSEQ_SURFACE) { //SURFACE VIEW

if (keyframe==1) {
tgt[0] = can.QuadraticEaseIn(animstep, 0.0f, -bz);
tgt[1] = can.QuadraticEaseIn(animstep,0.0f, 0.0f);;
tgt[2] = can.QuadraticEaseIn(animstep,0.0f, 0.0f);
eye[0] = can.QuadraticEaseIn(animstep,0.0f,- bz);
eye[1] = can.QuadraticEaseIn(animstep,0.0f, 0.0f);
eye[2] = can.QuadraticEaseIn(animstep,- pointAz,- bz*1.1);
eyerot[2] = can.QuadraticEaseIn(animstep,0.0f, 90);
animstep += 0.01f;
if (animstep>1 ) {animstep =0;keyframe = 2 ;}

}

if (keyframe ==2) {
animstep += 0.00001f;
if (animstep>1 ) {animstep =0;}
}

}

if (nseq==ANIMSEQ_SLINGSHOT) { //SLINGSHOT
//KeyFrame 1
if (keyframe==1) {
tgt[0] = can.QuadraticEaseIn(animstep, 0.0f, bz*1.01);
tgt[1] = can.QuadraticEaseIn(animstep,0.0f, 0.0f);
tgt[2] = can.QuadraticEaseIn(animstep,0.0f, 0.0f);
eye[0] = can.QuadraticEaseIn(animstep,0.0f, bz*1.01);
eye[1] = can.QuadraticEaseIn(animstep,0.0f, 0.0f);
eye[2] = can.QuadraticEaseIn(animstep,- pointAz,- bz*1.05);
eyerot[2] = can.QuadraticEaseIn(animstep,0.0f, 90.f);
animstep += 0.01f;
if (animstep>1 ) {animstep =0;keyframe=2;}
}

if (keyframe==2) {
static float yrotin = yrot;
yrot+=1;
if (yrot>(yrotin+180)) {keyframe =3;animstep=0;}
}

if (keyframe==3) {
yrot+=1.4f;
tgt[0] = can.QuadraticEaseIn(animstep, bz*1.01, 0);
tgt[1] = can.QuadraticEaseIn(animstep,0.0f, 0.0f);
tgt[2] = can.QuadraticEaseIn(animstep,0.0f, -1.0f);
eye[0] = can.QuadraticEaseIn(animstep,bz*1.01,0.0f);
eye[1] = can.QuadraticEaseIn(animstep,0.0f, 0.0f);
eye[2] = can.QuadraticEaseIn(animstep,- bz*1.05, - pointAz);
eyerot[2] = can.QuadraticEaseIn(animstep,90.f, 0.f);
animstep += 0.01f;
if (animstep>1 ) {animstep =1;yrot-=1.4f;}
}

}

if (nseq==ANIMSEQ_LAND) { //Land
//KeyFrame 1
yrot+=0.2; //cancel out movement
float alt = bz*1.3;

if (keyframe==1) {
tgt[0] = can.QuadraticEaseInOut(animstep, 0.0f, - alt);
tgt[1] = 0; tgt[2]=0;
eye[0] = 0; eye[1]=0;
eye[2] = can.QuadraticEaseIn(animstep,- pointAz,- alt);
eyerot[2] = can.QuadraticEaseIn(animstep,0.0f, 90.f);
animstep += 0.0025f;
if (animstep>1 ) {animstep =0;keyframe=2;}
}

if (keyframe==2) {
eye[2] = can.QuadraticEaseIn(animstep,- alt, -bz*1.2f);
animstep += 0.002f;
if (animstep>1 ) {animstep =0;keyframe = 3;}
}

if (keyframe==3) {
keyframe = 1; nseq=ANIMSEQ_SPHERE;
}

}

}

int nseq;

void PrintInfo(short planeNum) {
char line[256];
strcpy(line, pl9[planeNum]);
numv = 0;
char * pch = strtok (line,"\n");
while (pch != NULL)
{
fonts.print(pch);
numv++;
if (numv>84) numv=0;
//rm.models[ID_FONTS]->n_vertices = numv;
rm.models[ID_FONTS]->glDraw();
pch = strtok (NULL, "\n");
glTranslatef(0,-2.0f,0);
}

}

void Render(int aX, int aY, int aZ) {

processInput();
glClearColor(0,0,0,1);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer

for (int i =0; i<NUMSTARS; i++) {
if ((abs(starpos[0][i])<3 || abs(starpos[1][i])<3 || abs(starpos[2][i])glDraw();
billboardEnd();
} else {
glLoadIdentity();
}
}

glLoadIdentity();

AnimDo();
glRotatef(eyerot[2], 0,0,1);
aluLookAt(eye[0],eye[1],eye[2], tgt[0],tgt[1],tgt[2], 0,1,0);

//planetNum = 1;
if (z>-1.00000000f) {
z = -1.0f;
}

yrot-=0.2f;

/*
if (z>20.00000000f) {
planetNum = planetNum+1;
z = -15.0000000000f;
if (planetNum>8) planetNum=0;
output.pushP(CMD_TITLE, $ rm.models[planetNum]->name, 0);
//output.pushP(CMD_SNDPLAY0, $ "planets.wav",0);
}
*/
// z+=0.15f;

glRotatef(yrot,0.0f,1.0f,0.0f);
if (rm.models[planetNum]) {
rm.models[planetNum]->glDraw();
}

//HUD DI
//Misc
glLoadIdentity();
//glTranslatef(0,0.7,-2.0f);
glTranslatef(0,0.7,-2.0f);

glRotatef(180,0,0,1);
rm.models[ID_STARDOME+2]->glDraw();

glLoadIdentity();
// Reset The Current Modelview Matrix
glDisable(GL_DEPTH_TEST);
glTranslatef(-20.0f,-15.0f,-85.f);
glColor4f(0,1,0,0.5f);
PrintInfo(planetNum);

// static float angle = 0.1f;
// angle+=0.5f;
glLoadIdentity();
//DRAW TABBAR
float s1 = 0.76f;
glTranslatef(s1,0,-3.1f);
//glRotatef(angle,1,0,0);
rm.models[ID_STARDOME+1]->glDraw();
glTranslatef(-s1*2,0,0);
glRotatef(180,0,0,1);
rm.models[ID_STARDOME+1]->glDraw();
glEnable(GL_DEPTH_TEST);

glPopMatrix();
}

bool nearv;

void Init(char* path) {

nearv = false;
nseq = 0;

sprintf(pl9[0],"Planet MERCURY\n4878 km diameter\n0 moons\n0 rings\n-279 F to 800 F\n88 Earth days = 1 Mercury year\n59 Earth days = 1 Mercury day\n.06 mass\n.3 AU from the Sun");
sprintf(pl9[1],"Planet VENUS\n12,104 km diameter\n0 moons\n0 rings\n900 F\n225 Earth days = 1 Venus year\n243 Earth days = 1 Venus day\n.82 mass\n.7 AU from the Sun");
sprintf(pl9[2],"Planet EARTH\n12,756 km diameter\n1 moon\n0 rings\n56 F\n365 days = 1 Earth year\n24 hours = 1 Earth day\n1 mass\n1 AU from the Sun");
sprintf(pl9[3],"Planet MARS\n6795 km diameter\n2 moons\n0 rings\n-200 to 70 F\n687 Earth days = 1 Mars year\n24.5 Earth hours = 1 Mars day\n.1 mass\n1.67 AU from the Sun");
sprintf(pl9[4],"Planet JUPITER\n142,985 km diameter\n63 moons\n3 rings\n-150 F\n12 Earth years = 1 Jupiter year\n10 Earth hours = 1 Jupiter day\n318 mass\n5 AU from the Sun");
sprintf(pl9[5],"Planet SATURN\n120,537 km diameter\n33 moons\n4 main and thousands of smaller rings\n-300 F\n30 Earth years = 1 Saturn year\n10.5 Earth hours = 1 Saturn day\n95 mass\n9 AU from the Sun");
sprintf(pl9[6],"Planet URANUS\n51,119 km diameter\n21 known moons\n11 rings\n-350 F\n84 Earth years = 1 Uranus year\n15 Earth hours = 1 Uranus day\n14.5 mass\n19 AU from the Sun");
sprintf(pl9[7],"Planet NEPTUNE\n50,538 km diameter\n13 known moons\n4 rings\n-260 F\n165 Earth years = 1 Neptune year\n18 Earth hours = 1 Neptune day\n17 mass\n30 AU from the Sun");
sprintf(pl9[8],"Planet PLUTO\n2320 km diameter\n3 moons\n0 rings\n-370 F\n249 Earth years = 1 Pluto year\n6.5 Earth days = 1 Pluto day\n.003 mass\n49 AU from the Sun");

float size[] = {4880,7500,7500,4444,9900,9500,8000,8000,4880,2274};

for (int i=0; iname, "Mercury");
rm.loadAlxModel((char*) "sphere.alx", (char*) "venus.tga", 1, size[1]*sc);
strcpy(rm.models[1]->name, "Venus");
rm.loadAlxModel((char*)"sphere.alx", (char*) "earth.tga", 2, size[2]*sc);
strcpy(rm.models[2]->name, "Earth");
rm.loadAlxModel((char*) "sphere.alx", (char*) "mars.tga", 3, size[3]*sc);
strcpy(rm.models[3]->name, "Mars");
rm.loadAlxModel((char*) "sphere.alx", (char*) "jupiter.tga", 4, size[4]*sc);
strcpy(rm.models[4]->name, "Jupiter");
rm.loadAlxModel((char*) "sphere.alx", (char*) "saturn.tga", 5, size[5]*sc);
strcpy(rm.models[5]->name, "Saturn");
rm.loadAlxModel((char*) "sphere.alx", (char*) "uranus.tga", 6, size[6]*sc);
strcpy(rm.models[6]->name, "Uranus");
rm.loadAlxModel((char*) "sphere.alx", (char*) "neptune.tga", 7, size[7]*sc);
strcpy(rm.models[7]->name, "Neptune");
rm.loadAlxModel((char*) "sphere.alx", (char*) "pluto.tga", 8, size[8]*sc);
strcpy(rm.models[8]->name, "Pluto");

rm.loadAlxModel((char*) "font.alx",AUTO, ID_FONTS,1);
fonts.usetexof(rm.models[ID_FONTS]);

rm.loadAlxModel((char*) "misc.alx", AUTO, ID_STARDOME+2, 0.55f);
strcpy(rm.models[ID_STARDOME+2]->name, "misc");
rm.loadAlxModel((char*) "tabbar.alx",AUTO, ID_STARDOME+1, 0.05f);
strcpy(rm.models[ID_STARDOME+1]->name, "Tabbar");
rm.loadAlxModel((char*)"star.alx", AUTO, ID_STARDOME, 0.1f);
strcpy(rm.models[ID_STARDOME]->name, "Stardome");

planetNum = 0;
output.pushP(CMD_SNDPLAY0+SOUND_COSMOS, $ "cosmos.mp3",0);

xrot=0;
yrot=0;
z = - 20.f;
xspeed = 0.3;
yspeed = 0.3;
light = 0;
blend = 0; glDisable(GL_BLEND);
depth = 1; glEnable(GL_DEPTH_TEST);

for (int i =0; i<NUMSTARS; i++) {
starpos[0][i] = rndm()*40-20;// + 20;
// if (abs(starpos[0][i]<10)) starpos[0][i] *= 10;
starpos[1][i] = rndm()*40-20;// + 20;//updown angle +-90 deg;;//;rndm();
// if (abs(starpos[1][i]<10)) starpos[1][i] *= 10;
starpos[2][i] = rndm()*40-20;// + 20;//360;//rotatex;//70-i*2;//rndm();
// if (abs(starpos[2][i]command) {

case CMD_SCREENSIZE:
{
controls.screen[0] = p->i1;
controls.screen[1] = p->i2;
break;
}

case CMD_TOUCH_START:

{
x = p->i1;
y = p->i2;

if (y0 && xxs*1/4 && xxs*2/4 && xxs*3/4 && xi1, p->i2))
{
case KROSS_UP:
{
// output.pushP(CMD_TOAST, $ pl9[planetNum], rm.models[planetNum]->name);
}
break;

case KROSS_DOWN:

{
nearv = !nearv;
}
break;

case KROSS_RIGHT:

planetNum++;
z = -18.0000000000f;
if (planetNum>8) planetNum=0;

nearv = false;
animstep = 0;
nseq=0;
break;
case KROSS_LEFT:
z = -18.0000000000f;
planetNum--;
if (planetNum<0) planetNum=5;

nearv = false;
animstep = 0;
nseq=0;

break;
}

}
break;
}
}

if (btn_close_hit) output.pushI(CMD_END, 0, 0);
}

};

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: