#include "Objects.h"
extern XYZ viewer;
extern float viewdistance;
-extern float lightambient[3],lightbrightness[3];
extern float fadestart;
extern int environment;
extern float texscale;
extern float gravity;
extern FRUSTUM frustum;
extern Terrain terrain;
-extern float terraindetail;
extern bool foliage;
extern int detail;
extern float blurness;
extern float windvar;
extern float playerdist;
extern bool skyboxtexture;
-extern Sprites sprites;
//Functions
if(type[i]!=treeleavestype&&type[i]!=treetrunktype&&type[i]!=bushtype&&type[i]!=firetype&&i!=which){
colviewer=startpoint;
coltarget=endpoint;
- if(model[i].LineCheck(&colviewer,&coltarget,&colpoint,&position[i],&rotation[i])!=-1)return 1;
+ if(model[i].LineCheck(&colviewer,&coltarget,&colpoint,&position[i],&yaw[i])!=-1)return 1;
}
}
static int whichpatchx;
static int whichpatchz;
- whichpatchx=p1->x/(terrain.size/subdivision*terrain.scale*terraindetail);
- whichpatchz=p1->z/(terrain.size/subdivision*terrain.scale*terraindetail);
+ whichpatchx=p1->x/(terrain.size/subdivision*terrain.scale);
+ whichpatchz=p1->z/(terrain.size/subdivision*terrain.scale);
if(whichpatchx>=0&&whichpatchz>=0&&whichpatchx<subdivision&&whichpatchz<subdivision)
if(terrain.patchobjectnum[whichpatchx][whichpatchz]>0&&terrain.patchobjectnum[whichpatchx][whichpatchz]<500)
for(j=0;j<terrain.patchobjectnum[whichpatchx][whichpatchz];j++){
i=terrain.patchobjects[whichpatchx][whichpatchz][j];
possible[i]=0;
- if(model[i].SphereCheckPossible(p1, radius, &position[i], &rotation[i])!=-1){
+ if(model[i].SphereCheckPossible(p1, radius, &position[i], &yaw[i])!=-1){
possible[i]=1;
}
}
for(i=0;i<numobjects;i++){
if(type[i]!=firetype){
- moved=DoRotation(model[i].boundingspherecenter,0,rotation[i],0);
+ moved=DoRotation(model[i].boundingspherecenter,0,yaw[i],0);
if(type[i]==tunneltype||frustum.SphereInFrustum(position[i].x+moved.x,position[i].y+moved.y,position[i].z+moved.z,model[i].boundingsphereradius)){
distance=findDistancefast(&viewer,&position[i]);
distance*=1.2;
if(distance>1)distance=1;
if(distance>0){
- /*if(checkcollide(viewer,DoRotation(model[i].vertex[model[i].vertexNum],0,rotation[i],0)*scale[i]+position[i],i)){
+ /*if(checkcollide(viewer,DoRotation(model[i].vertex[model[i].vertexNum],0,yaw[i],0)*scale[i]+position[i],i)){
occluded[i]+=1;
}
else occluded[i]=0;*/
glRotatef((sin(windvar+position[i].x*.3)+.5)*4*.5*(sin(windvar*2+position[i].x*.3)+1)/2,1,0,0);
}
}
- glRotatef(rotation[i],0,1,0);
+ glRotatef(yaw[i],0,1,0);
if(distance>1)distance=1;
glColor4f((1-shadowed[i])/2+.5,(1-shadowed[i])/2+.5,(1-shadowed[i])/2+.5,distance);
if(distance>=1){
glTexEnvf( GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, 0 );
for(i=0;i<numobjects;i++){
if(type[i]==treeleavestype||type[i]==bushtype){
- moved=DoRotation(model[i].boundingspherecenter,0,rotation[i],0);
+ moved=DoRotation(model[i].boundingspherecenter,0,yaw[i],0);
if(frustum.SphereInFrustum(position[i].x+moved.x,position[i].y+moved.y,position[i].z+moved.z,model[i].boundingsphereradius)){
hidden=findDistancefastflat(&viewer,&position[i])<=playerdist+3;
if(hidden){
glRotatef((sin(windvar+position[i].x*.3)+.5)*4*.5*(sin(windvar*2+position[i].x*.3)+1)/2,1,0,0);
}
}
- glRotatef(rotation[i],0,1,0);
+ glRotatef(yaw[i],0,1,0);
glColor4f(1,1,1,distance);
if(type[i]==treeleavestype){
glDisable(GL_CULL_FACE);
void Objects::DeleteObject(int which)
{
type[numobjects-1]=0;
- rotation[numobjects-1]=0;
+ yaw[numobjects-1]=0;
position[numobjects-1]=0;
scale[numobjects-1]=0;
friction[numobjects-1]=0;
numobjects--;
}
-void Objects::MakeObject(int atype, XYZ where, float arotation, float ascale){
+void Objects::MakeObject(int atype, XYZ where, float ayaw, float ascale){
if((atype!=treeleavestype&&atype!=bushtype)||foliage==1){
scale[numobjects]=ascale;
if(atype==treeleavestype)scale[numobjects]+=fabs((float)(Random()%100)/900)*ascale;
position[numobjects]=where;
if(atype==bushtype)position[numobjects].y=terrain.getHeight(position[numobjects].x,position[numobjects].z)-.3;
- rotation[numobjects]=arotation;
+ yaw[numobjects]=ayaw;
rotxvel[numobjects]=0;
rotyvel[numobjects]=0;
model[numobjects].Scale(.3*scale[numobjects],.3*scale[numobjects],.3*scale[numobjects]);
model[numobjects].Rotate(90,1,1);
if(type[numobjects]==rocktype){
- model[numobjects].Rotate(arotation*5,1,1);
+ model[numobjects].Rotate(ayaw*5,1,1);
}
model[numobjects].CalculateNormals(1);
model[numobjects].ScaleNormals(-1,-1,-1);
}
if(atype!=treeleavestype&&atype!=bushtype&&atype!=firetype)
- terrain.AddObject(where+DoRotation(model[numobjects].boundingspherecenter,0,arotation,0),model[numobjects].boundingsphereradius,numobjects);
+ terrain.AddObject(where+DoRotation(model[numobjects].boundingspherecenter,0,ayaw,0),model[numobjects].boundingsphereradius,numobjects);
numobjects++;
}
}
-void Objects::MakeObject(int atype, XYZ where, float arotation, float arotation2, float ascale){
+void Objects::MakeObject(int atype, XYZ where, float ayaw, float apitch, float ascale){
if((atype!=treeleavestype&&atype!=bushtype)||foliage==1){
scale[numobjects]=ascale;
if(atype==treeleavestype)scale[numobjects]+=fabs((float)(Random()%100)/900)*ascale;
if(position[numobjects].y<terrain.getHeight(position[numobjects].x,position[numobjects].z)-.3)
position[numobjects].y=terrain.getHeight(position[numobjects].x,position[numobjects].z)-.3;
}*/
- rotation[numobjects]=arotation;
- rotation2[numobjects]=arotation2;
+ yaw[numobjects]=ayaw;
+ pitch[numobjects]=apitch;
rotxvel[numobjects]=0;
rotyvel[numobjects]=0;
if(atype==treetrunktype)friction[numobjects]=.4;
if(atype==treeleavestype)friction[numobjects]=0;
- if(friction[numobjects]==1.5&&fabs(arotation2)>5)friction[numobjects]=.5;
+ if(friction[numobjects]==1.5&&fabs(apitch)>5)friction[numobjects]=.5;
if(atype==platformtype){
model[numobjects].loaddecal((char *)":Data:Models:Platform.solid",0);
}
model[numobjects].Scale(.3*scale[numobjects],.3*scale[numobjects],.3*scale[numobjects]);
model[numobjects].Rotate(90,1,1);
- model[numobjects].Rotate(arotation2,0,0);
+ model[numobjects].Rotate(apitch,0,0);
if(type[numobjects]==rocktype){
- model[numobjects].Rotate(arotation*5,0,0);
+ model[numobjects].Rotate(ayaw*5,0,0);
}
model[numobjects].CalculateNormals(1);
model[numobjects].ScaleNormals(-1,-1,-1);
}
if(atype!=treeleavestype&&atype!=bushtype&&atype!=firetype)
- terrain.AddObject(where+DoRotation(model[numobjects].boundingspherecenter,0,arotation,0),model[numobjects].boundingsphereradius,numobjects);
+ terrain.AddObject(where+DoRotation(model[numobjects].boundingspherecenter,0,ayaw,0),model[numobjects].boundingsphereradius,numobjects);
numobjects++;
}
XYZ spawnpoint;
for(int i=0;i<numobjects;i++){
/*if(type[i]==firetype){
- sprites.MakeSprite(weaponshinesprite, position[i],position[i]*0, 1,1,1, 5, 1);
+ Sprite::MakeSprite(weaponshinesprite, position[i],position[i]*0, 1,1,1, 5, 1);
}*/
if(type[i]==firetype)onfire[i]=1;
spawnpoint.z=0;
spawnpoint=DoRotation(spawnpoint,0,Random()%360,0);
spawnpoint+=position[i];
- sprites.MakeSprite(flamesprite, spawnpoint,spawnpoint*0, 1,1,1, (.6+(float)abs(Random()%100)/200-.25)*5*scale[i], 1);
+ Sprite::MakeSprite(flamesprite, spawnpoint,spawnpoint*0, 1,1,1, (.6+(float)abs(Random()%100)/200-.25)*5*scale[i], 1);
}
if(type[i]==treeleavestype){
spawnpoint.x=((float)(Random()%100))/80*scale[i];
spawnpoint.z=0;
spawnpoint=DoRotation(spawnpoint,0,Random()%360,0);
spawnpoint+=position[i];
- sprites.MakeSprite(flamesprite, spawnpoint,spawnpoint*0, 1,1,1, (.6+(float)abs(Random()%100)/200-.25)*6, 1);
+ Sprite::MakeSprite(flamesprite, spawnpoint,spawnpoint*0, 1,1,1, (.6+(float)abs(Random()%100)/200-.25)*6, 1);
}
}
void Objects::DoShadows()
{
- int i,j,k,l,todivide;
- static float brightness, total;
+ int i,j,k,l;
static XYZ testpoint,testpoint2, terrainpoint,lightloc,col;
lightloc=light.location;
if(!skyboxtexture)lightloc=0;
for(i=0;i<numobjects;i++){
if(type[i]!=treeleavestype&&type[i]!=treetrunktype&&type[i]!=bushtype&&type[i]!=firetype){
for(j=0;j<model[i].vertexNum;j++){
- terrainpoint=position[i]+DoRotation(model[i].vertex[j]+model[i].normals[j]*.1,0,rotation[i],0);
+ terrainpoint=position[i]+DoRotation(model[i].vertex[j]+model[i].normals[j]*.1,0,yaw[i],0);
//terrainpoint.y+=model[i].boundingsphereradius;
shadowed[i]=0;
- patchx=terrainpoint.x/(terrain.size/subdivision*terrain.scale*terraindetail);
- patchz=terrainpoint.z/(terrain.size/subdivision*terrain.scale*terraindetail);
+ patchx=terrainpoint.x/(terrain.size/subdivision*terrain.scale);
+ patchz=terrainpoint.z/(terrain.size/subdivision*terrain.scale);
if(patchx>=0&&patchz>=0&&patchx<subdivision&&patchz<subdivision)
if(terrain.patchobjectnum[patchx][patchz])
for(k=0;k<terrain.patchobjectnum[patchx][patchz];k++){
if(type[l]!=treetrunktype/*&&l!=i*/){
testpoint=terrainpoint;
testpoint2=terrainpoint+lightloc*50*(1-shadowed[i]);
- if(model[l].LineCheck(&testpoint,&testpoint2,&col,&position[l],&rotation[l])!=-1){
+ if(model[l].LineCheck(&testpoint,&testpoint2,&col,&position[l],&yaw[l])!=-1){
shadowed[i]=1-(findDistance(&terrainpoint,&col)/50);
}
}
}
if(shadowed[i]>0){
- col=model[i].normals[j]-DoRotation(lightloc*shadowed[i],0,-rotation[i],0);
+ col=model[i].normals[j]-DoRotation(lightloc*shadowed[i],0,-yaw[i],0);
Normalise(&col);
for(k=0;k<model[i].TriangleNum;k++){
if(model[i].Triangles[k].vertex[0]==j){
memset(position, 0, sizeof(position));
memset(type, 0, sizeof(type));
- memset(rotation, 0, sizeof(rotation));
- memset(rotation2, 0, sizeof(rotation2));
+ memset(yaw, 0, sizeof(yaw));
+ memset(pitch, 0, sizeof(pitch));
memset(rotx, 0, sizeof(rotx));
memset(rotxvel, 0, sizeof(rotxvel));
memset(roty, 0, sizeof(roty));
Objects::~Objects()
{
- if (boxtextureptr) glDeleteTextures( 1, &boxtextureptr );
- if (treetextureptr) glDeleteTextures( 1, &treetextureptr );
- if (bushtextureptr) glDeleteTextures( 1, &bushtextureptr );
- if (rocktextureptr) glDeleteTextures( 1, &rocktextureptr );
+ glDeleteTextures( 1, &boxtextureptr );
+ glDeleteTextures( 1, &treetextureptr );
+ glDeleteTextures( 1, &bushtextureptr );
+ glDeleteTextures( 1, &rocktextureptr );
};