#include <acknex.h>
#include <default.c>
///////////////////////////////////////////////////////////////
// some global definitions
ENTITY* eGD5;
ENTITY* eEN1[7];
ENTITY* Dust[300];
VECTOR vSpeed, vAngularSpeed, vForce, vMove;
VECTOR vVelocity;
///////////////////////////////////////////////////////////////
function UpdateDust(){
int n;
VECTOR camloc;
//vec_for_vertex(&camloc,eGD5,1651);
camloc.x=eGD5.x;
camloc.y=eGD5.y;
camloc.z=eGD5.z;
//in the following code of this function if you replace the text "camloc" with eGD5 it "works" best
//if you replace it with "camera" it freezes
for(n=0;n<50;n++){
if(Dust[n].x<(camloc.x-50)){
Dust[n].x=camloc.x+50;
Dust[n].y=random(100)-50;
Dust[n].z=random(100)-50;
}
if(Dust[n].x>(camloc.x+50)){
Dust[n].x=camloc.x-50;
Dust[n].y=camloc.y+random(100)-50;
Dust[n].z=camloc.z+random(100)-50;
}
if(Dust[n].y<(camloc.y-50)){
Dust[n].y=camloc.y+50;
Dust[n].x=camloc.x+random(100)-50;
Dust[n].z=camloc.z+random(100)-50;
}
if(Dust[n].y>(camloc.y+50)){
Dust[n].y=camloc.y-50;
Dust[n].x=camloc.x+random(100)-50;
Dust[n].z=camloc.z+random(100)-50;
}
if(Dust[n].z<(camloc.z-50)){
Dust[n].z=camloc.z+50;
Dust[n].x=camloc.x+random(100)-50;
Dust[n].y=camloc.y+random(100)-50;
}
if(Dust[n].z>(camloc.z+50)){
Dust[n].z=camloc.z-50;
Dust[n].x=camloc.x+random(100)-50;
Dust[n].y=camloc.y+random(100)-50;
}
}
}
///////////////////////////////////////////////////////////////
function flyEN1(ENTITY* ENT1){
VECTOR vForce1, vMove1;
VECTOR vHeadDiff;
VECTOR vDiff2;
vec_set(vHeadDiff,eGD5.x);
vec_sub(vHeadDiff,ENT1.x);
vec_to_angle(ENT1.pan,vHeadDiff);
ENT1.roll=-eGD5.roll;
vForce1.x=0;
vForce1.y=0;
vForce1.z=0;
//make vForce1=ENT1-eGD5;
//this is really nice how you get to use a function now in place of using an '=' operator
//eg:the clearly readable "vForce1=ENT1.pos-eGD5.pos"
//is now replaced by the next two lines beautiful beautiful beautiful
vec_set(vForce1,ENT1.x);
vec_sub(vForce1,eGD5.x);
vec_scale(vForce1,-0.001);
vec_scale(vForce1,0.4);
VECTOR oldENT1pos;
if(vec_dist(ENT1.x,eGD5.x)<3000){
vec_scale(vForce1,-1);
}
ENT1.x=ENT1.x+vForce1.x;
ENT1.y=ENT1.y+vForce1.y;
ENT1.z=ENT1.z+vForce1.z;
}
///////////////////////////////////////////////////////////////
function main()
{
// Activate 800x600 screen resolution and stencil shadows,
// and set the sound at full volume.
// Video_mode is a 'redefine' variable that has to be set
// before initializig the video device during the first wait().
video_mode = 7;
shadow_stencil = 1;
wait(3);
level_load("");
wait(-1);
// create a sky cube on layer 0
ent_createlayer("stars+6.tga", SKY | CUBE | VISIBLE, 0);
eGD5=ent_create("ringship.MDL",vector(0,0,0),NULL);
eGD5.scale_x=4*3;
eGD5.scale_y=4*3;
eGD5.scale_z=4*3;
int n;
for(n=0;n<7;n++){
eEN1[n]=ent_create("ringship.MDL",vector(n*400,n*300,n*500),NULL);
eEN1[n].scale_x=4*3;
eEN1[n].scale_y=4*3;
eEN1[n].scale_z=4*3;
}
for(n=0;n<50;n++){
Dust[n]=ent_create("Dust.bmp",vector(random(100)-50,random(100)-50,random(100)-50),NULL);
Dust[n].scale_x=0.01;
Dust[n].scale_y=0.01;
Dust[n].scale_z=0.01;
}
while (1)
{
int n;
for(n=0;n<7;n++){
flyEN1(eEN1[n]);
}
vForce.x = -1.5*(key_force.x + mouse_force.x); // pan angle
vForce.y = -1.5*(key_force.y + mouse_force.y); // tilt angle
vForce.z = -0.5*(key_a-key_d); // roll angle
c_rotate(eGD5,vForce.x,USE_AXISR);
vForce.x = 0.018 * (key_w - key_s); // forward after vec_rotate
vForce.y = 0.018 * (key_a - key_d); // sideward after vec_rotate
vForce.z = 0.018 * (key_home - key_end); // upward after vec_rotate
vec_rotate(vForce.x,eGD5.pan);
VECTOR LastPos;
VECTOR CurrentPos;
LastPos.x=eGD5.x;
LastPos.y=eGD5.y;
LastPos.z=eGD5.z;
CurrentPos.x=eGD5.x+vVelocity.x;
CurrentPos.y=eGD5.y+vVelocity.y;
CurrentPos.z=eGD5.z+vVelocity.z;
CurrentPos.x+=vForce.x;
CurrentPos.y+=vForce.y;
CurrentPos.z+=vForce.z;
vVelocity.x=CurrentPos.x-LastPos.x;
vVelocity.y=CurrentPos.y-LastPos.y;
vVelocity.z=CurrentPos.z-LastPos.z;
vec_scale(vVelocity.x,0.99);
eGD5.x=CurrentPos.x;
eGD5.y=CurrentPos.y;
eGD5.z=CurrentPos.z;
VECTOR camloc;
vec_for_vertex(&camloc,eGD5,1651);
vec_set(camera.x,camloc);
vec_set(camera.pan,eGD5.pan);
UpdateDust();
wait(1);
}
}