woollybah пре 10 година
родитељ
комит
abe59ddb0b
44 измењених фајлова са 3640 додато и 1924 уклоњено
  1. 2 3
      openb3dlib.mod/openb3d/src/3ds.cpp
  2. 83 15
      openb3dlib.mod/openb3d/src/animation.cpp
  3. 1 1
      openb3dlib.mod/openb3d/src/brush.cpp
  4. 104 62
      openb3dlib.mod/openb3d/src/camera.cpp
  5. 2 2
      openb3dlib.mod/openb3d/src/camera.h
  6. 8 0
      openb3dlib.mod/openb3d/src/collidetri.c
  7. 297 104
      openb3dlib.mod/openb3d/src/entity.cpp
  8. 7 3
      openb3dlib.mod/openb3d/src/entity.h
  9. 58 10
      openb3dlib.mod/openb3d/src/functions.cpp
  10. 1197 1193
      openb3dlib.mod/openb3d/src/functions.h
  11. 24 26
      openb3dlib.mod/openb3d/src/geosphere.cpp
  12. 2 2
      openb3dlib.mod/openb3d/src/geosphere.h
  13. 94 16
      openb3dlib.mod/openb3d/src/isosurface.cpp
  14. 88 0
      openb3dlib.mod/openb3d/src/isosurface.h
  15. 16 3
      openb3dlib.mod/openb3d/src/light.cpp
  16. 59 65
      openb3dlib.mod/openb3d/src/makefile
  17. 151 101
      openb3dlib.mod/openb3d/src/material.cpp
  18. 9 7
      openb3dlib.mod/openb3d/src/matrix.cpp
  19. 2 4
      openb3dlib.mod/openb3d/src/matrix.h
  20. 12 6
      openb3dlib.mod/openb3d/src/md2.cpp
  21. 113 16
      openb3dlib.mod/openb3d/src/mesh.cpp
  22. 5 2
      openb3dlib.mod/openb3d/src/mesh.h
  23. 11 9
      openb3dlib.mod/openb3d/src/model.cpp
  24. 175 159
      openb3dlib.mod/openb3d/src/particle.cpp
  25. 7 4
      openb3dlib.mod/openb3d/src/particle.h
  26. 2 2
      openb3dlib.mod/openb3d/src/pick.cpp
  27. 1 1
      openb3dlib.mod/openb3d/src/project.h
  28. 1 2
      openb3dlib.mod/openb3d/src/shadermat.h
  29. 2 0
      openb3dlib.mod/openb3d/src/shaderobject.h
  30. 21 18
      openb3dlib.mod/openb3d/src/shadow.cpp
  31. 16 13
      openb3dlib.mod/openb3d/src/stencil.cpp
  32. 1 1
      openb3dlib.mod/openb3d/src/string_helper.cpp
  33. 1 1
      openb3dlib.mod/openb3d/src/string_helper.h
  34. 16 13
      openb3dlib.mod/openb3d/src/surface.cpp
  35. 23 23
      openb3dlib.mod/openb3d/src/terrain.cpp
  36. 2 2
      openb3dlib.mod/openb3d/src/terrain.h
  37. 29 19
      openb3dlib.mod/openb3d/src/texture.cpp
  38. 2 0
      openb3dlib.mod/openb3d/src/texture.h
  39. 20 14
      openb3dlib.mod/openb3d/src/voxel.cpp
  40. 939 0
      openb3dlib.mod/openb3d/src/voxterrain.cpp
  41. 32 0
      openb3dlib.mod/openb3d/src/voxterrain.h
  42. 1 1
      openb3dlib.mod/openb3d/src/x.cpp
  43. 3 0
      openb3dlib.mod/openb3dlib.bmx
  44. 1 1
      openb3dlib.mod/source.bmx

+ 2 - 3
openb3dlib.mod/openb3d/src/3ds.cpp

@@ -208,13 +208,12 @@ void ReadTexCoords(){
   }
 }
 
-void LoadMap(string Filepath){
+void LoadMap(){
   string Filename;
   //int Pixmap;
   Filename = ReadCString();
   //Pixmap = FileType(Filename)
   //If Pixmap <> 0 Then
-  Filename = Texture::NewFilePath(Filepath,Filename);
   texture = Texture::LoadTexture(Filename,4);
   if (TextureLayer == M3D_3DS_TEXTUREMAP1){
     // Layer 0
@@ -350,7 +349,7 @@ Mesh* Load3ds(string URL, Entity* parent_ent){
       //'Loader.Brush.BrushShininess(Percent)
       break;
     case M3D_3DS_MAPFILENAME:
-      LoadMap(URL);
+      LoadMap();
       break;
     case M3D_3DS_MAPVSCALE:
       texture->v_scale = Stream->ReadFloat();

+ 83 - 15
openb3dlib.mod/openb3d/src/animation.cpp

@@ -207,7 +207,7 @@ void Animation::AnimateMesh(Mesh* ent1,float framef,int start_frame,int end_fram
 		}
 		no_keys=false;
 
-		// store current keyframe for use with transtions
+		// store current keyframe for use with transitions
 		bent.kx=px3;
 		bent.ky=py3;
 		bent.kz=pz3;
@@ -286,7 +286,7 @@ void Animation::AnimateMesh(Mesh* ent1,float framef,int start_frame,int end_fram
 		}
 		no_keys=false;
 
-		// store current keyframe for use with transtions
+		// store current keyframe for use with transitions
 		bent.kqw=w3;
 		bent.kqx=x3;
 		bent.kqy=y3;
@@ -330,10 +330,10 @@ void Animation::AnimateMesh(Mesh* ent1,float framef,int start_frame,int end_fram
 		// set mat2 - does not include root parent transformation
 		// mat2 is used to store local bone positions, and is needed for vertex deform
 		if(dynamic_cast<Bone*>(bent.parent)!=NULL){
-			Matrix* new_mat=dynamic_cast<Bone*>(bent.parent)->mat2.Copy();
-			new_mat->Multiply(bent.mat2);
-			bent.mat2.Overwrite(*new_mat);
-			delete new_mat;
+			Matrix new_mat;
+			new_mat.Overwrite(dynamic_cast<Bone*>(bent.parent)->mat2);
+			new_mat.Multiply(bent.mat2);
+			bent.mat2.Overwrite(new_mat);
 		}
 
 		// set tform mat
@@ -361,7 +361,57 @@ void Animation::AnimateMesh2(Mesh* ent1,float framef,int start_frame,int end_fra
 
 	//if(dynamic_cast<Mesh*>(ent1)!=NULL){
 
-	if(ent1->anim!=1) return; // mesh contains no anim data
+	if(ent1->anim!=1) {			//Not a bone based animation
+
+		if(ent1->anim==2) { 
+			//Vertex deform animation
+			ent1->anim_render=true;
+
+			list<Surface*>::iterator surf_it;
+			surf_it=ent1->surf_list.begin();
+
+			list<Surface*>::iterator anim_surf_it;
+
+
+			// cycle through all surfs
+			for(anim_surf_it=ent1->anim_surf_list.begin();anim_surf_it!=ent1->anim_surf_list.end();anim_surf_it++){
+
+				Surface& anim_surf=**anim_surf_it;
+
+				Surface& surf=**surf_it;
+
+				anim_surf.reset_vbo=anim_surf.reset_vbo|1;
+
+				int t0=0;
+				for(unsigned int i=0;i<=anim_surf.vert_weight4.size();i++){
+					if (anim_surf.vert_weight4[i]>=start_frame){
+						t0=i;
+						break;
+					}
+				}
+
+
+				t0*=anim_surf.no_verts*3;
+
+				float m0=1.0/ent1->anim_trans;
+				float m1=1.0-m0;
+
+				for(int i=0;i<=anim_surf.no_verts*3;i++){
+					anim_surf.vert_coords[i]=surf.vert_coords[i+t0]*m0+anim_surf.vert_coords[i]*m1;
+
+				}
+
+
+
+
+				surf_it++;
+
+			}
+			
+		}
+		return;
+
+	}
 
 		ent1->anim_render=true;
 
@@ -533,10 +583,10 @@ void Animation::AnimateMesh2(Mesh* ent1,float framef,int start_frame,int end_fra
 			// set mat2 - does not include root parent transformation
 			// mat2 is used to store local bone positions, and is needed for vertex deform
 			if(dynamic_cast<Bone*>(bent.parent)!=NULL){
-				Matrix* new_mat=dynamic_cast<Bone*>(bent.parent)->mat2.Copy();
-				new_mat->Multiply(bent.mat2);
-				bent.mat2.Overwrite(*new_mat);
-				delete new_mat;
+				Matrix new_mat;
+				new_mat.Overwrite(dynamic_cast<Bone*>(bent.parent)->mat2);
+				new_mat.Multiply(bent.mat2);
+				bent.mat2.Overwrite(new_mat);
 			}
 
 			// set tform mat
@@ -573,14 +623,32 @@ void Animation::AnimateMesh3(Mesh* ent1){
 			Bone& bent=**it;
 
 			// set mat2 to equal mat
-			bent.mat2.Overwrite(bent.mat);
+			bent.mat2.Overwrite(bent.rotmat);
+
+			bent.mat2.grid[3][0]=bent.px;
+			bent.mat2.grid[3][1]=bent.py;
+			bent.mat2.grid[3][2]=-bent.pz;
+
+			// store current keyframe for use with transitions
+
+			bent.rotmat.ToQuat(bent.kqx, bent.kqy, bent.kqz, bent.kqw);
+			bent.kqw=-bent.kqw;
+
+			bent.kx=bent.px;
+			bent.ky=bent.py;
+			bent.kz=-bent.pz;
+
 
-			bent.mat2.grid[3][0]-=ent1->mat.grid[3][0];
-			bent.mat2.grid[3][1]-=ent1->mat.grid[3][1];
-			bent.mat2.grid[3][2]-=ent1->mat.grid[3][2];
 
 
 			// mat2 is used to store local bone positions, and is needed for vertex deform
+			if(dynamic_cast<Bone*>(bent.parent)!=NULL){
+				Matrix new_mat;
+				new_mat.Overwrite(dynamic_cast<Bone*>(bent.parent)->mat2);
+				new_mat.Multiply(bent.mat2);
+				bent.mat2.Overwrite(new_mat);
+			}
+
 
 			// set tform mat
 			// A tform mat is needed to transform vertices, and is basically the bone mat multiplied by the inverse reference pose mat

+ 1 - 1
openb3dlib.mod/openb3d/src/brush.cpp

@@ -155,7 +155,7 @@ int Brush::CompareBrushes(Brush* brush1,Brush* brush2){
 			if(brush1->tex[i]==NULL && brush2->tex[i]!=NULL) return false;
 			if(brush1->tex[i]!=NULL && brush2->tex[i]==NULL) return false;
 			if(brush1->tex[i]!=NULL && brush2->tex[i]!=NULL){
-				//if(brush1->tex[i]->texture!=brush2->tex[i]->texture) return false;
+				if(brush1->tex[i]->texture!=brush2->tex[i]->texture) return false;
 				if(brush1->tex[i]->blend!=brush2->tex[i]->blend) return false;
 				if(brush1->tex[i]->coords!=brush2->tex[i]->coords) return false;
 			}

+ 104 - 62
openb3dlib.mod/openb3d/src/camera.cpp

@@ -184,10 +184,11 @@ void Camera::CameraClsMode(int color,int zbuffer){
 
 }
 
-void Camera::CameraRange(float near,float far){
+void Camera::CameraRange(float Near,float Far){
 
-	range_near=near;
-	range_far=far;
+	range_near=Near;
+	range_far=Far;
+	UpdateProjMatrix();
 
 }
 
@@ -218,10 +219,10 @@ void Camera::CameraFogColor(float r,float g,float b){
 
 }
 
-void Camera::CameraFogRange(float near,float far){
+void Camera::CameraFogRange(float Near,float Far){
 
-	fog_range_near=near;
-	fog_range_far=far;
+	fog_range_near=Near;
+	fog_range_far=Far;
 
 }
 
@@ -274,37 +275,37 @@ float Camera::EntityInView(Entity* ent){
 	
 void Camera::ExtractFrustum(){
 
-	float proj[16]={0.0};
-	float modl[16]={0.0};
+	//float proj[16]={0.0};
+	//float modl[16]={0.0};
 	float clip[16]={0.0};
 	float t=0.0;
 	
 	// Get the current PROJECTION matrix from OpenGL
-	glGetFloatv( GL_PROJECTION_MATRIX, proj );
+	//glGetFloatv( GL_PROJECTION_MATRIX, proj );
 	
 	// Get the current MODELVIEW matrix from OpenGL
-	glGetFloatv( GL_MODELVIEW_MATRIX, modl );
+	//glGetFloatv( GL_MODELVIEW_MATRIX, modl );
 	
 	// Combine the two matrices (multiply projection by modelview)
-	clip[ 0] = modl[ 0] * proj[ 0] + modl[ 1] * proj[ 4] + modl[ 2] * proj[ 8] + modl[ 3] * proj[12];
-	clip[ 1] = modl[ 0] * proj[ 1] + modl[ 1] * proj[ 5] + modl[ 2] * proj[ 9] + modl[ 3] * proj[13];
-	clip[ 2] = modl[ 0] * proj[ 2] + modl[ 1] * proj[ 6] + modl[ 2] * proj[10] + modl[ 3] * proj[14];
-	clip[ 3] = modl[ 0] * proj[ 3] + modl[ 1] * proj[ 7] + modl[ 2] * proj[11] + modl[ 3] * proj[15];
-	
-	clip[ 4] = modl[ 4] * proj[ 0] + modl[ 5] * proj[ 4] + modl[ 6] * proj[ 8] + modl[ 7] * proj[12];
-	clip[ 5] = modl[ 4] * proj[ 1] + modl[ 5] * proj[ 5] + modl[ 6] * proj[ 9] + modl[ 7] * proj[13];
-	clip[ 6] = modl[ 4] * proj[ 2] + modl[ 5] * proj[ 6] + modl[ 6] * proj[10] + modl[ 7] * proj[14];
-	clip[ 7] = modl[ 4] * proj[ 3] + modl[ 5] * proj[ 7] + modl[ 6] * proj[11] + modl[ 7] * proj[15];
-	
-	clip[ 8] = modl[ 8] * proj[ 0] + modl[ 9] * proj[ 4] + modl[10] * proj[ 8] + modl[11] * proj[12];
-	clip[ 9] = modl[ 8] * proj[ 1] + modl[ 9] * proj[ 5] + modl[10] * proj[ 9] + modl[11] * proj[13];
-	clip[10] = modl[ 8] * proj[ 2] + modl[ 9] * proj[ 6] + modl[10] * proj[10] + modl[11] * proj[14];
-	clip[11] = modl[ 8] * proj[ 3] + modl[ 9] * proj[ 7] + modl[10] * proj[11] + modl[11] * proj[15];
-	
-	clip[12] = modl[12] * proj[ 0] + modl[13] * proj[ 4] + modl[14] * proj[ 8] + modl[15] * proj[12];
-	clip[13] = modl[12] * proj[ 1] + modl[13] * proj[ 5] + modl[14] * proj[ 9] + modl[15] * proj[13];
-	clip[14] = modl[12] * proj[ 2] + modl[13] * proj[ 6] + modl[14] * proj[10] + modl[15] * proj[14];
-	clip[15] = modl[12] * proj[ 3] + modl[13] * proj[ 7] + modl[14] * proj[11] + modl[15] * proj[15];
+	clip[ 0] = mod_mat[ 0] * proj_mat[ 0] + mod_mat[ 1] * proj_mat[ 4] + mod_mat[ 2] * proj_mat[ 8] + mod_mat[ 3] * proj_mat[12];
+	clip[ 1] = mod_mat[ 0] * proj_mat[ 1] + mod_mat[ 1] * proj_mat[ 5] + mod_mat[ 2] * proj_mat[ 9] + mod_mat[ 3] * proj_mat[13];
+	clip[ 2] = mod_mat[ 0] * proj_mat[ 2] + mod_mat[ 1] * proj_mat[ 6] + mod_mat[ 2] * proj_mat[10] + mod_mat[ 3] * proj_mat[14];
+	clip[ 3] = mod_mat[ 0] * proj_mat[ 3] + mod_mat[ 1] * proj_mat[ 7] + mod_mat[ 2] * proj_mat[11] + mod_mat[ 3] * proj_mat[15];
+	
+	clip[ 4] = mod_mat[ 4] * proj_mat[ 0] + mod_mat[ 5] * proj_mat[ 4] + mod_mat[ 6] * proj_mat[ 8] + mod_mat[ 7] * proj_mat[12];
+	clip[ 5] = mod_mat[ 4] * proj_mat[ 1] + mod_mat[ 5] * proj_mat[ 5] + mod_mat[ 6] * proj_mat[ 9] + mod_mat[ 7] * proj_mat[13];
+	clip[ 6] = mod_mat[ 4] * proj_mat[ 2] + mod_mat[ 5] * proj_mat[ 6] + mod_mat[ 6] * proj_mat[10] + mod_mat[ 7] * proj_mat[14];
+	clip[ 7] = mod_mat[ 4] * proj_mat[ 3] + mod_mat[ 5] * proj_mat[ 7] + mod_mat[ 6] * proj_mat[11] + mod_mat[ 7] * proj_mat[15];
+	
+	clip[ 8] = mod_mat[ 8] * proj_mat[ 0] + mod_mat[ 9] * proj_mat[ 4] + mod_mat[10] * proj_mat[ 8] + mod_mat[11] * proj_mat[12];
+	clip[ 9] = mod_mat[ 8] * proj_mat[ 1] + mod_mat[ 9] * proj_mat[ 5] + mod_mat[10] * proj_mat[ 9] + mod_mat[11] * proj_mat[13];
+	clip[10] = mod_mat[ 8] * proj_mat[ 2] + mod_mat[ 9] * proj_mat[ 6] + mod_mat[10] * proj_mat[10] + mod_mat[11] * proj_mat[14];
+	clip[11] = mod_mat[ 8] * proj_mat[ 3] + mod_mat[ 9] * proj_mat[ 7] + mod_mat[10] * proj_mat[11] + mod_mat[11] * proj_mat[15];
+	
+	clip[12] = mod_mat[12] * proj_mat[ 0] + mod_mat[13] * proj_mat[ 4] + mod_mat[14] * proj_mat[ 8] + mod_mat[15] * proj_mat[12];
+	clip[13] = mod_mat[12] * proj_mat[ 1] + mod_mat[13] * proj_mat[ 5] + mod_mat[14] * proj_mat[ 9] + mod_mat[15] * proj_mat[13];
+	clip[14] = mod_mat[12] * proj_mat[ 2] + mod_mat[13] * proj_mat[ 6] + mod_mat[14] * proj_mat[10] + mod_mat[15] * proj_mat[14];
+	clip[15] = mod_mat[12] * proj_mat[ 3] + mod_mat[13] * proj_mat[ 7] + mod_mat[14] * proj_mat[11] + mod_mat[15] * proj_mat[15];
 	
 	// Extract the numbers for the right plane
 	frustum[0][0] = clip[ 3] - clip[ 0];
@@ -512,7 +513,8 @@ void Camera::Update(){
 
 	accPerspective(atan((1.0/(zoom*ratio)))*2.0,ratio,range_near,range_far,0.0,0.0,0.0,0.0,1.0);
 
-	Matrix new_mat=mat.Inverse();
+	Matrix new_mat;
+	mat.GetInverse(new_mat);
 	//mat.Inverse(Camera::InverseMat);
 
 	//glLoadMatrixf(&Camera::InverseMat.grid[0][0]);
@@ -520,11 +522,28 @@ void Camera::Update(){
 	glLoadMatrixf(&new_mat.grid[0][0]);
 
 	
+	mod_mat[0]=new_mat.grid[0][0];
+	mod_mat[1]=new_mat.grid[0][1];
+	mod_mat[2]=new_mat.grid[0][2];
+	mod_mat[3]=new_mat.grid[0][3];
+	mod_mat[4]=new_mat.grid[1][0];
+	mod_mat[5]=new_mat.grid[1][1];
+	mod_mat[6]=new_mat.grid[1][2];
+	mod_mat[7]=new_mat.grid[1][3];
+	mod_mat[8]=new_mat.grid[2][0];
+	mod_mat[9]=new_mat.grid[2][1];
+	mod_mat[10]=new_mat.grid[2][2];
+	mod_mat[11]=new_mat.grid[2][3];
+	mod_mat[12]=new_mat.grid[3][0];
+	mod_mat[13]=new_mat.grid[3][1];
+	mod_mat[14]=new_mat.grid[3][2];
+	mod_mat[15]=new_mat.grid[3][3];
+
 	if(project_enabled){ // only get these directly after a cameraproject/camerapick call, as they are expensive calls
 	
 		// get projection/model/viewport info - for use with cameraproject/camerapick
-		glGetFloatv(GL_MODELVIEW_MATRIX,&mod_mat[0]);
-		glGetFloatv(GL_PROJECTION_MATRIX,&proj_mat[0]);
+		//glGetFloatv(GL_MODELVIEW_MATRIX,&mod_mat[0]);
+		//glGetFloatv(GL_PROJECTION_MATRIX,&proj_mat[0]);
 		glGetIntegerv(GL_VIEWPORT,&viewport[0]);
 		
 		project_enabled=false;
@@ -648,7 +667,8 @@ void UpdateEntityRender(Entity* ent,Entity* cam){
 				
 						return;}
 					case (3):{
-						Surface* surf=ParticleBatch::GetParticleBatchSurface(sprite->brush.tex[0],sprite->brush.blend,sprite->order);
+						ParticleBatch* p=ParticleBatch::GetParticleBatch(sprite->brush.tex[0],sprite->brush.blend,sprite->order);
+						Surface* surf=*p->surf_list.begin();
 			
 						surf->no_verts++;
 
@@ -656,10 +676,10 @@ void UpdateEntityRender(Entity* ent,Entity* cam){
 						surf->vert_coords.push_back(sprite->mat.grid[3][1]);
 						surf->vert_coords.push_back(sprite->mat.grid[3][2]);
 
-						surf->vert_col.push_back(1.0);
-						surf->vert_col.push_back(1.0);
-						surf->vert_col.push_back(1.0);
-						surf->vert_col.push_back(1.0);
+						surf->vert_col.push_back(sprite->brush.red);
+						surf->vert_col.push_back(sprite->brush.green);
+						surf->vert_col.push_back(sprite->brush.blue);
+						surf->vert_col.push_back(sprite->brush.alpha);
 
 				
 						return;}
@@ -988,11 +1008,11 @@ void Camera::accPerspective(float fovy,float aspect,float zNear,float zFar,float
 
 void Camera::accFrustum(float left_,float right_,float bottom,float top,float zNear,float zFar,float pixdx,float pixdy,float eyedx,float eyedy,float focus){
 	
-	float xwsize=0.0,ywsize=0.0;
-	float dx=0.0,dy=0.0;
+	//float xwsize=0.0,ywsize=0.0;
+	//float dx=0.0,dy=0.0;
 	
-	xwsize=right_-left_;
-	ywsize=top-bottom;
+	//xwsize=right_-left_;
+	//ywsize=top-bottom;
 	//dx=(pixdx*xwsize/float(viewport[2])+eyedx*zNear/focus);
 	//dy=-(pixdy*ywsize/float(viewport[3])+eyedy*zNear/focus);
 	
@@ -1000,9 +1020,9 @@ void Camera::accFrustum(float left_,float right_,float bottom,float top,float zN
 	glLoadIdentity();
 	
 	if (proj_mode == 1) {
-		glFrustum(left_+dx,right_+dx,bottom+dy,top+dy,zNear,zFar);
+		glFrustum(left_,right_,bottom,top,zNear,zFar);
 	}else if (proj_mode == 2){
-		glOrtho(left_+dx,right_+dx,bottom+dy,top+dy,zNear,zFar);
+		glOrtho(left_,right_,bottom,top,zNear,zFar);
 	}
 	
 	glMatrixMode(GL_MODELVIEW);
@@ -1017,24 +1037,46 @@ void Camera::UpdateProjMatrix(){
 	float top=range_near/(cos(fov)/sin(fov));
 	float right_=top*ratio;
 
-	proj_mat[0]=range_near/right_;
-	proj_mat[1]=0;
-	proj_mat[2]=0;
-	proj_mat[3]=0;
-
-	proj_mat[4]=0;
-	proj_mat[5]=range_near/top;
-	proj_mat[6]=0;
-	proj_mat[7]=0;
-
-	proj_mat[8]=0;
-	proj_mat[9]=0;
-	proj_mat[10]=-(range_far+range_near)/(range_far-range_near);
-	proj_mat[11]=-1;
-
-	proj_mat[12]=0;
-	proj_mat[13]=0;
-	proj_mat[14]=(-2*range_far*range_near)/(range_far-range_near);
-	proj_mat[15]=0;
+	if (proj_mode == 1) {
+		proj_mat[0]=range_near/right_;
+		proj_mat[1]=0;
+		proj_mat[2]=0;
+		proj_mat[3]=0;
+
+		proj_mat[4]=0;
+		proj_mat[5]=range_near/top;
+		proj_mat[6]=0;
+		proj_mat[7]=0;
+
+		proj_mat[8]=0;
+		proj_mat[9]=0;
+		proj_mat[10]=-(range_far+range_near)/(range_far-range_near);
+		proj_mat[11]=-1;
+
+		proj_mat[12]=0;
+		proj_mat[13]=0;
+		proj_mat[14]=(-2*range_far*range_near)/(range_far-range_near);
+		proj_mat[15]=0;
+	}else if (proj_mode == 2){
+		proj_mat[0]=1.0/right_;
+		proj_mat[1]=0;
+		proj_mat[2]=0;
+		proj_mat[3]=0;
+
+		proj_mat[4]=0;
+		proj_mat[5]=1.0/top;
+		proj_mat[6]=0;
+		proj_mat[7]=0;
+
+		proj_mat[8]=0;
+		proj_mat[9]=0;
+		proj_mat[10]=-2.0/(range_far-range_near);
+		proj_mat[11]=0;
+
+		proj_mat[12]=0;
+		proj_mat[13]=0;
+		proj_mat[14]=-(range_far+range_near)/(range_far-range_near);
+		proj_mat[15]=1.0;
+	}
 
 }

+ 2 - 2
openb3dlib.mod/openb3d/src/camera.h

@@ -80,12 +80,12 @@ public:
 	void CameraViewport(int,int,int,int);
 	void CameraClsColor(float r,float g,float b);
 	void CameraClsMode(int color,int zbuffer);
-	void CameraRange(float near,float far);
+	void CameraRange(float Near,float Far);
 	void CameraZoom(float zoom_val);
 	void CameraProjMode(int mode=1);
 	void CameraFogMode(int mode);
 	void CameraFogColor(float r,float g,float b);
-	void CameraFogRange(float near,float far);
+	void CameraFogRange(float Near,float Far);
 
 	void CameraProject(float x,float y,float z);
 	static float ProjectedX();

+ 8 - 0
openb3dlib.mod/openb3d/src/collidetri.c

@@ -152,11 +152,15 @@ int coplanar_tri_tri(float N[3],float V0[3],float V1[3],float V2[3],
    short i0,i1;
    /* first project onto an axis-aligned plane, that maximizes the area */
    /* of the triangles, compute indices: i0,i1. */
+#ifndef __GNUC__
 #pragma warning( disable : 4244 )
+#endif
    A[0]=fabs(N[0]);
    A[1]=fabs(N[1]);
    A[2]=fabs(N[2]);
+#ifndef __GNUC__
 #pragma warning( default : 4244 )
+#endif
    if(A[0]>A[1])
    {
       if(A[0]>A[2])  
@@ -263,12 +267,16 @@ int tri_tri_intersect(float V0[3],float V1[3],float V2[3],
   CROSS(D,N1,N2);
 
   /* compute and index to the largest component of D */
+#ifndef __GNUC__
 #pragma warning( disable : 4244 )
+#endif
   max=fabs(D[0]);
   index=0;
   b=fabs(D[1]);
   c=fabs(D[2]);
+#ifndef __GNUC__
 #pragma warning( default : 4244 )
+#endif
   if(b>max) max=b,index=1;
   if(c>max) max=c,index=2;
 

+ 297 - 104
openb3dlib.mod/openb3d/src/entity.cpp

@@ -10,6 +10,7 @@
 #include "entity.h"
 #include "camera.h"
 #include "mesh.h"
+#include "model.h"
 #include "animation.h"
 #include "pick.h"
 #include "maths_helper.h"
@@ -64,8 +65,8 @@ void Entity::EntityParent(Entity* parent_ent,int glob){
 	float orgx=0.0f,orgy=0.0f,orgz=0.0f;
 	float orgw,orgh,orgd;
 	float neww,newh,newd;
-	Matrix* m1=0;
-	Matrix* m2;
+	Matrix m1;
+	Matrix m2;
 
 	//get global position/rotation
 	if (glob != 0) {
@@ -73,10 +74,10 @@ void Entity::EntityParent(Entity* parent_ent,int glob){
 		orgx = tformed_x;
 		orgy = tformed_y;
 		orgz = tformed_z;
-		m1 = MQ_GetMatrix(true);
-		m1->grid[3][0] = 0; //remove translation
-		m1->grid[3][1] = 0;
-		m1->grid[3][2] = 0;
+		MQ_GetMatrix(m1, true);
+		m1.grid[3][0] = 0; //remove translation
+		m1.grid[3][1] = 0;
+		m1.grid[3][2] = 0;
 		//get scaling
 		MQ_GetScaleXYZ(orgw,orgh,orgd);
 	}
@@ -105,19 +106,16 @@ void Entity::EntityParent(Entity* parent_ent,int glob){
 		pz = orgz;
 		//get parent inverted rotation matrix
 		if (parent_ent == 0) {
-			m2 = new Matrix; //no parent
-			m2->LoadIdentity();
+			m2.LoadIdentity(); //no parent
 		}else{
-			m2 = parent_ent->MQ_GetInvMatrix(true);
-			m2->grid[3][0] = 0; //remove translation
-			m2->grid[3][1] = 0;
-			m2->grid[3][2] = 0;
+			parent_ent->MQ_GetInvMatrix(m2, true);
+			m2.grid[3][0] = 0; //remove translation
+			m2.grid[3][1] = 0;
+			m2.grid[3][2] = 0;
 		}
 		//apply rotation matrix
-		m1->Multiply2(*m2);
-		rotmat.Overwrite(*m1);
-		delete m2;
-		delete m1;
+		m1.Multiply2(m2);
+		rotmat.Overwrite(m1);
 	}
 
 	if (parent_ent == 0) {
@@ -289,15 +287,14 @@ void Entity::RotateEntity(float x,float y,float z,int global){
 	if (global != 0) {
 		//get parent inverted rotation matrix
 		if (parent != 0) {
-			Matrix* m2;
-			m2 = parent->MQ_GetInvMatrix(true);
-			m2->grid[3][0] = 0; //remove translation
-			m2->grid[3][1] = 0;
-			m2->grid[3][2] = 0;
-			m2->Scale(parent->sx, parent->sy, parent->sz);
+			Matrix m2;
+			parent->MQ_GetInvMatrix(m2,true);
+			m2.grid[3][0] = 0; //remove translation
+			m2.grid[3][1] = 0;
+			m2.grid[3][2] = 0;
+			m2.Scale(parent->sx, parent->sy, parent->sz);
 			//apply rotation matrix
-			rotmat.Multiply2(*m2);
-			delete m2;
+			rotmat.Multiply2(m2);
 		}
 	}
 
@@ -357,9 +354,9 @@ float Entity::EntityPitch(int global){
 	if(global==false){
 		return rotmat.GetPitch();
 	}else{
-		Matrix* m=MQ_GetMatrix(false);
-		float f=m->GetPitch();
-		delete m;
+		Matrix m;
+		MQ_GetMatrix(m,false);
+		float f=m.GetPitch();
 		return f;
 	}
 }
@@ -368,9 +365,9 @@ float Entity::EntityYaw(int global){
 	if(global==false){
 		return rotmat.GetYaw();
 	}else{
-		Matrix* m=MQ_GetMatrix(false);
-		float f=m->GetYaw();
-		delete m;
+		Matrix m;
+		MQ_GetMatrix(m,false);
+		float f=m.GetYaw();
 		return f;
 	}
 }
@@ -379,9 +376,9 @@ float Entity::EntityRoll(int global){
 	if(global==false){
 		return rotmat.GetRoll();
 	}else{
-		Matrix* m=MQ_GetMatrix(false);
-		float f=m->GetRoll();
-		delete m;
+		Matrix m;
+		MQ_GetMatrix(m,false);
+		float f=m.GetRoll();
 		return f;
 	}
 }
@@ -731,6 +728,175 @@ int Entity::ExtractAnimSeq(int first_frame,int last_frame,int seq){
 
 }
 
+int Entity::LoadAnimSeq(string filename){
+	// mesh that we will load anim seq from
+	Mesh* mesh=LoadAnimB3D(filename);
+	if (anim==false || mesh->anim==false){	//' mesh or self contains no anim data
+		mesh->FreeEntity();
+		return 0; 
+	}
+	no_seqs=no_seqs+1;
+
+	// expand anim_seqs array
+	anim_seqs_first.push_back(0);
+	anim_seqs_last.push_back(0);
+
+	// update anim_seqs array
+	anim_seqs_first[no_seqs]=anim_seqs_last[0];
+	anim_seqs_last[no_seqs]=anim_seqs_last[0]+mesh->anim_seqs_last[0];
+
+	// update anim_seqs_last[0] - sequence 0 is for all frames, so this needs to be increased
+	// must be done after updating anim_seqs array above
+	anim_seqs_last[0]=anim_seqs_last[0]+mesh->anim_seqs_last[0];
+
+	if (mesh){
+		// go through all bones belonging to self
+
+		vector<Bone*>::iterator it;
+
+		Mesh* m1=dynamic_cast<Mesh*>(this);
+		for(it=m1->bones.begin();it!=m1->bones.end();it++){
+
+			Bone& bone=**it;
+
+			// find bone in mesh that matches bone in self - search based on bone name
+			Bone* mesh_bone=dynamic_cast<Bone*>(mesh->FindChild(bone.name));
+
+			if (mesh_bone){
+				// resize self arrays first so the one empty element at the end is removed
+				bone.keys->flags.pop_back();
+				bone.keys->px.pop_back();
+				bone.keys->py.pop_back();
+				bone.keys->pz.pop_back();
+				bone.keys->sx.pop_back();
+				bone.keys->sy.pop_back();
+				bone.keys->sz.pop_back();
+				bone.keys->qw.pop_back();
+				bone.keys->qx.pop_back();
+				bone.keys->qy.pop_back();
+				bone.keys->qz.pop_back();
+
+				// add mesh bone key arrays to self bone key arrays
+				bone.keys->frames=anim_seqs_last[0];
+				bone.keys->flags.insert(bone.keys->flags.end(),mesh_bone->keys->flags.begin(),mesh_bone->keys->flags.end());
+				bone.keys->px.insert(bone.keys->px.end(), mesh_bone->keys->px.begin(), mesh_bone->keys->px.end());
+				bone.keys->py.insert(bone.keys->py.end(), mesh_bone->keys->py.begin(), mesh_bone->keys->py.end());
+				bone.keys->pz.insert(bone.keys->pz.end(), mesh_bone->keys->pz.begin(), mesh_bone->keys->pz.end());
+				bone.keys->sx.insert(bone.keys->sx.end(), mesh_bone->keys->sx.begin(), mesh_bone->keys->sx.end());
+				bone.keys->sy.insert(bone.keys->sy.end(), mesh_bone->keys->sy.begin(), mesh_bone->keys->sy.end());
+				bone.keys->sz.insert(bone.keys->sz.end(), mesh_bone->keys->sz.begin(), mesh_bone->keys->sz.end());
+				bone.keys->qw.insert(bone.keys->qw.end(), mesh_bone->keys->qw.begin(), mesh_bone->keys->qw.end());
+				bone.keys->qx.insert(bone.keys->qx.end(), mesh_bone->keys->qx.begin(), mesh_bone->keys->qx.end());
+				bone.keys->qy.insert(bone.keys->qy.end(), mesh_bone->keys->qy.begin(), mesh_bone->keys->qy.end());
+				bone.keys->qz.insert(bone.keys->qz.end(), mesh_bone->keys->qz.begin(), mesh_bone->keys->qz.end());
+			}
+		}
+	}
+	mesh->FreeEntity();
+	return no_seqs;
+}
+
+void Entity::SetAnimKey(float frame, int pos_key, int rot_key, int scale_key){
+	if(dynamic_cast<Mesh*>(this)){
+		if (anim==1){			//Bone based animation
+
+			Mesh* mesh=dynamic_cast<Mesh*>(this);
+			vector<Bone*>::iterator it;
+
+			int iframe=frame;
+
+			for(it=mesh->bones.begin();it!=mesh->bones.end();it++){
+
+				Bone& bone=**it;
+				bone.keys->flags[iframe]=0;
+
+				if (rot_key){
+					bone.keys->flags[iframe] |= 4;
+					float q1_x, q1_y, q1_z, q1_w;
+					bone.rotmat.ToQuat(q1_x, q1_y, q1_z, q1_w);
+					bone.keys->qw[iframe]=-q1_w;
+					bone.keys->qx[iframe]=q1_x;
+					bone.keys->qy[iframe]=q1_y;
+					bone.keys->qz[iframe]=q1_z;
+				}
+
+				if (pos_key){
+					bone.keys->flags[iframe] |= 1;
+					bone.keys->px[iframe]=bone.px;
+					bone.keys->py[iframe]=bone.py;
+					bone.keys->pz[iframe]=-bone.pz;
+				}
+
+				if (scale_key){
+					bone.keys->flags[iframe] |= 2;
+					bone.keys->sx[iframe]=bone.sx;
+					bone.keys->sy[iframe]=bone.sy;
+					bone.keys->sz[iframe]=bone.sz;
+				}
+			}
+
+
+
+		}
+		else if (anim==2){		//Vertex based animation
+
+			Mesh* mesh=dynamic_cast<Mesh*>(this);
+
+			list<Surface*>::iterator surf_it;
+			surf_it=mesh->surf_list.begin();
+
+			list<Surface*>::iterator anim_surf_it;
+
+
+			// cycle through all surfs
+			for(anim_surf_it=mesh->anim_surf_list.begin();anim_surf_it!=mesh->anim_surf_list.end();anim_surf_it++){
+
+				Surface& anim_surf=**anim_surf_it;
+
+				Surface& surf=**surf_it;
+
+				unsigned int t=anim_surf.vert_weight4.size();
+
+				for(unsigned int i=0;i<=anim_surf.vert_weight4.size();i++){
+					if (anim_surf.vert_weight4[i]>=frame){
+						t=i;
+						break;
+					}
+				}
+				anim_surf.vert_weight4.insert(anim_surf.vert_weight4.begin()+t, frame);
+
+				t*=anim_surf.no_verts*3;
+
+				for(int i=0;i<anim_surf.no_verts;i++){
+					float x=surf.vert_coords[i*3];
+					float y=surf.vert_coords[i*3+1];
+					float z=surf.vert_coords[i*3+2];
+					if (pos_key){
+						x+=px;
+						y+=py;
+						z-=pz;
+					}
+					if (scale_key){
+						x*=sx;
+						y*=sy;
+						z*=sz;
+					}
+					if (rot_key){
+						rotmat.TransformVec(x,y,z);
+					}
+					surf.vert_coords.insert(surf.vert_coords.begin()+i*3+t, x);
+					surf.vert_coords.insert(surf.vert_coords.begin()+i*3+1+t, y);
+					surf.vert_coords.insert(surf.vert_coords.begin()+i*3+2+t, z);
+
+				}
+				surf_it++;
+
+			}
+		}
+	}
+
+}
+
 int Entity::AddAnimSeq(int length){
 
 	if (anim==false){
@@ -742,12 +908,8 @@ int Entity::AddAnimSeq(int length){
 			anim_render=true;
 
 			//mesh->frames=a_frames
-			anim_seqs_first.push_back(0);
-			anim_seqs_last.push_back(0);
-
 			anim_seqs_first[0]=0;
 			anim_seqs_last[0]=length;
-			no_seqs=1;
 
 			// create anim surfs, copy vertex coords array, add to anim_surf_list
 
@@ -762,16 +924,22 @@ int Entity::AddAnimSeq(int length){
 				mesh->anim_surf_list.push_back(anim_surf);
 				anim_surf->no_verts=surf.no_verts;
 
+				//First frame
 				anim_surf->vert_coords=surf.vert_coords;
+				anim_surf->vert_weight4.push_back(0);
 
-				anim_surf->vert_bone1_no.resize(surf.no_verts+1);
+				//Last frame
+				surf.vert_coords.insert(surf.vert_coords.end(), anim_surf->vert_coords.begin(),anim_surf->vert_coords.end());
+				anim_surf->vert_weight4.push_back(length);
+
+				/*anim_surf->vert_bone1_no.resize(surf.no_verts+1);
 				anim_surf->vert_bone2_no.resize(surf.no_verts+1);
 				anim_surf->vert_bone3_no.resize(surf.no_verts+1);
 				anim_surf->vert_bone4_no.resize(surf.no_verts+1);
 				anim_surf->vert_weight1.resize(surf.no_verts+1);
 				anim_surf->vert_weight2.resize(surf.no_verts+1);
 				anim_surf->vert_weight3.resize(surf.no_verts+1);
-				anim_surf->vert_weight4.resize(surf.no_verts+1);
+				anim_surf->vert_weight4.resize(surf.no_verts+1);*/
 
 				// transfer vmin/vmax values for using with TrimVerts func after
 				anim_surf->vmin=surf.vmin;
@@ -783,11 +951,46 @@ int Entity::AddAnimSeq(int length){
 		no_seqs=no_seqs+1;
 
 		// expand anim_seqs array
-		anim_seqs_first.push_back(0);
-		anim_seqs_last.push_back(0);
+		anim_seqs_first.push_back(anim_seqs_last[0]);
+		anim_seqs_last.push_back(anim_seqs_last[0]+length);
+
+		anim_seqs_last[0]=anim_seqs_last[0]+length;
+
+		if (anim==1){			//Bone based animation
+			Mesh* mesh=dynamic_cast<Mesh*>(this);
+			vector<Bone*>::iterator it;
+
+			for(it=mesh->bones.begin();it!=mesh->bones.end();it++){
+
+				Bone& bone=**it;
+				bone.keys->frames=anim_seqs_last[0];;
+				bone.keys->flags.resize(anim_seqs_last[0]+1);
+				bone.keys->px.resize(anim_seqs_last[0]+1);
+				bone.keys->py.resize(anim_seqs_last[0]+1);
+				bone.keys->pz.resize(anim_seqs_last[0]+1);
+				bone.keys->sx.resize(anim_seqs_last[0]+1);
+				bone.keys->sy.resize(anim_seqs_last[0]+1);
+				bone.keys->sz.resize(anim_seqs_last[0]+1);
+				bone.keys->qw.resize(anim_seqs_last[0]+1);
+				bone.keys->qx.resize(anim_seqs_last[0]+1);
+				bone.keys->qy.resize(anim_seqs_last[0]+1);
+				bone.keys->qz.resize(anim_seqs_last[0]+1);
+
+
+			}
+
+		}else if (anim==2){		//Vertex based animation
+
+			Mesh* mesh=dynamic_cast<Mesh*>(this);
+			list<Surface*>::iterator it;
+
+			for(it=mesh->anim_surf_list.begin();it!=mesh->anim_surf_list.end();it++){
+				Surface& anim_surf=**it;
+
+				anim_surf.vert_weight4.back()=anim_seqs_last[0];
+			}
+		}
 
-		anim_seqs_first[no_seqs]=anim_seqs_last[no_seqs-1];
-		anim_seqs_last[no_seqs]=anim_seqs_last[no_seqs-1]+length;
 	}
 	return no_seqs;
 }
@@ -992,7 +1195,7 @@ void Entity::AlignToVector(float x,float y,float z, int axis=3, float rate=1){
 	if (axis<1 || axis>3)
 	  return;
 
-	Matrix* m=new Matrix;
+	Matrix m;
 
 	//normalize
 	float dd = sqrt( x*x + y*y + z*z );
@@ -1013,37 +1216,36 @@ void Entity::AlignToVector(float x,float y,float z, int axis=3, float rate=1){
 	az =  TFormedZ();
 
  	//get transformation matrix from org. axis to new one
-	m->FromToRotation(ax,ay,-az, x,y,-z);
+	m.FromToRotation(ax,ay,-az, x,y,-z);
 
 	//interpolate
 	if (rate < 1.0){
-		m = InterpolateMatrix(m, rate);
+		InterpolateMatrix(m, m, rate);
 	}
 
      //apply matrix
-	this->rotmat.Multiply2(*m);
+	this->rotmat.Multiply2(m);
 	this->MQ_Update();
 
-	delete m;
 
 }
 
 
 // tform
 void Entity::TFormPoint(float x,float y,float z,Entity* src_ent,Entity* dest_ent){
-	Matrix* mat1=0;
-	Matrix* mat2=0;
+	Matrix mat1;
+	Matrix mat2;
 
 	if(src_ent != 0){
-		mat1 = src_ent->MQ_GetMatrix(true);
+		src_ent->MQ_GetMatrix(mat1, true);
 	}
 
 	if(dest_ent != 0){
-		mat2 = dest_ent->MQ_GetInvMatrix(true);
+		dest_ent->MQ_GetInvMatrix(mat2, true);
 	}
 
-	if (dest_ent != 0) {mat2->TransformVec(x, y, z, 1);delete mat2;}//global to mesh
-	if (src_ent  != 0) {mat1->TransformVec(x, y, z, 1);delete mat1;}//mesh to global
+	if (dest_ent != 0) {mat2.TransformVec(x, y, z, 1);}//global to mesh
+	if (src_ent  != 0) {mat1.TransformVec(x, y, z, 1);}//mesh to global
 
 	tformed_x=x;
 	tformed_y=y;
@@ -1053,28 +1255,28 @@ void Entity::TFormPoint(float x,float y,float z,Entity* src_ent,Entity* dest_ent
 
 void Entity::TFormVector(float x,float y,float z,Entity* src_ent,Entity* dest_ent){
 
-	Matrix* mat1=0;
-	Matrix* mat2=0;
+	Matrix mat1;
+	Matrix mat2;
 
 	//get src matrix
 	if(src_ent != 0){
-		mat1 = src_ent->MQ_GetMatrix(true);
-		mat1->grid[3][0] = 0; //remove translation
-		mat1->grid[3][1] = 0;
-		mat1->grid[3][2] = 0;
+		src_ent->MQ_GetMatrix(mat1, true);
+		mat1.grid[3][0] = 0; //remove translation
+		mat1.grid[3][1] = 0;
+		mat1.grid[3][2] = 0;
 	}
 
 	//get dest matrix
 	if(dest_ent != 0){
-		mat2 = dest_ent->MQ_GetInvMatrix(true);
-		mat2->grid[3][0] = 0; //remove translation
-		mat2->grid[3][1] = 0;
-		mat2->grid[3][2] = 0;
+		dest_ent->MQ_GetInvMatrix(mat2, true);
+		mat2.grid[3][0] = 0; //remove translation
+		mat2.grid[3][1] = 0;
+		mat2.grid[3][2] = 0;
 	}
 
 	//transform point by matrix
-	if (dest_ent != 0) {mat2->TransformVec(x, y, z, 1);delete mat2;}//global to mesh
-	if (src_ent  != 0) {mat1->TransformVec(x, y, z, 1);delete mat1;}//mesh to global
+	if (dest_ent != 0) {mat2.TransformVec(x, y, z, 1);}//global to mesh
+	if (src_ent  != 0) {mat1.TransformVec(x, y, z, 1);}//mesh to global
 
 	tformed_x=x;
 	tformed_y=y;
@@ -1136,26 +1338,24 @@ float Entity::EntityDistanceSquared(Entity* ent2){
 	return xd*xd + yd*yd + zd*zd;
 }
 
-Matrix* Entity::MQ_GetInvMatrix(int scale=true){
+void Entity::MQ_GetInvMatrix(Matrix &mat0, int scale=true){
 	Matrix mat3;
 	mat3.LoadIdentity();
 	Matrix mat2;
 	mat2.LoadIdentity();
-	Matrix* mat1;
-	Matrix* mat0;
+	Matrix mat1;
 
 	if (parent != 0) {
 		//transform by parent matrix
-		mat0 = parent->MQ_GetInvMatrix(scale);
+		parent->MQ_GetInvMatrix(mat0, scale);
 	}else{
-		mat0 = new Matrix;
-		mat0->LoadIdentity();
+		mat0.LoadIdentity();
 	}
 
 
 	//get inverted rotation matrix
-	mat1 = rotmat.Copy();
-	mat1->Transpose();
+	mat1.Overwrite(rotmat);
+	mat1.Transpose();
 
 	//scale
 	if (scale!=0) {if (sx != 0 && sy != 0 && sz != 0) {mat3.Scale(1 / sx, 1 / sy, 1 / sz);}}
@@ -1163,41 +1363,38 @@ Matrix* Entity::MQ_GetInvMatrix(int scale=true){
 	mat2.SetTranslate(-px,-py, pz);
 
 	//combine
-	mat1->Multiply2(mat3);
-	mat2.Multiply2(*mat1);
-	mat0->Multiply2(mat2);
+	mat1.Multiply2(mat3);
+	mat2.Multiply2(mat1);
+	mat0.Multiply2(mat2);
 
-	delete mat1;
-	return mat0;
+	return;
 }
 
-Matrix* Entity::MQ_GetMatrix(int scale=true){
-	Matrix* mat3 = new Matrix;
-	mat3->LoadIdentity();
+void Entity::MQ_GetMatrix(Matrix &mat3, int scale=true){
+	mat3.LoadIdentity();
 	Matrix mat2;
 	mat2.LoadIdentity();
-	Matrix* mat1;
+	Matrix mat1;
 	//float ipz;
 
 	//scale
-	if (scale!=0) {mat3->Scale(sx, sy, sz);}
+	if (scale!=0) {mat3.Scale(sx, sy, sz);}
 	//position
 	mat2.SetTranslate(px, py, -pz);
 	//rotation
-	mat1 = rotmat.Copy();
+	mat1.Overwrite(rotmat);
 
-	mat3->Multiply2(*mat1);
-	mat3->Multiply2(mat2);
+	mat3.Multiply2(mat1);
+	mat3.Multiply2(mat2);
 
 	if (parent != 0) {
 		//transform by parent matrix
-		Matrix* m=parent->MQ_GetMatrix(scale);
-		mat3->Multiply2(*m);
-		delete m;
+		Matrix m;
+		parent->MQ_GetMatrix(m, scale);
+		mat3.Multiply2(m);
 	}
 
-	delete mat1;
-	return mat3;
+	return;
 
 }
 
@@ -1216,35 +1413,31 @@ void Entity::MQ_Turn( float ang, float vx, float vy, float vz, int glob ){
 }
 
 void Entity::MQ_GetScaleXYZ(float &width, float &height, float &depth, int glob){
-	Matrix* m;
+	Matrix m;
 
 	if (glob != 0){
-		m = MQ_GetMatrix();
+		MQ_GetMatrix(m);
 	}else{
-		m = new Matrix;
-		m->LoadIdentity();
-		m->Scale(sx, sy, sz);
+		m.LoadIdentity();
+		m.Scale(sx, sy, sz);
 	}
 
 	float xx=1,xy=0,xz=0;
 	float yx=0,yy=1,yz=0;
 	float zx=0,zy=0,zz=1;
 
-	m->TransformVec(xx,xy,xz);
-	m->TransformVec(yx,yy,yz);
-	m->TransformVec(zx,zy,zz);
+	m.TransformVec(xx,xy,xz);
+	m.TransformVec(yx,yy,yz);
+	m.TransformVec(zx,zy,zz);
 
 	width  = sqrt((xx*xx)+(xy*xy)+(xz*xz));
 	height = sqrt((yx*yx)+(yy*yy)+(yz*yz));
 	depth  = sqrt((zx*zx)+(zy*zy)+(zz*zz));
 
-	delete m;
 }
 
 void Entity::MQ_Update(){
-	Matrix* m=MQ_GetMatrix(true);
-	mat.Overwrite(*m);
-	delete m;
+	MQ_GetMatrix(mat, true);
 
 	//update child_list
 	list<Entity*>::iterator it;

+ 7 - 3
openb3dlib.mod/openb3d/src/entity.h

@@ -62,7 +62,7 @@ public:
 	static list<Entity*> animate_list;
 	int anim; // true if mesh contains anim data
 	int anim_render; // true to render as anim mesh
-	float anim_mode;
+	int anim_mode;
 	float anim_time;
 	float anim_speed;
 	int anim_seq;
@@ -167,6 +167,8 @@ public:
 											
 	}
 	
+	//virtual ~Entity(){};		//Actually not needed, since no class derived from Entity has a destructor
+
 	virtual Entity* CopyEntity(Entity* ent)=0;
 	virtual void FreeEntity(void);
 	// relations
@@ -223,6 +225,8 @@ public:
 	int AnimLength();
 	float AnimTime();
 	int ExtractAnimSeq(int first_frame,int last_frame,int seq=0);
+	int LoadAnimSeq(string filename);
+	void SetAnimKey(float frame, int pos_key=true, int rot_key=true, int scale_key=true);
 	int AddAnimSeq(int length);
 	// collisions
 	void EntityType(int type_no,int recursive=false);
@@ -263,8 +267,8 @@ public:
 	float EntityDistanceSquared(Entity* ent2);	
 	// Quaternions
 	void MQ_Update();
-	Matrix* MQ_GetMatrix(int scale);
-	Matrix* MQ_GetInvMatrix(int scale);
+	void MQ_GetInvMatrix(Matrix &mat0, int scale);
+	void MQ_GetMatrix(Matrix &mat3, int scale);
 	void MQ_GetScaleXYZ(float &width, float &height, float &depth, int glob=true);
 	void MQ_Turn( float ang, float vx, float vy, float vz, int glob=false);
 	// virtual

+ 58 - 10
openb3dlib.mod/openb3d/src/functions.cpp

@@ -11,7 +11,8 @@
 #include "voxel.h"
 #include "octree.h"
 #include "geosphere.h"
-#include "metaball.h"
+#include "isosurface.h"
+#include "particle.h"
 
 extern "C" {
 
@@ -431,6 +432,10 @@ Blob* CreateBlob(Fluid* fluid, float radius, Entity* parent_ent){
 	return Blob::CreateBlob(fluid, radius, parent_ent);
 }
 
+Bone* CreateBone(Mesh* mesh, Entity* parent_ent){
+	return mesh->CreateBone(parent_ent);
+}
+
 /*
 bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=CreateBrush">Online Help</a>
 */
@@ -789,6 +794,18 @@ void FlipMesh(Mesh* mesh){
 	mesh->FlipMesh();
 }
 
+void FluidArray(Fluid* fluid, float* Array, int w, int h, int d){
+	fluid->FluidArray(Array, w, h, d);
+}
+
+void FluidFunction(Fluid* fluid, float (*FieldFunction)(float, float, float)){
+	fluid->FluidFunction(FieldFunction);
+}
+
+void FluidThreshold(Fluid* fluid, float threshold){
+	fluid->threshold=threshold;
+}
+
 /*
 bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=FreeBrush">Online Help</a>
 */
@@ -820,7 +837,6 @@ void GeosphereHeight(Geosphere* geo, float h){
 	geo->vsize=h;
 }
 
-
 /*
 bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=GetBrushTexture">Online Help</a>
 */
@@ -938,6 +954,13 @@ Mesh* LoadAnimMesh(char* file,Entity* parent){
 	return Mesh::LoadAnimMesh(file,parent);
 }
 
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=LoadAnimSeq">Online Help</a>
+*/
+int LoadAnimSeq(Entity* ent, char* file){
+	return ent->LoadAnimSeq(file);
+}
+
 /*
 bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=LoadAnimTexture">Online Help</a>
 */
@@ -1061,6 +1084,27 @@ void PaintSurface(Surface* surf,Brush* brush){
 	surf->PaintSurface(brush);
 }
 
+void ParticleColor(Sprite* sprite, float r, float g, float b, float a){
+	ParticleBatch* p=ParticleBatch::GetParticleBatch(sprite->brush.tex[0],sprite->brush.blend,sprite->order);
+	p->brush.red=r/255.0+2;
+	p->brush.green=g/255.0+2;
+	p->brush.blue=b/255.0+2;
+	p->brush.alpha=a+2;
+}
+
+void ParticleVector(Sprite* sprite, float x, float y, float z){
+	ParticleBatch* p=ParticleBatch::GetParticleBatch(sprite->brush.tex[0],sprite->brush.blend,sprite->order);
+	p->px=x;
+	p->py=y;
+	p->pz=z;
+}
+
+void ParticleTrail(Sprite* sprite,int length){
+	ParticleBatch* p=ParticleBatch::GetParticleBatch(sprite->brush.tex[0],sprite->brush.blend,sprite->order);
+	p->trail=length;
+}
+
+
 /*
 bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=PickedEntity">Online Help</a>
 */
@@ -1259,6 +1303,13 @@ void ScaleTexture(Texture* tex,float u_scale,float v_scale){
 	tex->ScaleTexture(u_scale,v_scale);
 }
 
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=SetAnimKey">Online Help</a>
+*/
+void SetAnimKey(Entity* ent, float frame, int pos_key=true, int rot_key=true, int scale_key=true){
+	ent->SetAnimKey(frame, pos_key, rot_key, scale_key);
+}
+
 /*
 bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=SetAnimTime">Online Help</a>
 */
@@ -1294,6 +1345,11 @@ void ShowEntity(Entity* ent){
 	ent->ShowEntity();
 }
 
+void SkinMesh(Mesh* mesh, int surf_no_get, int vid, int bone1, float weight1=1.0, int bone2=0, float weight2=0, int bone3=0, float weight3=0, int bone4=0, float weight4=0){
+	mesh->SkinMesh(surf_no_get, vid, bone1, weight1, bone2, weight2, bone3, weight3, bone4, weight4);
+}
+
+
 void SpriteRenderMode(Sprite* sprite,int mode){
 	sprite->SpriteRenderMode(mode);
 }
@@ -1947,14 +2003,6 @@ void SetParameter4D(Shader* material, char* name, double v1, double v2, double v
 /*
 Function LightMesh(mesh:TMesh,red#,green#,blue#,range#=0,light_x#=0,light_y#=0,light_z#=0)
 End Function
-Function MeshesIntersect(mesh1:TMesh,mesh2:TMesh)
-End Function
-Function CreatePlane(sub_divs=1,parent:TEntity=Null)
-End Function
-Function AlignToVector(vx:Float,vy:Float,vz:Float,axis,rate=1)
-End Function
-Function LoadAnimSeq(ent:TEntity,filename$)
-End Function
 Function SetAnimKey(ent:TEntity,frame,pos_key=True,rot_key=True,scale_key=True)
 End Function
 */

+ 1197 - 1193
openb3dlib.mod/openb3d/src/functions.h

@@ -1,1193 +1,1197 @@
-#ifndef __functions_h__
-#define __functions_h__
-
-// functions
-extern "C" {
-
-void BufferToTex(Texture* tex,unsigned char* buffer, int frame);
-void BackBufferToTex(Texture* tex,int frame);
-void CameraToTex(Texture* tex, Camera* cam, int frame);
-void TexToBuffer(Texture* tex,unsigned char* buffer, int frame);
-
-// wrapper only
-void DepthBufferToTex(Texture* tex,int frame);
-void GraphicsResize(int width,int height);
-void SetRenderState(int capability,int flag);
-
-/*
-bbdoc: Minib3d Only
-about:
-This command is the equivalent of Blitz3D's MeshCullBox command.
-
-It is used to set the radius of a mesh's 'cull sphere' - if the 'cull sphere' is not inside the viewing area, the mesh will not
-be rendered.
-
-A mesh's cull radius is set automatically, therefore in most cases you will not have to use this command.
-
-One time you may have to use it is for animated meshes where the default cull radius may not take into account all animation
-positions, resulting in the mesh being wrongly culled at extreme positions.
-*/
-void MeshCullRadius(Entity* ent, float radius);
-// Blitz3D functions, A-Z
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=AddAnimSeq">Online Help</a>
-*/
-int AddAnimSeq(Entity* ent,int length);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=AddMesh">Online Help</a>
-*/
-void AddMesh(Mesh* mesh1,Mesh* mesh2);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=AddTriangle">Online Help</a>
-*/
-int AddTriangle(Surface* surf,int v0,int v1,int v2);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=AddVertex">Online Help</a>
-*/
-int AddVertex(Surface* surf,float x, float y,float z,float u, float v,float w);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=AmbientLight">Online Help</a>
-*/
-void AmbientLight(float r,float g,float b);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=AntiAlias">Online Help</a>
-*/
-void AntiAlias(int samples);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=Animate">Online Help</a>
-*/
-void Animate(Entity* ent,int mode,float speed,int seq,int trans);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=Animating">Online Help</a>
-*/
-int Animating(Entity* ent);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=AnimLength">Online Help</a>
-*/
-int AnimLength(Entity* ent);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=AnimSeq">Online Help</a>
-*/
-int AnimSeq(Entity* ent);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=AnimTime">Online Help</a>
-*/
-float AnimTime(Entity* ent);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=BrushAlpha">Online Help</a>
-*/
-void BrushAlpha(Brush* brush, float a);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=BrushBlend">Online Help</a>
-*/
-void BrushBlend(Brush* brush,int blend);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=BrushColor">Online Help</a>
-*/
-void BrushColor(Brush* brush,float r,float g,float b);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=BrushFX">Online Help</a>
-*/
-void BrushFX(Brush* brush,int fx);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=BrushShininess">Online Help</a>
-*/
-void BrushShininess(Brush* brush,float s);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=BrushTexture">Online Help</a>
-*/
-void BrushTexture(Brush* brush,Texture* tex,int frame,int index);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=CameraClsColor">Online Help</a>
-*/
-void CameraClsColor(Camera* cam, float r,float g,float b);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=CameraClsMode">Online Help</a>
-*/
-void CameraClsMode(Camera* cam,int cls_depth,int cls_zbuffer);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=CameraFogColor">Online Help</a>
-*/
-void CameraFogColor(Camera* cam,float r,float g,float b);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=CameraFogMode">Online Help</a>
-*/
-void CameraFogMode(Camera* cam,int mode);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=CameraFogRange">Online Help</a>
-*/
-void CameraFogRange(Camera* cam,float nnear,float nfar);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=CameraPick">Online Help</a>
-*/
-Entity* CameraPick(Camera* cam,float x,float y);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=CameraProject">Online Help</a>
-*/
-void CameraProject(Camera* cam,float x,float y,float z);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=CameraProjMode">Online Help</a>
-*/
-void  CameraProjMode(Camera* cam,int mode);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=CameraRange">Online Help</a>
-*/
-void  CameraRange(Camera* cam,float nnear,float nfar);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=CameraViewport">Online Help</a>
-*/
-void  CameraViewport(Camera* cam,int x,int y,int width,int height);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=CameraZoom">Online Help</a>
-*/
-void  CameraZoom(Camera* cam,float zoom);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=ClearCollisions">Online Help</a>
-int ClearCollisions(){
-	Global::ClearCollisions();
-}
-*/
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=ClearSurface">Online Help</a>
-*/
-void ClearSurface(Surface* surf,bool clear_verts,bool clear_tris);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=ClearTextureFilters">Online Help</a>
-*/
-void ClearTextureFilters();
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=ClearWorld">Online Help</a>
-*/
-void ClearWorld(bool entities,bool brushes,bool textures);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=CollisionEntity">Online Help</a>
-*/
-Entity* CollisionEntity(Entity* ent,int index);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=Collisions">Online Help</a>
-*/
-void Collisions(int src_no,int dest_no,int method_no,int response_no);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=CollisionNX">Online Help</a>
-*/
-float CollisionNX(Entity* ent,int index);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=CollisionNY">Online Help</a>
-*/
-float CollisionNY(Entity* ent,int index);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=CollisionNZ">Online Help</a>
-*/
-float CollisionNZ(Entity* ent,int index);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=CollisionSurface">Online Help</a>
-*/
-Surface* CollisionSurface(Entity* ent,int index);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=CollisionTime">Online Help</a>
-*/
-float CollisionTime(Entity* ent,int index);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=CollisionTriangle">Online Help</a>
-*/
-int CollisionTriangle(Entity* ent,int index);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=CollisionX">Online Help</a>
-*/
-float CollisionX(Entity* ent,int index);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=CollisionY">Online Help</a>
-*/
-float CollisionY(Entity* ent,int index);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=CollisionZ">Online Help</a>
-*/
-float CollisionZ(Entity* ent,int index);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=CountChildren">Online Help</a>
-*/
-int CountChildren(Entity* ent);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=CountCollisions">Online Help</a>
-*/
-int CountCollisions(Entity* ent);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=CopyEntity">Online Help</a>
-*/
-Entity* CopyEntity(Entity* ent,Entity* parent);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=CopyMesh">Online Help</a>
-*/
-Mesh* CopyMesh(Mesh* mesh,Entity* parent);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=CountSurfaces">Online Help</a>
-*/
-int CountSurfaces(Mesh* mesh);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=CountTriangles">Online Help</a>
-*/
-int CountTriangles(Surface* surf);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=CountVertices">Online Help</a>
-*/
-int CountVertices(Surface* surf);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=CreateBrush">Online Help</a>
-*/
-Brush* CreateBrush(float r,float g,float b);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=CreateCamera">Online Help</a>
-*/
-Camera* CreateCamera(Entity* parent);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=CreateCone">Online Help</a>
-*/
-Mesh* CreateCone(int segments,bool solid,Entity* parent);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=CreateCylinder">Online Help</a>
-*/
-Mesh* CreateCylinder(int segments,bool solid,Entity* parent);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=CreateCube">Online Help</a>
-*/
-Mesh* CreateCube(Entity* parent);
-
-Terrain* CreateGeosphere(int size, Entity* parent);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=CreateMesh">Online Help</a>
-*/
-Mesh* CreateMesh(Entity* parent);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=CreateLight">Online Help</a>
-*/
-Light* CreateLight(int light_type,Entity* parent);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=CreatePivot">Online Help</a>
-*/
-Pivot* CreatePivot(Entity* parent);
-
-Mesh* CreatePlane(int divisions,Entity* parent);
-
-Mesh* CreateQuad(Entity* parent);
-
-ShadowObject* CreateShadow(Mesh* parent, char Static);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=CreateSphere">Online Help</a>
-*/
-Mesh* CreateSphere(int segments,Entity* parent);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=CreateSprite">Online Help</a>
-*/
-Sprite* CreateSprite(Entity* parent);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=CreateSurface">Online Help</a>
-*/
-Surface* CreateSurface(Mesh* mesh,Brush* brush);
-
-/*
-*/
-Stencil* CreateStencil();
-
-/*
-*/
-Terrain* CreateTerrain(int size, Entity* parent);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=CreateTexture">Online Help</a>
-*/
-Texture* CreateTexture(int width,int height,int flags,int frames);
-
-/*
-*/
-VoxelSprite* CreateVoxelSprite(int slices, Entity* parent);
-
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=DeltaPitch">Online Help</a>
-*/
-float DeltaPitch(Entity* ent1,Entity* ent2);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=DeltaYaw">Online Help</a>
-*/
-float DeltaYaw(Entity* ent1,Entity* ent2);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=EntityAlpha">Online Help</a>
-*/
-void EntityAlpha(Entity* ent,float alpha);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=EntityAutoFade">Online Help</a>
-*/
-void EntityAutoFade(Entity* ent,float near,float far);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=EntityBlend">Online Help</a>
-*/
-void EntityBlend(Entity* ent, int blend);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=EntityBox">Online Help</a>
-*/
-void EntityBox(Entity* ent,float x,float y,float z,float w,float h,float d);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=EntityClass">Online Help</a>
-*/
-const char* EntityClass(Entity* ent);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=EntityCollided">Online Help</a>
-*/
-Entity* EntityCollided(Entity* ent,int type_no);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=EntityColor">Online Help</a>
-*/
-void EntityColor(Entity* ent,float red,float green,float blue);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=EntityDistance">Online Help</a>
-*/
-float EntityDistance(Entity* ent1,Entity* ent2);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=EntityFX">Online Help</a>
-*/
-void EntityFX(Entity* ent,int fx);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=EntityInView">Online Help</a>
-*/
-int EntityInView(Entity* ent,Camera* cam);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=EntityName">Online Help</a>
-*/
-const char* EntityName(Entity* ent);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=EntityOrder">Online Help</a>
-*/
-void EntityOrder(Entity* ent,int order);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=EntityParent">Online Help</a>
-
-
-
-
-*/
-void EntityParent(Entity* ent,Entity* parent_ent,bool glob);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=EntityPick">Online Help</a>
-*/
-Entity* EntityPick(Entity* ent,float range);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=EntityPickMode">Online Help</a>
-*/
-void EntityPickMode(Entity* ent,int pick_mode,bool obscurer);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=EntityPitch">Online Help</a>
-*/
-float EntityPitch(Entity* ent,bool glob);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=EntityRadius">Online Help</a>
-*/
-void EntityRadius(Entity* ent,float radius_x,float radius_y);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=EntityRoll">Online Help</a>
-*/
-float EntityRoll(Entity* ent,bool glob);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=EntityShininess">Online Help</a>
-*/
-void EntityShininess(Entity* ent,float shine);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=EntityTexture">Online Help</a>
-*/
-void EntityTexture(Entity* ent,Texture* tex,int frame,int index);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=EntityType">Online Help</a>
-*/
-void EntityType(Entity* ent,int type_no,bool recursive);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=EntityVisible">Online Help</a>
-*/
-int EntityVisible(Entity* src_ent,Entity* dest_ent);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=EntityX">Online Help</a>
-*/
-float EntityX(Entity* ent,bool glob);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=EntityY">Online Help</a>
-*/
-float EntityY(Entity* ent,bool glob);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=EntityYaw">Online Help</a>
-*/
-float EntityYaw(Entity* ent,bool glob);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=EntityZ">Online Help</a>
-*/
-float EntityZ(Entity* ent,bool glob);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=ExtractAnimSeq">Online Help</a>
-*/
-int ExtractAnimSeq(Entity* ent,int first_frame,int last_frame,int seq);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=FindChild">Online Help</a>
-*/
-Entity* FindChild(Entity* ent,char* child_name);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=FindSurface">Online Help</a>
-*/
-Surface* FindSurface(Mesh* mesh,Brush* brush);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=FitMesh">Online Help</a><p>
-*/
-void FitMesh(Mesh* mesh,float x,float y,float z,float width,float height,float depth,bool uniform);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=FlipMesh">Online Help</a>
-*/
-void FlipMesh(Mesh* mesh);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=FreeBrush">Online Help</a>
-*/
-void  FreeBrush(Brush* brush);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=FreeEntity">Online Help</a>
-*/
-void FreeEntity(Entity* ent);
-
-void FreeShadow(ShadowObject* shad);
-
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=FreeTexture">Online Help</a>
-*/
-void FreeTexture(Texture* tex);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=GetBrushTexture">Online Help</a>
-*/
-Texture* GetBrushTexture(Brush* brush,int index);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=GetChild">Online Help</a>
-*/
-Entity* GetChild(Entity* ent,int child_no);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=GetEntityBrush">Online Help</a>
-*/
-Brush* GetEntityBrush(Entity* ent);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=GetEntityType">Online Help</a>
-*/
-int GetEntityType(Entity* ent);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=ResetEntity">Online Help</a>
-*/
-float GetMatElement(Entity* ent,int row,int col);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=GetParent">Online Help</a>
-*/
-Entity* GetParentEntity(Entity* ent);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=GetSurface">Online Help</a>
-*/
-Surface* GetSurface(Mesh* mesh,int surf_no);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=GetSurfaceBrush">Online Help</a>
-*/
-Brush* GetSurfaceBrush(Surface* surf);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=Graphics3D">Online Help</a>
-*/
-void Graphics3D(int width,int height,int depth,int mode,int rate);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=HandleSprite">Online Help</a>
-*/
-void HandleSprite(Sprite* sprite,float h_x,float h_y);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=HideEntity">Online Help</a>
-*/
-void HideEntity(Entity* ent);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=LightColor">Online Help</a>
-*/
-void LightColor(Light* light,float red,float green,float blue);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=LightConeAngles">Online Help</a>
-*/
-void LightConeAngles(Light* light,float inner_ang,float outer_ang);
-
-/*
-
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=LightRange">Online Help</a>
-*/
-void LightRange(Light* light,float range);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=LinePick">Online Help</a>
-*/
-Entity* LinePick(float x,float y,float z,float dx,float dy,float dz,float radius);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=LoadAnimMesh">Online Help</a>
-*/
-Mesh* LoadAnimMesh(char* file,Entity* parent);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=LoadAnimTexture">Online Help</a>
-*/
-Texture* LoadAnimTexture(char* file,int flags,int frame_width,int frame_height,int first_frame,int frame_count);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=LoadBrush">Online Help</a>
-*/
-Brush* LoadBrush(char *file,int flags,float u_scale,float v_scale);
-
-Terrain* LoadGeosphere(char* file,Entity* parent);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=LoadMesh">Online Help</a>
-*/
-Mesh* LoadMesh(char* file,Entity* parent);
-
-
-Terrain* LoadTerrain(char* file,Entity* parent);
-
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=LoadTexture">Online Help</a>
-*/
-Texture* LoadTexture(char* file,int flags);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=LoadSprite">Online Help</a>
-*/
-Sprite* LoadSprite(char* tex_file,int tex_flag,Entity* parent);
-
-/*
-*/
-Mesh* MeshCSG(Mesh* m1, Mesh* m2, int method = 1);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=MeshDepth">Online Help</a>
-*/
-float MeshDepth(Mesh* mesh);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=MeshesIntersect">Online Help</a>
-*/
-int MeshesIntersect(Mesh* mesh1,Mesh* mesh2);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=MeshHeight">Online Help</a>
-*/
-float MeshHeight(Mesh* mesh);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=MeshWidth">Online Help</a>
-*/
-float MeshWidth(Mesh* mesh);
-
-void ModifyGeosphere(Geosphere* geo, int x, int z, float new_height);
-
-void ModifyTerrain(Terrain* terr, int x, int z, float new_height);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=MoveEntity">Online Help</a>
-*/
-void MoveEntity(Entity* ent,float x,float y,float z);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=NameEntity">Online Help</a>
-*/
-void NameEntity(Entity* ent,char* name);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=PaintEntity">Online Help</a>
-*/
-void PaintEntity(Entity* ent,Brush* brush);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=PaintMesh">Online Help</a>
-*/
-void PaintMesh(Mesh* mesh,Brush* brush);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=PaintSurface">Online Help</a>
-*/
-void PaintSurface(Surface* surf,Brush* brush);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=PickedEntity">Online Help</a>
-*/
-Entity* PickedEntity();
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=PickedNX">Online Help</a>
-*/
-float PickedNX();
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=PickedNY">Online Help</a>
-*/
-float PickedNY();
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=PickedNZ">Online Help</a>
-*/
-float PickedNZ();
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=PickedSurface">Online Help</a>
-*/
-Surface* PickedSurface();
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=PickedTime">Online Help</a>
-*/
-float PickedTime();
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=PickedTriangle">Online Help</a>
-*/
-int PickedTriangle();
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=PickedX">Online Help</a>
-*/
-float PickedX();
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=PickedY">Online Help</a>
-*/
-float PickedY();
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=PickedZ">Online Help</a>
-*/
-float PickedZ();
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=PointEntity">Online Help</a>
-*/
-void PointEntity(Entity* ent,Entity* target_ent,float roll);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=PositionEntity">Online Help</a>
-*/
-void PositionEntity(Entity* ent,float x,float y,float z,bool glob);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=PositionMesh">Online Help</a>
-*/
-void PositionMesh(Mesh* mesh,float px,float py,float pz);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=PositionTexture">Online Help</a>
-*/
-void PositionTexture(Texture* tex,float u_pos,float v_pos);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=ProjectedX">Online Help</a>
-*/
-float ProjectedX();
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=ProjectedY">Online Help</a>
-*/
-float ProjectedY();
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=ProjectedZ">Online Help</a>
-*/
-float ProjectedZ();
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=RenderWorld">Online Help</a>
-*/
-void RenderWorld();
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=RepeatMesh">Online Help</a>
-*/
-Mesh* RepeatMesh(Mesh* mesh,Entity* parent);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=ResetEntity">Online Help</a>
-*/
-void ResetEntity(Entity* ent);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=RotateEntity">Online Help</a>
-*/
-void RotateEntity(Entity* ent,float x,float y,float z,bool glob);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=RotateMesh">Online Help</a>
-*/
-void RotateMesh(Mesh* mesh,float pitch,float yaw,float roll);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=RotateSprite">Online Help</a>
-*/
-void RotateSprite(Sprite* sprite,float ang);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=RotateTexture">Online Help</a>
-*/
-void RotateTexture(Texture* tex,float ang);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=ScaleEntity">Online Help</a>
-*/
-void ScaleEntity(Entity* ent,float x,float y,float z,bool glob);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=ScaleMesh">Online Help</a>
-*/
-void ScaleMesh(Mesh* mesh,float sx,float sy,float sz);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=ScaleSprite">Online Help</a>
-*/
-void ScaleSprite(Sprite* sprite,float s_x,float s_y);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=ScaleTexture">Online Help</a>
-*/
-void ScaleTexture(Texture* tex,float u_scale,float v_scale);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=SetAnimTime">Online Help</a>
-*/
-void SetAnimTime(Entity* ent,float time,int seq);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=SetCubeFace">Online Help</a>
-*/
-void SetCubeFace(Texture* tex,int face);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=SetCubeMode">Online Help</a>
-*/
-void SetCubeMode(Texture* tex,int mode);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=ShowEntity">Online Help</a>
-*/
-void ShowEntity(Entity* ent);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=SpriteViewMode">Online Help</a>
-*/
-void SpriteViewMode(Sprite* sprite,int mode);
-
-/*
-*/
-void StencilAlpha(Stencil* stencil, float a);
-
-/*
-*/
-void StencilClsColor(Stencil* stencil, float r,float g,float b);
-
-/*
-*/
-void StencilClsMode(Stencil* stencil,int cls_depth,int cls_zbuffer);
-
-/*
-*/
-void StencilMesh(Stencil* stencil, Mesh* mesh, int mode=1);
-
-/*
-*/
-void StencilMode(Stencil* stencil, int m, int o=1);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=TerrainHeight">Online Help</a>
-*/
-float TerrainHeight (Terrain* terr, int x, int z);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=TerrainX">Online Help</a>
-*/
-float TerrainX (Terrain* terr, float x, float y, float z);
-
-/*
-
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=TerrainY">Online Help</a>
-*/
-float TerrainY (Terrain* terr, float x, float y, float z);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=TerrainZ">Online Help</a>
-*/
-float TerrainZ (Terrain* terr, float x, float y, float z);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=TextureBlend">Online Help</a>
-*/
-void TextureBlend(Texture* tex,int blend);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=TextureCoords">Online Help</a>
-*/
-void TextureCoords(Texture* tex,int coords);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=TextureHeight">Online Help</a>
-*/
-int TextureHeight(Texture* tex);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=TextureFilter">Online Help</a>
-*/
-void TextureFilter(char* match_text,int flags);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=TextureName">Online Help</a>
-*/
-const char* TextureName(Texture* tex);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=TextureWidth">Online Help</a>
-*/
-int TextureWidth(Texture* tex);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=TFormedX">Online Help</a>
-*/
-float TFormedX();
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=TFormedY">Online Help</a>
-*/
-float TFormedY();
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=TFormedZ">Online Help</a>
-*/
-float TFormedZ();
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=TFormNormal">Online Help</a>
-*/
-void TFormNormal(float x,float y,float z,Entity* src_ent,Entity* dest_ent);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=TFormPoint">Online Help</a>
-*/
-void TFormPoint(float x,float y,float z,Entity* src_ent,Entity* dest_ent);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=TFormVector">Online Help</a>
-*/
-void TFormVector(float x,float y,float z,Entity* src_ent,Entity* dest_ent);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=TranslateEntity">Online Help</a>
-*/
-void TranslateEntity(Entity* ent,float x,float y,float z,bool glob);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=TriangleVertex">Online Help</a>
-*/
-int TriangleVertex(Surface* surf,int tri_no,int corner);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=TurnEntity">Online Help</a>
-*/
-void TurnEntity(Entity* ent,float x,float y,float z,bool glob);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=UpdateNormals">Online Help</a>
-*/
-void UpdateNormals(Mesh* mesh);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=UpdateNormals">Online Help</a>
-*/
-void UpdateTexCoords(Surface* surf);
-
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=UpdateWorld">Online Help</a>
-*/
-void UpdateWorld(float anim_speed);
-
-/*
-*/
-void UseStencil(Stencil* stencil);
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=VectorPitch">Online Help</a>
-*/
-float VectorPitch(float vx,float vy,float vz);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=VectorYaw">Online Help</a>
-*/
-float VectorYaw(float vx,float vy,float vz);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=VertexAlpha">Online Help</a>
-*/
-float VertexAlpha(Surface* surf,int vid);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=VertexBlue">Online Help</a>
-*/
-float VertexBlue(Surface* surf,int vid);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=VertexColor">Online Help</a>
-*/
-void VertexColor(Surface* surf,int vid,float r,float g,float b,float a);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=VertexCoords">Online Help</a>
-*/
-void VertexCoords(Surface* surf,int vid,float x,float y,float z);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=VertexGreen">Online Help</a>
-*/
-float VertexGreen(Surface* surf,int vid);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=VertexNormal">Online Help</a>
-*/
-void VertexNormal(Surface* surf,int vid,float nx,float ny,float nz);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=VertexNX">Online Help</a>
-*/
-float VertexNX(Surface* surf,int vid);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=VertexNY">Online Help</a>
-*/
-float VertexNY(Surface* surf,int vid);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=VertexNZ">Online Help</a>
-*/
-float VertexNZ(Surface* surf,int vid);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=VertexRed">Online Help</a>
-*/
-float VertexRed(Surface* surf,int vid);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=VertexTexCoords">Online Help</a>
-*/
-void VertexTexCoords(Surface* surf,int vid,float u,float v,float w,int coord_set);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=VertexU">Online Help</a>
-*/
-float VertexU(Surface* surf,int vid,int coord_set);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=VertexV">Online Help</a>
-*/
-float VertexV(Surface* surf,int vid,int coord_set);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=VertexW">Online Help</a>
-*/
-float VertexW(Surface* surf,int vid,int coord_set);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=VertexX">Online Help</a>
-*/
-float VertexX(Surface* surf,int vid);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=VertexY">Online Help</a>
-*/
-float VertexY(Surface* surf,int vid);
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=VertexZ">Online Help</a>
-*/
-float VertexZ(Surface* surf,int vid);
-
-/*
-*/
-void VoxelSpriteMaterial(VoxelSprite* voxelspr, Material* mat);
-
-
-/*
-bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=Wireframe">Online Help</a>
-*/
-void Wireframe(int enable);
-
-
-float EntityScaleX(Entity* ent,bool glob);
-
-float EntityScaleY(Entity* ent,bool glob);
-
-float EntityScaleZ(Entity* ent,bool glob);
-
-Shader* LoadShader(char* ShaderName, char* VshaderFileName, char* FshaderFileName);
-
-Shader* CreateShader(char* ShaderName, char* VshaderString, char* FshaderString);
-
-void ShadeSurface(Surface* surf, Shader* material);
-
-void ShadeMesh(Mesh* mesh, Shader* material);
-
-void ShadeEntity(Entity* ent, Shader* material);
-
-void ShaderTexture(Shader* material, Texture* tex, char* name, int index);
-
-void SetFloat(Shader* material, char* name, float v1);
-
-void SetFloat2(Shader* material, char* name, float v1, float v2);
-
-void SetFloat3(Shader* material, char* name, float v1, float v2, float v3);
-
-void SetFloat4(Shader* material, char* name, float v1, float v2, float v3, float v4);
-
-void UseFloat(Shader* material, char* name, float* v1);
-
-void UseFloat2(Shader* material, char* name, float* v1, float* v2);
-
-void UseFloat3(Shader* material, char* name, float* v1, float* v2, float* v3);
-
-void UseFloat4(Shader* material, char* name, float* v1, float* v2, float* v3, float* v4);
-
-void SetInteger(Shader* material, char* name, int v1);
-
-void SetInteger2(Shader* material, char* name, int v1, int v2):
-
-void SetInteger3(Shader* material, char* name, int v1, int v2, int v3);
-
-void SetInteger4(Shader* material, char* name, int v1, int v2, int v3, int v4);
-
-void UseInteger(Shader* material, char* name, int* v1);
-
-void UseInteger2(Shader* material, char* name, int* v1, int* v2);
-
-void UseInteger3(Shader* material, char* name, int* v1, int* v2, int* v3);
-
-void UseInteger4(Shader* material, char* name, int* v1, int* v2, int* v3, int* v4);
-
-void UseSurface(Shader* material, char* name, Surface* surf, int vbo);
-
-void UseMatrix(Shader* material, char* name, int mode);
-
-Material* LoadMaterial(char* filename,int flags, int frame_width,int frame_height,int first_frame,int frame_count);
-
-void ShaderMaterial(Shader* material, Material* tex, char* name, int index);
-
-
-
-
-
-
-OcTree* CreateOcTree(float w, float h, float d, Entity* parent_ent=0);
-
-void AddToOctree(OcTree* octree, Mesh* mesh, int level, float X, float Y, float Z, float Near=0.0, float Far=1000.0);
-
-
-} // extern "C"
-
-#endif
+#ifndef __functions_h__
+#define __functions_h__
+
+
+#if defined(WIN32) & !defined(OPENB3D_STATIC)
+ #ifdef BUILD_DLL
+  #define DLL_EXPORT __declspec(dllexport)
+ #else
+  #define DLL_EXPORT __declspec(dllimport)
+ #endif
+#else
+ #define DLL_EXPORT
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void DLL_EXPORT BufferToTex(Texture* tex,unsigned char* buffer, int frame);
+void DLL_EXPORT BackBufferToTex(Texture* tex,int frame);
+void DLL_EXPORT CameraToTex(Texture* tex, Camera* cam, int frame);
+void DLL_EXPORT TexToBuffer(Texture* tex,unsigned char* buffer, int frame);
+
+// wrapper only
+void DepthBufferToTex(Texture* tex,int frame);
+void GraphicsResize(int width,int height);
+void SetRenderState(int capability,int flag);
+
+/*
+bbdoc: Minib3d Only
+about:
+This command is the equivalent of Blitz3D's MeshCullBox command.
+
+It is used to set the radius of a mesh's 'cull sphere' - if the 'cull sphere' is not inside the viewing area, the mesh will not
+be rendered.
+
+A mesh's cull radius is set automatically, therefore in most cases you will not have to use this command.
+
+One time you may have to use it is for animated meshes where the default cull radius may not take into account all animation
+positions, resulting in the mesh being wrongly culled at extreme positions.
+*/
+void DLL_EXPORT MeshCullRadius(Entity* ent, float radius);
+// Blitz3D functions, A-Z
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=AddAnimSeq">Online Help</a>
+*/
+int DLL_EXPORT AddAnimSeq(Entity* ent,int length);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=AddMesh">Online Help</a>
+*/
+void DLL_EXPORT AddMesh(Mesh* mesh1,Mesh* mesh2);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=AddTriangle">Online Help</a>
+*/
+int DLL_EXPORT AddTriangle(Surface* surf,int v0,int v1,int v2);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=AddVertex">Online Help</a>
+*/
+int DLL_EXPORT AddVertex(Surface* surf,float x, float y,float z,float u, float v,float w);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=AmbientLight">Online Help</a>
+*/
+void DLL_EXPORT AmbientLight(float r,float g,float b);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=AntiAlias">Online Help</a>
+*/
+void DLL_EXPORT AntiAlias(int samples);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=Animate">Online Help</a>
+*/
+void DLL_EXPORT Animate(Entity* ent,int mode,float speed,int seq,int trans);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=Animating">Online Help</a>
+*/
+int DLL_EXPORT Animating(Entity* ent);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=AnimLength">Online Help</a>
+*/
+int DLL_EXPORT AnimLength(Entity* ent);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=AnimSeq">Online Help</a>
+*/
+int DLL_EXPORT AnimSeq(Entity* ent);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=AnimTime">Online Help</a>
+*/
+float DLL_EXPORT AnimTime(Entity* ent);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=BrushAlpha">Online Help</a>
+*/
+void DLL_EXPORT BrushAlpha(Brush* brush, float a);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=BrushBlend">Online Help</a>
+*/
+void DLL_EXPORT BrushBlend(Brush* brush,int blend);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=BrushColor">Online Help</a>
+*/
+void DLL_EXPORT BrushColor(Brush* brush,float r,float g,float b);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=BrushFX">Online Help</a>
+*/
+void DLL_EXPORT BrushFX(Brush* brush,int fx);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=BrushShininess">Online Help</a>
+*/
+void DLL_EXPORT BrushShininess(Brush* brush,float s);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=BrushTexture">Online Help</a>
+*/
+void DLL_EXPORT BrushTexture(Brush* brush,Texture* tex,int frame,int index);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=CameraClsColor">Online Help</a>
+*/
+void DLL_EXPORT CameraClsColor(Camera* cam, float r,float g,float b);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=CameraClsMode">Online Help</a>
+*/
+void DLL_EXPORT CameraClsMode(Camera* cam,int cls_depth,int cls_zbuffer);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=CameraFogColor">Online Help</a>
+*/
+void DLL_EXPORT CameraFogColor(Camera* cam,float r,float g,float b);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=CameraFogMode">Online Help</a>
+*/
+void DLL_EXPORT CameraFogMode(Camera* cam,int mode);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=CameraFogRange">Online Help</a>
+*/
+void DLL_EXPORT CameraFogRange(Camera* cam,float nnear,float nfar);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=CameraPick">Online Help</a>
+*/
+Entity* DLL_EXPORT CameraPick(Camera* cam,float x,float y);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=CameraProject">Online Help</a>
+*/
+void DLL_EXPORT CameraProject(Camera* cam,float x,float y,float z);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=CameraProjMode">Online Help</a>
+*/
+void DLL_EXPORT CameraProjMode(Camera* cam,int mode);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=CameraRange">Online Help</a>
+*/
+void DLL_EXPORT CameraRange(Camera* cam,float nnear,float nfar);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=CameraViewport">Online Help</a>
+*/
+void DLL_EXPORT CameraViewport(Camera* cam,int x,int y,int width,int height);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=CameraZoom">Online Help</a>
+*/
+void DLL_EXPORT CameraZoom(Camera* cam,float zoom);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=ClearCollisions">Online Help</a>
+int ClearCollisions(){
+	Global::ClearCollisions();
+}
+*/
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=ClearSurface">Online Help</a>
+*/
+void DLL_EXPORT ClearSurface(Surface* surf,int clear_verts,int clear_tris);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=ClearTextureFilters">Online Help</a>
+*/
+void DLL_EXPORT ClearTextureFilters();
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=ClearWorld">Online Help</a>
+*/
+void DLL_EXPORT ClearWorld(int entities,int brushes,int textures);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=CollisionEntity">Online Help</a>
+*/
+Entity* DLL_EXPORT CollisionEntity(Entity* ent,int index);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=Collisions">Online Help</a>
+*/
+void DLL_EXPORT Collisions(int src_no,int dest_no,int method_no,int response_no);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=CollisionNX">Online Help</a>
+*/
+float DLL_EXPORT CollisionNX(Entity* ent,int index);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=CollisionNY">Online Help</a>
+*/
+float DLL_EXPORT CollisionNY(Entity* ent,int index);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=CollisionNZ">Online Help</a>
+*/
+float DLL_EXPORT CollisionNZ(Entity* ent,int index);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=CollisionSurface">Online Help</a>
+*/
+Surface* DLL_EXPORT CollisionSurface(Entity* ent,int index);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=CollisionTime">Online Help</a>
+*/
+float DLL_EXPORT CollisionTime(Entity* ent,int index);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=CollisionTriangle">Online Help</a>
+*/
+int DLL_EXPORT CollisionTriangle(Entity* ent,int index);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=CollisionX">Online Help</a>
+*/
+float DLL_EXPORT CollisionX(Entity* ent,int index);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=CollisionY">Online Help</a>
+*/
+float DLL_EXPORT CollisionY(Entity* ent,int index);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=CollisionZ">Online Help</a>
+*/
+float DLL_EXPORT CollisionZ(Entity* ent,int index);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=CountChildren">Online Help</a>
+*/
+int DLL_EXPORT CountChildren(Entity* ent);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=CountCollisions">Online Help</a>
+*/
+int DLL_EXPORT CountCollisions(Entity* ent);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=CopyEntity">Online Help</a>
+*/
+Entity* DLL_EXPORT CopyEntity(Entity* ent,Entity* parent);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=CopyMesh">Online Help</a>
+*/
+Mesh* DLL_EXPORT CopyMesh(Mesh* mesh,Entity* parent);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=CountSurfaces">Online Help</a>
+*/
+int DLL_EXPORT CountSurfaces(Mesh* mesh);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=CountTriangles">Online Help</a>
+*/
+int DLL_EXPORT CountTriangles(Surface* surf);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=CountVertices">Online Help</a>
+*/
+int DLL_EXPORT CountVertices(Surface* surf);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=CreateBrush">Online Help</a>
+*/
+Brush* DLL_EXPORT CreateBrush(float r,float g,float b);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=CreateCamera">Online Help</a>
+*/
+Camera* DLL_EXPORT CreateCamera(Entity* parent);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=CreateCone">Online Help</a>
+*/
+Mesh* DLL_EXPORT CreateCone(int segments,int solid,Entity* parent);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=CreateCylinder">Online Help</a>
+*/
+Mesh* DLL_EXPORT CreateCylinder(int segments,int solid,Entity* parent);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=CreateCube">Online Help</a>
+*/
+Mesh* DLL_EXPORT CreateCube(Entity* parent);
+
+Terrain* DLL_EXPORT CreateGeosphere(int size, Entity* parent);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=CreateMesh">Online Help</a>
+*/
+Mesh* DLL_EXPORT CreateMesh(Entity* parent);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=CreateLight">Online Help</a>
+*/
+Light* DLL_EXPORT CreateLight(int light_type,Entity* parent);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=CreatePivot">Online Help</a>
+*/
+Pivot* DLL_EXPORT CreatePivot(Entity* parent);
+
+Mesh* DLL_EXPORT CreatePlane(int divisions,Entity* parent);
+
+Mesh* DLL_EXPORT CreateQuad(Entity* parent);
+
+ShadowObject* DLL_EXPORT CreateShadow(Mesh* parent, char Static);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=CreateSphere">Online Help</a>
+*/
+Mesh* DLL_EXPORT CreateSphere(int segments,Entity* parent);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=CreateSprite">Online Help</a>
+*/
+Sprite* DLL_EXPORT CreateSprite(Entity* parent);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=CreateSurface">Online Help</a>
+*/
+Surface* DLL_EXPORT CreateSurface(Mesh* mesh,Brush* brush);
+
+/*
+*/
+Stencil* DLL_EXPORT CreateStencil();
+
+/*
+*/
+Terrain* DLL_EXPORT CreateTerrain(int size, Entity* parent);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=CreateTexture">Online Help</a>
+*/
+Texture* DLL_EXPORT CreateTexture(int width,int height,int flags,int frames);
+
+/*
+*/
+VoxelSprite* DLL_EXPORT CreateVoxelSprite(int slices, Entity* parent);
+
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=DeltaPitch">Online Help</a>
+*/
+float DLL_EXPORT DeltaPitch(Entity* ent1,Entity* ent2);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=DeltaYaw">Online Help</a>
+*/
+float DLL_EXPORT DeltaYaw(Entity* ent1,Entity* ent2);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=EntityAlpha">Online Help</a>
+*/
+void DLL_EXPORT EntityAlpha(Entity* ent,float alpha);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=EntityAutoFade">Online Help</a>
+*/
+void DLL_EXPORT EntityAutoFade(Entity* ent,float near,float far);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=EntityBlend">Online Help</a>
+*/
+void DLL_EXPORT EntityBlend(Entity* ent, int blend);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=EntityBox">Online Help</a>
+*/
+void DLL_EXPORT EntityBox(Entity* ent,float x,float y,float z,float w,float h,float d);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=EntityClass">Online Help</a>
+*/
+const char* DLL_EXPORT EntityClass(Entity* ent);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=EntityCollided">Online Help</a>
+*/
+Entity* DLL_EXPORT EntityCollided(Entity* ent,int type_no);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=EntityColor">Online Help</a>
+*/
+void DLL_EXPORT EntityColor(Entity* ent,float red,float green,float blue);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=EntityDistance">Online Help</a>
+*/
+float DLL_EXPORT EntityDistance(Entity* ent1,Entity* ent2);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=EntityFX">Online Help</a>
+*/
+void DLL_EXPORT EntityFX(Entity* ent,int fx);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=EntityInView">Online Help</a>
+*/
+int DLL_EXPORT EntityInView(Entity* ent,Camera* cam);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=EntityName">Online Help</a>
+*/
+const char* DLL_EXPORT EntityName(Entity* ent);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=EntityOrder">Online Help</a>
+*/
+void DLL_EXPORT EntityOrder(Entity* ent,int order);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=EntityParent">Online Help</a>
+*/
+void DLL_EXPORT EntityParent(Entity* ent,Entity* parent_ent,int glob);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=EntityPick">Online Help</a>
+*/
+Entity* DLL_EXPORT EntityPick(Entity* ent,float range);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=EntityPickMode">Online Help</a>
+*/
+void DLL_EXPORT EntityPickMode(Entity* ent,int pick_mode,int obscurer);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=EntityPitch">Online Help</a>
+*/
+float DLL_EXPORT EntityPitch(Entity* ent,int glob);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=EntityRadius">Online Help</a>
+*/
+void DLL_EXPORT EntityRadius(Entity* ent,float radius_x,float radius_y);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=EntityRoll">Online Help</a>
+*/
+float DLL_EXPORT EntityRoll(Entity* ent,int glob);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=EntityShininess">Online Help</a>
+*/
+void DLL_EXPORT EntityShininess(Entity* ent,float shine);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=EntityTexture">Online Help</a>
+*/
+void DLL_EXPORT EntityTexture(Entity* ent,Texture* tex,int frame,int index);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=EntityType">Online Help</a>
+*/
+void DLL_EXPORT EntityType(Entity* ent,int type_no,int recursive);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=EntityVisible">Online Help</a>
+*/
+int DLL_EXPORT EntityVisible(Entity* src_ent,Entity* dest_ent);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=EntityX">Online Help</a>
+*/
+float DLL_EXPORT EntityX(Entity* ent,int glob);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=EntityY">Online Help</a>
+*/
+float DLL_EXPORT EntityY(Entity* ent,int glob);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=EntityYaw">Online Help</a>
+*/
+float DLL_EXPORT EntityYaw(Entity* ent,int glob);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=EntityZ">Online Help</a>
+*/
+float DLL_EXPORT EntityZ(Entity* ent,int glob);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=ExtractAnimSeq">Online Help</a>
+*/
+int DLL_EXPORT ExtractAnimSeq(Entity* ent,int first_frame,int last_frame,int seq);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=FindChild">Online Help</a>
+*/
+Entity* DLL_EXPORT FindChild(Entity* ent,char* child_name);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=FindSurface">Online Help</a>
+*/
+Surface* DLL_EXPORT FindSurface(Mesh* mesh,Brush* brush);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=FitMesh">Online Help</a><p>
+*/
+void DLL_EXPORT FitMesh(Mesh* mesh,float x,float y,float z,float width,float height,float depth,int uniform);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=FlipMesh">Online Help</a>
+*/
+void DLL_EXPORT FlipMesh(Mesh* mesh);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=FreeBrush">Online Help</a>
+*/
+void DLL_EXPORT FreeBrush(Brush* brush);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=FreeEntity">Online Help</a>
+*/
+void DLL_EXPORT FreeEntity(Entity* ent);
+
+void DLL_EXPORT FreeShadow(ShadowObject* shad);
+
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=FreeTexture">Online Help</a>
+*/
+void DLL_EXPORT FreeTexture(Texture* tex);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=GetBrushTexture">Online Help</a>
+*/
+Texture* DLL_EXPORT GetBrushTexture(Brush* brush,int index);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=GetChild">Online Help</a>
+*/
+Entity* DLL_EXPORT GetChild(Entity* ent,int child_no);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=GetEntityBrush">Online Help</a>
+*/
+Brush* DLL_EXPORT GetEntityBrush(Entity* ent);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=GetEntityType">Online Help</a>
+*/
+int DLL_EXPORT GetEntityType(Entity* ent);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=ResetEntity">Online Help</a>
+*/
+float DLL_EXPORT GetMatElement(Entity* ent,int row,int col);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=GetParent">Online Help</a>
+*/
+Entity* DLL_EXPORT GetParentEntity(Entity* ent);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=GetSurface">Online Help</a>
+*/
+Surface* DLL_EXPORT GetSurface(Mesh* mesh,int surf_no);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=GetSurfaceBrush">Online Help</a>
+*/
+Brush* DLL_EXPORT GetSurfaceBrush(Surface* surf);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=Graphics3D">Online Help</a>
+*/
+void DLL_EXPORT Graphics3D(int width,int height,int depth,int mode,int rate);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=HandleSprite">Online Help</a>
+*/
+void DLL_EXPORT HandleSprite(Sprite* sprite,float h_x,float h_y);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=HideEntity">Online Help</a>
+*/
+void DLL_EXPORT HideEntity(Entity* ent);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=LightColor">Online Help</a>
+*/
+void DLL_EXPORT LightColor(Light* light,float red,float green,float blue);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=LightConeAngles">Online Help</a>
+*/
+void DLL_EXPORT LightConeAngles(Light* light,float inner_ang,float outer_ang);
+
+/*
+
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=LightRange">Online Help</a>
+*/
+void DLL_EXPORT LightRange(Light* light,float range);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=LinePick">Online Help</a>
+*/
+Entity* DLL_EXPORT LinePick(float x,float y,float z,float dx,float dy,float dz,float radius);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=LoadAnimMesh">Online Help</a>
+*/
+Mesh* DLL_EXPORT LoadAnimMesh(char* file,Entity* parent);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=LoadAnimTexture">Online Help</a>
+*/
+Texture* DLL_EXPORT LoadAnimTexture(char* file,int flags,int frame_width,int frame_height,int first_frame,int frame_count);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=LoadBrush">Online Help</a>
+*/
+Brush* DLL_EXPORT LoadBrush(char *file,int flags,float u_scale,float v_scale);
+
+Terrain* DLL_EXPORT LoadGeosphere(char* file,Entity* parent);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=LoadMesh">Online Help</a>
+*/
+Mesh* DLL_EXPORT LoadMesh(char* file,Entity* parent);
+
+
+Terrain* DLL_EXPORT LoadTerrain(char* file,Entity* parent);
+
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=LoadTexture">Online Help</a>
+*/
+Texture* DLL_EXPORT LoadTexture(char* file,int flags);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=LoadSprite">Online Help</a>
+*/
+Sprite* DLL_EXPORT LoadSprite(char* tex_file,int tex_flag,Entity* parent);
+
+/*
+*/
+Mesh* DLL_EXPORT MeshCSG(Mesh* m1, Mesh* m2, int method);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=MeshDepth">Online Help</a>
+*/
+float DLL_EXPORT MeshDepth(Mesh* mesh);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=MeshesIntersect">Online Help</a>
+*/
+int DLL_EXPORT MeshesIntersect(Mesh* mesh1,Mesh* mesh2);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=MeshHeight">Online Help</a>
+*/
+float DLL_EXPORT MeshHeight(Mesh* mesh);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=MeshWidth">Online Help</a>
+*/
+float DLL_EXPORT MeshWidth(Mesh* mesh);
+
+void DLL_EXPORT ModifyGeosphere(Geosphere* geo, int x, int z, float new_height);
+
+void DLL_EXPORT ModifyTerrain(Terrain* terr, int x, int z, float new_height);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=MoveEntity">Online Help</a>
+*/
+void DLL_EXPORT MoveEntity(Entity* ent,float x,float y,float z);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=NameEntity">Online Help</a>
+*/
+void DLL_EXPORT NameEntity(Entity* ent,char* name);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=PaintEntity">Online Help</a>
+*/
+void DLL_EXPORT PaintEntity(Entity* ent,Brush* brush);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=PaintMesh">Online Help</a>
+*/
+void DLL_EXPORT PaintMesh(Mesh* mesh,Brush* brush);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=PaintSurface">Online Help</a>
+*/
+void DLL_EXPORT PaintSurface(Surface* surf,Brush* brush);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=PickedEntity">Online Help</a>
+*/
+Entity* DLL_EXPORT PickedEntity();
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=PickedNX">Online Help</a>
+*/
+float DLL_EXPORT PickedNX();
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=PickedNY">Online Help</a>
+*/
+float DLL_EXPORT PickedNY();
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=PickedNZ">Online Help</a>
+*/
+float DLL_EXPORT PickedNZ();
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=PickedSurface">Online Help</a>
+*/
+Surface* DLL_EXPORT PickedSurface();
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=PickedTime">Online Help</a>
+*/
+float DLL_EXPORT PickedTime();
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=PickedTriangle">Online Help</a>
+*/
+int DLL_EXPORT PickedTriangle();
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=PickedX">Online Help</a>
+*/
+float DLL_EXPORT PickedX();
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=PickedY">Online Help</a>
+*/
+float DLL_EXPORT PickedY();
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=PickedZ">Online Help</a>
+*/
+float DLL_EXPORT PickedZ();
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=PointEntity">Online Help</a>
+*/
+void DLL_EXPORT PointEntity(Entity* ent,Entity* target_ent,float roll);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=PositionEntity">Online Help</a>
+*/
+void DLL_EXPORT PositionEntity(Entity* ent,float x,float y,float z,int glob);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=PositionMesh">Online Help</a>
+*/
+void DLL_EXPORT PositionMesh(Mesh* mesh,float px,float py,float pz);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=PositionTexture">Online Help</a>
+*/
+void DLL_EXPORT PositionTexture(Texture* tex,float u_pos,float v_pos);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=ProjectedX">Online Help</a>
+*/
+float DLL_EXPORT ProjectedX();
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=ProjectedY">Online Help</a>
+*/
+float DLL_EXPORT ProjectedY();
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=ProjectedZ">Online Help</a>
+*/
+float DLL_EXPORT ProjectedZ();
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=RenderWorld">Online Help</a>
+*/
+void DLL_EXPORT RenderWorld();
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=RepeatMesh">Online Help</a>
+*/
+Mesh* DLL_EXPORT RepeatMesh(Mesh* mesh,Entity* parent);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=ResetEntity">Online Help</a>
+*/
+void DLL_EXPORT ResetEntity(Entity* ent);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=RotateEntity">Online Help</a>
+*/
+void DLL_EXPORT RotateEntity(Entity* ent,float x,float y,float z,int glob);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=RotateMesh">Online Help</a>
+*/
+void DLL_EXPORT RotateMesh(Mesh* mesh,float pitch,float yaw,float roll);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=RotateSprite">Online Help</a>
+*/
+void DLL_EXPORT RotateSprite(Sprite* sprite,float ang);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=RotateTexture">Online Help</a>
+*/
+void DLL_EXPORT RotateTexture(Texture* tex,float ang);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=ScaleEntity">Online Help</a>
+*/
+void DLL_EXPORT ScaleEntity(Entity* ent,float x,float y,float z,int glob);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=ScaleMesh">Online Help</a>
+*/
+void DLL_EXPORT ScaleMesh(Mesh* mesh,float sx,float sy,float sz);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=ScaleSprite">Online Help</a>
+*/
+void DLL_EXPORT ScaleSprite(Sprite* sprite,float s_x,float s_y);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=ScaleTexture">Online Help</a>
+*/
+void DLL_EXPORT ScaleTexture(Texture* tex,float u_scale,float v_scale);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=SetAnimTime">Online Help</a>
+*/
+void DLL_EXPORT SetAnimTime(Entity* ent,float time,int seq);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=SetCubeFace">Online Help</a>
+*/
+void DLL_EXPORT SetCubeFace(Texture* tex,int face);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=SetCubeMode">Online Help</a>
+*/
+void DLL_EXPORT SetCubeMode(Texture* tex,int mode);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=ShowEntity">Online Help</a>
+*/
+void DLL_EXPORT ShowEntity(Entity* ent);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=SpriteViewMode">Online Help</a>
+*/
+void DLL_EXPORT SpriteViewMode(Sprite* sprite,int mode);
+
+/*
+*/
+void DLL_EXPORT StencilAlpha(Stencil* stencil, float a);
+
+/*
+*/
+void DLL_EXPORT StencilClsColor(Stencil* stencil, float r,float g,float b);
+
+/*
+*/
+void DLL_EXPORT StencilClsMode(Stencil* stencil,int cls_depth,int cls_zbuffer);
+
+/*
+*/
+void DLL_EXPORT StencilMesh(Stencil* stencil, Mesh* mesh, int mode);
+
+/*
+*/
+void DLL_EXPORT StencilMode(Stencil* stencil, int m, int o);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=TerrainHeight">Online Help</a>
+*/
+float DLL_EXPORT TerrainHeight (Terrain* terr, int x, int z);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=TerrainX">Online Help</a>
+*/
+float DLL_EXPORT TerrainX(Terrain* terr, float x, float y, float z);
+
+/*
+
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=TerrainY">Online Help</a>
+*/
+float DLL_EXPORT TerrainY(Terrain* terr, float x, float y, float z);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=TerrainZ">Online Help</a>
+*/
+float DLL_EXPORT TerrainZ(Terrain* terr, float x, float y, float z);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=TextureBlend">Online Help</a>
+*/
+void DLL_EXPORT TextureBlend(Texture* tex,int blend);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=TextureCoords">Online Help</a>
+*/
+void DLL_EXPORT TextureCoords(Texture* tex,int coords);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=TextureHeight">Online Help</a>
+*/
+int DLL_EXPORT TextureHeight(Texture* tex);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=TextureFilter">Online Help</a>
+*/
+void DLL_EXPORT TextureFilter(char* match_text,int flags);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=TextureName">Online Help</a>
+*/
+const char* DLL_EXPORT TextureName(Texture* tex);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=TextureWidth">Online Help</a>
+*/
+int DLL_EXPORT TextureWidth(Texture* tex);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=TFormedX">Online Help</a>
+*/
+float DLL_EXPORT TFormedX();
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=TFormedY">Online Help</a>
+*/
+float DLL_EXPORT TFormedY();
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=TFormedZ">Online Help</a>
+*/
+float DLL_EXPORT TFormedZ();
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=TFormNormal">Online Help</a>
+*/
+void DLL_EXPORT TFormNormal(float x,float y,float z,Entity* src_ent,Entity* dest_ent);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=TFormPoint">Online Help</a>
+*/
+void DLL_EXPORT TFormPoint(float x,float y,float z,Entity* src_ent,Entity* dest_ent);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=TFormVector">Online Help</a>
+*/
+void DLL_EXPORT TFormVector(float x,float y,float z,Entity* src_ent,Entity* dest_ent);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=TranslateEntity">Online Help</a>
+*/
+void DLL_EXPORT TranslateEntity(Entity* ent,float x,float y,float z,int glob);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=TriangleVertex">Online Help</a>
+*/
+int DLL_EXPORT TriangleVertex(Surface* surf,int tri_no,int corner);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=TurnEntity">Online Help</a>
+*/
+void DLL_EXPORT TurnEntity(Entity* ent,float x,float y,float z,int glob);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=UpdateNormals">Online Help</a>
+*/
+void DLL_EXPORT UpdateNormals(Mesh* mesh);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=UpdateNormals">Online Help</a>
+*/
+void DLL_EXPORT UpdateTexCoords(Surface* surf);
+
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=UpdateWorld">Online Help</a>
+*/
+void DLL_EXPORT UpdateWorld(float anim_speed);
+
+/*
+*/
+void DLL_EXPORT UseStencil(Stencil* stencil);
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=VectorPitch">Online Help</a>
+*/
+float DLL_EXPORT VectorPitch(float vx,float vy,float vz);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=VectorYaw">Online Help</a>
+*/
+float DLL_EXPORT VectorYaw(float vx,float vy,float vz);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=VertexAlpha">Online Help</a>
+*/
+float DLL_EXPORT VertexAlpha(Surface* surf,int vid);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=VertexBlue">Online Help</a>
+*/
+float DLL_EXPORT VertexBlue(Surface* surf,int vid);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=VertexColor">Online Help</a>
+*/
+void DLL_EXPORT VertexColor(Surface* surf,int vid,float r,float g,float b,float a);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=VertexCoords">Online Help</a>
+*/
+void DLL_EXPORT VertexCoords(Surface* surf,int vid,float x,float y,float z);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=VertexGreen">Online Help</a>
+*/
+float DLL_EXPORT VertexGreen(Surface* surf,int vid);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=VertexNormal">Online Help</a>
+*/
+void DLL_EXPORT VertexNormal(Surface* surf,int vid,float nx,float ny,float nz);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=VertexNX">Online Help</a>
+*/
+float DLL_EXPORT VertexNX(Surface* surf,int vid);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=VertexNY">Online Help</a>
+*/
+float DLL_EXPORT VertexNY(Surface* surf,int vid);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=VertexNZ">Online Help</a>
+*/
+float DLL_EXPORT VertexNZ(Surface* surf,int vid);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=VertexRed">Online Help</a>
+*/
+float DLL_EXPORT VertexRed(Surface* surf,int vid);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=VertexTexCoords">Online Help</a>
+*/
+void DLL_EXPORT VertexTexCoords(Surface* surf,int vid,float u,float v,float w,int coord_set);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=VertexU">Online Help</a>
+*/
+float DLL_EXPORT VertexU(Surface* surf,int vid,int coord_set);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=VertexV">Online Help</a>
+*/
+float DLL_EXPORT VertexV(Surface* surf,int vid,int coord_set);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=VertexW">Online Help</a>
+*/
+float DLL_EXPORT VertexW(Surface* surf,int vid,int coord_set);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=VertexX">Online Help</a>
+*/
+float DLL_EXPORT VertexX(Surface* surf,int vid);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=VertexY">Online Help</a>
+*/
+float DLL_EXPORT VertexY(Surface* surf,int vid);
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=VertexZ">Online Help</a>
+*/
+float DLL_EXPORT VertexZ(Surface* surf,int vid);
+
+/*
+*/
+void DLL_EXPORT VoxelSpriteMaterial(VoxelSprite* voxelspr, Material* mat);
+
+
+/*
+bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=Wireframe">Online Help</a>
+*/
+void DLL_EXPORT Wireframe(int enable);
+
+
+float DLL_EXPORT EntityScaleX(Entity* ent,int glob);
+
+float DLL_EXPORT EntityScaleY(Entity* ent,int glob);
+
+float DLL_EXPORT EntityScaleZ(Entity* ent,int glob);
+
+Shader* DLL_EXPORT LoadShader(char* ShaderName, char* VshaderFileName, char* FshaderFileName);
+
+Shader* DLL_EXPORT CreateShader(char* ShaderName, char* VshaderString, char* FshaderString);
+
+void DLL_EXPORT ShadeSurface(Surface* surf, Shader* material);
+
+void DLL_EXPORT ShadeMesh(Mesh* mesh, Shader* material);
+
+void DLL_EXPORT ShadeEntity(Entity* ent, Shader* material);
+
+void DLL_EXPORT ShaderTexture(Shader* material, Texture* tex, char* name, int index);
+
+void DLL_EXPORT SetFloat(Shader* material, char* name, float v1);
+
+void DLL_EXPORT SetFloat2(Shader* material, char* name, float v1, float v2);
+
+void DLL_EXPORT SetFloat3(Shader* material, char* name, float v1, float v2, float v3);
+
+void DLL_EXPORT SetFloat4(Shader* material, char* name, float v1, float v2, float v3, float v4);
+
+void DLL_EXPORT UseFloat(Shader* material, char* name, float* v1);
+
+void DLL_EXPORT UseFloat2(Shader* material, char* name, float* v1, float* v2);
+
+void DLL_EXPORT UseFloat3(Shader* material, char* name, float* v1, float* v2, float* v3);
+
+void DLL_EXPORT UseFloat4(Shader* material, char* name, float* v1, float* v2, float* v3, float* v4);
+
+void DLL_EXPORT SetInteger(Shader* material, char* name, int v1);
+
+void DLL_EXPORT SetInteger2(Shader* material, char* name, int v1, int v2);
+
+void DLL_EXPORT SetInteger3(Shader* material, char* name, int v1, int v2, int v3);
+
+void DLL_EXPORT SetInteger4(Shader* material, char* name, int v1, int v2, int v3, int v4);
+
+void DLL_EXPORT UseInteger(Shader* material, char* name, int* v1);
+
+void DLL_EXPORT UseInteger2(Shader* material, char* name, int* v1, int* v2);
+
+void DLL_EXPORT UseInteger3(Shader* material, char* name, int* v1, int* v2, int* v3);
+
+void DLL_EXPORT UseInteger4(Shader* material, char* name, int* v1, int* v2, int* v3, int* v4);
+
+void DLL_EXPORT UseSurface(Shader* material, char* name, Surface* surf, int vbo);
+
+void DLL_EXPORT UseMatrix(Shader* material, char* name, int mode);
+
+Material* DLL_EXPORT LoadMaterial(char* filename,int flags, int frame_width,int frame_height,int first_frame,int frame_count);
+
+void DLL_EXPORT ShaderMaterial(Shader* material, Material* tex, char* name, int index);
+
+OcTree* DLL_EXPORT CreateOcTree(float w, float h, float d, Entity* parent_ent);
+
+void DLL_EXPORT AddToOctree(OcTree* octree, Mesh* mesh, int level, float X, float Y, float Z, float Near, float Far);
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
+
+#endif

+ 24 - 26
openb3dlib.mod/openb3d/src/geosphere.cpp

@@ -4,23 +4,23 @@
  *
  *
  */
-
-#include "glew.h"
-
-/*
-#ifdef linux
-#define GL_GLEXT_PROTOTYPES
-#include <GL/gl.h>
-#include <GL/glext.h>
+#ifdef OPENB3D_GLEW
+	#include "glew.h"
+#else
+	#ifdef linux
+	#define GL_GLEXT_PROTOTYPES
+	#include <GL/gl.h>
+	#include <GL/glext.h>
+	#endif
+
+	#ifdef WIN32
+	#include <gl\GLee.h>
+	#endif
+
+	#ifdef __APPLE__
+	#include "GLee.h"
+	#endif
 #endif
-#ifdef WIN32
-#include "GLee.h"
-#endif
-#ifdef __APPLE__
-#include "GLee.h"
-#endif
-*/
-
 
 #include "global.h"
 #include "entity.h"
@@ -42,7 +42,7 @@ static float radius;
 static vector<float> vertices;
 
 
-Terrain* Geosphere::CopyEntity(Entity* parent_ent){
+Geosphere* Geosphere::CopyEntity(Entity* parent_ent){
 
 	// new terr
 	Geosphere* geo=new Geosphere;
@@ -294,7 +294,7 @@ void Geosphere::UpdateTerrain(){
 	int tex_count=0;
 
 	if(ShaderMat!=NULL){
-		ShaderMat->TurnOn(0, mat);
+		ShaderMat->TurnOn(mat, 0, &vertices);
 	}
 
 	tex_count=brush.no_texs;
@@ -306,7 +306,7 @@ void Geosphere::UpdateTerrain(){
 
 			// Main brush texture takes precedent over surface brush texture
 			unsigned int texture=0;
-			int tex_flags=0,tex_blend=0,tex_coords=0;
+			int tex_flags=0,tex_blend=0;
 			float tex_u_scale=1.0,tex_v_scale=1.0,tex_u_pos=0.0,tex_v_pos=0.0,tex_ang=0.0;
 			int tex_cube_mode=0;
 
@@ -314,7 +314,7 @@ void Geosphere::UpdateTerrain(){
 			texture=brush.cache_frame[ix];
 			tex_flags=brush.tex[ix]->flags;
 			tex_blend=brush.tex[ix]->blend;
-			tex_coords=brush.tex[ix]->coords;
+			//tex_coords=brush.tex[ix]->coords;
 			tex_u_scale=brush.tex[ix]->u_scale;
 			tex_v_scale=brush.tex[ix]->v_scale;
 			tex_u_pos=brush.tex[ix]->u_pos;
@@ -595,7 +595,7 @@ void Geosphere::RecreateGeoROAM(){
 	}
 
 
-	tmat = MQ_GetMatrix(true);
+	MQ_GetMatrix(tmat, true);
 
 
 	triangleindex = 0;
@@ -613,7 +613,6 @@ void Geosphere::RecreateGeoROAM(){
 	geosub( 0, v[1], v[4], v[8]);
 
 
-	delete tmat;
 
 
 }
@@ -657,7 +656,7 @@ void Geosphere::geosub(int l, float v2[], float v1[], float v0[]){
 		float vcx=x;
 		float vcy=y;
 		float vcz=-z;
-		tmat->TransformVec(vcx, vcy, vcz, 1);
+		tmat.TransformVec(vcx, vcy, vcz, 1);
 
 		for (int i = 0 ;i<= 5; i++){
 			float d = eyepoint->frustum[i][0] * vcx + eyepoint->frustum[i][1] * vcy - eyepoint->frustum[i][2] * vcz + eyepoint->frustum[i][3];
@@ -1197,7 +1196,7 @@ void Geosphere::TreeCheck(CollisionInfo* ci){
 	}
 
 
-	tmat = MQ_GetMatrix(true);
+	MQ_GetMatrix(tmat, true);
 
 
 
@@ -1223,7 +1222,6 @@ void Geosphere::TreeCheck(CollisionInfo* ci){
 
 	c_col_tree=C_CreateColTree(mesh_info);
 	C_DeleteMeshInfo(mesh_info);
-	delete tmat;
 
 
 
@@ -1267,7 +1265,7 @@ void Geosphere::c_col_tree_geosub(int l, float v2[], float v1[], float v0[]){
 		float vcx=x;
 		float vcy=y;
 		float vcz=-z;
-		tmat->TransformVec(vcx, vcy, vcz, 1);
+		tmat.TransformVec(vcx, vcy, vcz, 1);
 
 		/*Is triangle on the collision line?*/
 

+ 2 - 2
openb3dlib.mod/openb3d/src/geosphere.h

@@ -13,7 +13,7 @@
 
 class Geosphere : public Terrain{
 private:
-	Matrix* tmat;
+	Matrix tmat;
 	float dradius;
 	float* NormalsMap;
 	//int* EqToToast;
@@ -33,7 +33,7 @@ public:
 
 	static Geosphere* CreateGeosphere(int tsize=0, Entity* parent_ent=NULL);
 	static Geosphere* LoadGeosphere(string filename,Entity* parent_ent=NULL);
-	Terrain* CopyEntity(Entity* parent_ent=NULL);
+	Geosphere* CopyEntity(Entity* parent_ent=NULL);
 	void FreeEntity(void);
 
 	//void TreeCheck(CollisionInfo* ci);

+ 94 - 16
openb3dlib.mod/openb3d/src/metaball.cpp → openb3dlib.mod/openb3d/src/isosurface.cpp

@@ -1,15 +1,23 @@
-#include "glew.h"
-/*
-#ifdef linux
-#define GL_GLEXT_PROTOTYPES
-#include <GL/gl.h>
-#include <GL/glext.h>
-#endif
-#ifdef WIN32
-#include <gl\GLee.h>
+
+#ifdef OPENB3D_GLEW
+	#include "glew.h"
+#else
+	#ifdef linux
+	#define GL_GLEXT_PROTOTYPES
+	#include <GL/gl.h>
+	#include <GL/glext.h>
+	#endif
+
+	#ifdef WIN32
+	#include <gl\GLee.h>
+	#endif
+
+	#ifdef __APPLE__
+	#include "GLee.h"
+	#endif
 #endif
-*/
-#include "metaball.h"
+
+#include "isosurface.h"
 #include "global.h"
 #include "camera.h"
 #include "pick.h"
@@ -18,10 +26,12 @@ static float Xcf, Ycf, Zcf;
 
 static list<Blob*> render_blobs;
 
+static FieldArray* data_array;
+
 static int level;
 
 
-const int edgeTable[256]={
+/*extern*/ const int edgeTable[256]={
 0x0  , 0x109, 0x203, 0x30a, 0x406, 0x50f, 0x605, 0x70c,
 0x80c, 0x905, 0xa0f, 0xb06, 0xc0a, 0xd03, 0xe09, 0xf00,
 0x190, 0x99 , 0x393, 0x29a, 0x596, 0x49f, 0x795, 0x69c,
@@ -56,7 +66,7 @@ const int edgeTable[256]={
 0x70c, 0x605, 0x50f, 0x406, 0x30a, 0x203, 0x109, 0x0   };
 
 //gives which vertices to join to form triangles for the surface
-const int triTable[256][16] =
+extern const int triTable[256][16] =
 {{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
 {0, 8, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
 {0, 1, 9, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
@@ -335,6 +345,47 @@ float MetaballsField (float x, float y, float z){
 	return field;
 }
 
+float ArraysField (float x, float y, float z){
+
+	data_array->mat.TransformVec(x, y, z, 1);
+
+	int X,Y,Z;
+	X=(int)x;
+	Y=(int)y;
+	Z=(int)z;
+
+	int w=data_array->width;
+	int h=data_array->height;
+	int d=data_array->depth;
+	int Offset=X + Y*w + Z*w*h;
+
+	if (X<0 || X>=w) return 0;
+	if (Y<0 || Y>=h) return 0;
+	if (Z<0 || Z>=d) return 0;
+
+	float a1,a2,a3,a4,a5,a6,a7,a8;
+	a1=data_array->data[Offset];
+	a2=data_array->data[Offset + 1];
+	a3=data_array->data[Offset + w];
+	a4=data_array->data[Offset + 1 + w];
+	a5=data_array->data[Offset + w*h];
+	a6=data_array->data[Offset + 1 + w*h];
+	a7=data_array->data[Offset + w + w*h];
+	a8=data_array->data[Offset + 1 +w + w*h];
+
+
+	float i1,i2,i3,i4,i5,i6;
+
+	i1=a1+(a2-a1)*(x-X);
+	i2=a3+(a4-a3)*(x-X);
+	i3=a5+(a6-a5)*(x-X);
+	i4=a7+(a8-a7)*(x-X);
+	i5=i1+(i2-i1)*(y-Y);
+	i6=i3+(i4-i3)*(y-Y);
+
+	return i5+(i6-i5)*(z-Z);
+
+}
 
 Fluid* Fluid::CreateFluid(){
 	Fluid* fluid=new Fluid();
@@ -361,6 +412,7 @@ Fluid* Fluid::CreateFluid(){
 	fluid->ScalarField=&MetaballsField;
 
 	fluid->threshold=.5;
+	fluid->render_mode=0;
 
 	fluid->ResetBuffers();
 
@@ -402,6 +454,19 @@ void Fluid::FreeEntity(){
 
 }
 
+void Fluid::FluidFunction(float (*FieldFunction)(float, float, float)){
+	ScalarField=FieldFunction;
+}
+
+void Fluid::FluidArray(float* Array, int w, int h, int d){
+	ScalarField=&ArraysField;
+	render_mode=2;
+	fieldarray=new FieldArray;
+	fieldarray->data=Array;
+	fieldarray->width=w;
+	fieldarray->height=h;
+	fieldarray->depth=d;
+}
 
 void Fluid::MarchingCube(float x, float y, float z, float x1, float y1, float z1, float F[8]){
 
@@ -1012,7 +1077,7 @@ void Fluid::Render(){
 	surf->vert_col.clear();
 	surf->no_tris=0;
 
-	if (fastmode){
+	if (render_mode==1){
 		// Only metaballs that are in the view frustum are used to compute the scalar field
 		render_blobs.clear();
 		list<Blob*>::iterator it;
@@ -1023,8 +1088,13 @@ void Fluid::Render(){
 				render_blobs.push_back(blob);
 			}
 		}
-	}else{
+	}else if (render_mode==0){
 		render_blobs=metaball_list;
+	}else
+	{
+		//Array
+		data_array=fieldarray;
+		MQ_GetInvMatrix(fieldarray->mat, true);
 	}
 
 	level=0;
@@ -1132,7 +1202,7 @@ void Fluid::Render(){
 	int tex_count=0;
 
 	if(surf->ShaderMat!=NULL){
-		surf->ShaderMat->TurnOn(surf, mat);
+		surf->ShaderMat->TurnOn(mat, surf);
 	}else{
 
 		tex_count=brush.no_texs;
@@ -1494,3 +1564,11 @@ Blob* Blob::CopyEntity(Entity* parent_ent){
 	
 }
 
+void FieldArray::FreeEntity(){
+	delete this;
+	
+	return;
+}
+
+FieldArray* FieldArray::CopyEntity(Entity* parent_ent){ return 0;}
+

+ 88 - 0
openb3dlib.mod/openb3d/src/isosurface.h

@@ -0,0 +1,88 @@
+#ifndef METABALL_H
+#define METABALL_H
+
+#include "mesh.h"
+
+#include <iostream>
+using namespace std;
+
+class Blob;
+class FieldArray;
+
+class Fluid : public Mesh{
+friend class VoxelTerrain;
+
+private:
+	int* buffercenter;
+	float ***xzbuffer;
+	float ***xybuffer;
+	float ***yzbuffer;
+
+	void ResetBuffers();
+
+	void MarchingCube(float x, float y, float z, float x1, float y1, float z1, float F[8]);
+
+	float MiddlePoint (float A, float B, float C, float D);
+
+	void BuildCubeGrid (float x, float y, float z, float l,
+		float f1, float f2, float f3, float f4, float f5, float f6, float f7, float f8);
+
+	float (*ScalarField)(float x, float y, float z);
+public:
+	list<Blob*> metaball_list;
+
+	int render_mode;
+
+	FieldArray* fieldarray;
+
+	void FluidFunction(float (*FieldFunction)(float, float, float));
+	void FluidArray(float* Array, int w, int h, int d);
+
+	float threshold;
+
+	int* cells;
+
+	static Fluid* CreateFluid();
+
+	void FreeEntity(void);
+
+	void Render();
+
+};
+
+
+class Blob : public Entity{
+ 
+public:
+
+	float charge;
+	Fluid* fluid;
+	
+	Blob(){};
+	
+	Blob* CopyEntity(Entity* parent_ent=NULL);
+	void FreeEntity(void);
+	
+	static Blob* CreateBlob(Fluid* fluid, float radius, Entity* parent_ent=NULL);
+	void Update(){}
+ 
+ };
+
+class FieldArray : public Entity{
+ 
+public:
+
+	float* data;
+
+	int width, height, depth;
+	
+	FieldArray(){};
+	
+	FieldArray* CopyEntity(Entity* parent_ent=NULL);
+	void FreeEntity(void);
+	
+	void Update(){}
+ 
+ };
+
+#endif

+ 16 - 3
openb3dlib.mod/openb3d/src/light.cpp

@@ -107,6 +107,19 @@ Light* Light::CopyEntity(Entity* parent_ent){
 void Light::FreeEntity(){
 
 	Entity::FreeEntity();
+
+	int erased=0;
+
+	for (int i=0; i<no_lights;i++){
+		glDisable(gl_light[i]);
+		if (!erased && light_list[i]==this){
+			light_list.erase(light_list.begin()+i);
+			erased=1;
+		}
+	}
+
+	no_lights=no_lights-1;
+
 	
 	delete this;
 	
@@ -116,12 +129,12 @@ void Light::FreeEntity(){
 
 Light* Light::CreateLight(int l_type,Entity* parent_ent){
 
+	if(no_lights>=max_lights) return NULL; // no more lights available, return and don't create
+
 	Light* light=new Light;
 	light->light_type=l_type;
 	light->class_name="Light";
-		
-	if(no_lights>=max_lights) return NULL; // no more lights available, return and gc will collect create light
-		
+	
 	// no of lights increased, enable additional gl light
 	no_lights=no_lights+1;
 	glEnable(gl_light[no_lights-1]);

+ 59 - 65
openb3dlib.mod/openb3d/src/makefile

@@ -1,157 +1,151 @@
-CC = g++
-CFLAGS = -Wall -O3 -m32
+CCMPILER = g++
+CC=g++ -Wall -O3 
 
-OBJECTS = model.o string_helper.o surface.o bank.o bone.o brush.o collision.o entity.o functions.o geom.o global.o light.o matrix.o pick.o pivot.o project.o sprite.o tilt.o touch.o texture_filter.o tree.o animation.o animation_keys.o collision2.o maths_helper.o quaternion.o sprite_batch.o camera.o file.o mesh.o texture.o terrain.o stb_image.o 3ds.o collidetri.o shadow.o material.o stencil.o csg.o voxel.o x.o octree.o geosphere.o
+OBJECTS = model.o string_helper.o surface.o bank.o bone.o brush.o collision.o entity.o functions.o geom.o global.o light.o matrix.o pick.o pivot.o project.o sprite.o tilt.o touch.o texture_filter.o tree.o animation.o animation_keys.o collision2.o maths_helper.o quaternion.o sprite_batch.o camera.o file.o mesh.o texture.o terrain.o stb_image.o 3ds.o collidetri.o shadow.o material.o stencil.o csg.o voxel.o x.o octree.o geosphere.o md2.o isosurface.o particle.o
 
 main:$(OBJECTS) 
 ifeq ($(shell uname), Linux)
-	$(CC) $(CFLAGS) -shared -o libOpenB3D.so $(OBJECTS)  -lGL -lGLU
-endif
-ifeq ($(shell uname), Darwin)
-	$(CC) $(CFLAGS) -shared -o libopenb3d.dylib $(OBJECTS)  GLee.o -framework CoreFoundation -framework OpenGL
-endif
-ifeq "$(OS)" "Windows_NT"
-	$(CC) $(CFLAGS) -shared -o openb3d.dll $(OBJECTS)  GLee.o -lopengl32 -lglu32 -lGDI32
+	$(CC) -shared -o libOpenB3D.so $(OBJECTS)  -lGL -lGLU
+else
+	$(CC) -shared -o openb3d.dll $(OBJECTS)  -lGLee -lopengl32 -lglu32 -lGDI32
 endif
 
 
 3ds.o  : 3ds.cpp 3ds.h
-	$(CC) $(CFLAGS) -c 3ds.cpp -o 3ds.o
+	$(CC) -c 3ds.cpp -o 3ds.o
+
+md2.o  : md2.cpp md2.h
+	$(CC) -c md2.cpp -o md2.o
 
 bank.o : bank.cpp bank.h
-	$(CC) $(CFLAGS) -c bank.cpp -o bank.o
+	$(CC) -c bank.cpp -o bank.o
 
 bone.o : bone.cpp bone.h
-	$(CC) $(CFLAGS) -c bone.cpp -o bone.o
+	$(CC) -c bone.cpp -o bone.o
 
 brush.o : brush.cpp brush.h
-	$(CC) $(CFLAGS) -c brush.cpp -o brush.o
+	$(CC) -c brush.cpp -o brush.o
 
 camera.o : camera.cpp camera.h
-	$(CC) $(CFLAGS) -c camera.cpp -o camera.o
+	$(CC) -c camera.cpp -o camera.o
 
 collision.o : collision.cpp collision.h
-	$(CC) $(CFLAGS) -c collision.cpp -o collision.o
+	$(CC) -c collision.cpp -o collision.o
 
 entity.o : entity.cpp entity.h
-	$(CC) $(CFLAGS) -c entity.cpp -o entity.o
+	$(CC) -c entity.cpp -o entity.o
 
 file.o : file.cpp file.h
-	$(CC) $(CFLAGS) -c file.cpp -o file.o
+	$(CC) -c file.cpp -o file.o
 
 functions.o : functions.cpp
-	$(CC) $(CFLAGS) -c functions.cpp -o functions.o	
+	$(CC) -c functions.cpp -o functions.o	
 
 geom.o : geom.cpp geom.h
-	$(CC) $(CFLAGS) -c geom.cpp -o geom.o
-	
+	$(CC) -c geom.cpp -o geom.o
+
 geosphere.o : geosphere.cpp geosphere.h
-	$(CC) $(CFLAGS) -c geosphere.cpp -o geosphere.o
+	$(CC) -c geosphere.cpp -o geosphere.o
 
 global.o : global.cpp global.h
-	$(CC) $(CFLAGS) -c global.cpp -o global.o
+	$(CC) -c global.cpp -o global.o
 
 light.o : light.cpp light.h
-	$(CC) $(CFLAGS) -c light.cpp -o light.o
+	$(CC) -c light.cpp -o light.o
 
 matrix.o : matrix.cpp matrix.h
-	$(CC) $(CFLAGS) -c matrix.cpp -o matrix.o
+	$(CC) -c matrix.cpp -o matrix.o
 
 mesh.o : mesh.cpp mesh.h
-	$(CC) $(CFLAGS) -c mesh.cpp -o mesh.o
+	$(CC) -c mesh.cpp -o mesh.o
 
 model.o : model.cpp model.h
-	$(CC) $(CFLAGS) -c model.cpp -o model.o
+	$(CC) -c model.cpp -o model.o
 
 pick.o : pick.cpp pick.h
-	$(CC) $(CFLAGS) -c pick.cpp -o pick.o
+	$(CC) -c pick.cpp -o pick.o
 
 pivot.o : pivot.cpp pivot.h
-	$(CC) $(CFLAGS) -c pivot.cpp -o pivot.o
+	$(CC) -c pivot.cpp -o pivot.o
 
 project.o : project.cpp project.h
-	$(CC) $(CFLAGS) -c project.cpp -o project.o
+	$(CC) -c project.cpp -o project.o
 
 sprite.o : sprite.cpp sprite.h
-	$(CC) $(CFLAGS) -c sprite.cpp -o sprite.o
+	$(CC) -c sprite.cpp -o sprite.o
 
 surface.o : surface.cpp surface.h
-	$(CC) $(CFLAGS) -c surface.cpp -o surface.o
+	$(CC) -c surface.cpp -o surface.o
 
 terrain.o : terrain.cpp terrain.h stb_image.c
-	$(CC) $(CFLAGS) -c terrain.cpp -o terrain.o
+	$(CC) -c terrain.cpp -o terrain.o
 
 texture.o : texture.cpp texture.h stb_image.c
-	$(CC) $(CFLAGS) -c texture.cpp -o texture.o
+	$(CC) -c texture.cpp -o texture.o
 
 tilt.o : tilt.cpp tilt.h
-	$(CC) $(CFLAGS) -c tilt.cpp -o tilt.o
+	$(CC) -c tilt.cpp -o tilt.o
 
 touch.o : touch.cpp touch.h
-	$(CC) $(CFLAGS) -c touch.cpp -o touch.o
+	$(CC) -c touch.cpp -o touch.o
 
 string_helper.o : string_helper.cpp string_helper.h
-	$(CC) $(CFLAGS) -c string_helper.cpp -o string_helper.o
+	$(CC) -c string_helper.cpp -o string_helper.o
 
 texture_filter.o : texture_filter.cpp texture_filter.h
-	$(CC) $(CFLAGS) -c texture_filter.cpp -o texture_filter.o
+	$(CC) -c texture_filter.cpp -o texture_filter.o
 
 tree.o : tree.cpp tree.h
-	$(CC) $(CFLAGS) -c tree.cpp -o tree.o
+	$(CC) -c tree.cpp -o tree.o
 
 animation.o : animation.cpp animation.h
-	$(CC) $(CFLAGS) -c animation.cpp -o animation.o
+	$(CC) -c animation.cpp -o animation.o
 
 animation_keys.o : animation_keys.cpp animation_keys.h
-	$(CC) $(CFLAGS) -c animation_keys.cpp -o animation_keys.o
+	$(CC) -c animation_keys.cpp -o animation_keys.o
 
 collision2.o : collision2.cpp collision2.h
-	$(CC) $(CFLAGS) -c collision2.cpp -o collision2.o
+	$(CC) -c collision2.cpp -o collision2.o
 
 material.o : material.cpp 
-	$(CC) $(CFLAGS) -c material.cpp -o material.o
+	$(CC) -c material.cpp -o material.o
 
 maths_helper.o : maths_helper.cpp maths_helper.h
-	$(CC) $(CFLAGS) -c maths_helper.cpp -o maths_helper.o
+	$(CC) -c maths_helper.cpp -o maths_helper.o
+
+particle.o : particle.cpp particle.h
+	$(CC) -c particle.cpp -o particle.o
 
 quaternion.o : quaternion.cpp quaternion.h
-	$(CC) $(CFLAGS) -c quaternion.cpp -o quaternion.o
+	$(CC) -c quaternion.cpp -o quaternion.o
 
 shadow.o : shadow.cpp shadow.h
-	$(CC) $(CFLAGS) -c shadow.cpp -o shadow.o
+	$(CC) -c shadow.cpp -o shadow.o
 
 sprite_batch.o : sprite_batch.cpp sprite_batch.h
-	$(CC) $(CFLAGS) -c sprite_batch.cpp -o sprite_batch.o
+	$(CC) -c sprite_batch.cpp -o sprite_batch.o
 
 stb_image.o	: stb_image.c
-	gcc $(CFLAGS) -c stb_image.c -o stb_image.o
+	gcc -c stb_image.c -o stb_image.o
 
 stencil.o : stencil.cpp stencil.h
-	$(CC) $(CFLAGS) -c stencil.cpp -o stencil.o
+	$(CC) -c stencil.cpp -o stencil.o
 
 csg.o : csg.cpp csg.h
-	$(CC) $(CFLAGS) -c csg.cpp -o csg.o
+	$(CC) -c csg.cpp -o csg.o
+
+isosurface.o : isosurface.cpp isosurface.h
+	$(CC) -c isosurface.cpp -o isosurface.o
 
 octree.o : octree.cpp octree.h
-	$(CC) $(CFLAGS) -c octree.cpp -o octree.o
+	$(CC) -c octree.cpp -o octree.o
 
 voxel.o : voxel.cpp voxel.h
-	$(CC) $(CFLAGS) -c voxel.cpp -o voxel.o
+	$(CC) -c voxel.cpp -o voxel.o
 
 x.o : x.cpp x.h
-	$(CC) $(CFLAGS) -c x.cpp -o x.o
+	$(CC) -c x.cpp -o x.o
 
 collidetri.o	: collidetri.c
-	gcc $(CFLAGS) -c collidetri.c -o collidetri.o
-
-
-glee: GLee.o
-	gcc $(CFLAGS) -c GLee.c -o GLee.o
+	gcc -c collidetri.c -o collidetri.o
 
-
-clean:
-ifeq "$(OS)" "Windows_NT"
-	del $(OBJECTS) openb3d.dll libopenb3d.dylib libOpenB3D.so
-else
-	rm -rf $(OBJECTS) openb3d.dll libopenb3d.dylib libOpenB3D.so
-endif

+ 151 - 101
openb3dlib.mod/openb3d/src/material.cpp

@@ -1,24 +1,27 @@
 #include <iostream>
 #include <string>
-;
 
-#include "glew.h"
-/*
-#ifdef linux
-#define GL_GLEXT_PROTOTYPES
-#include <GL/gl.h>
-#include <GL/glext.h>
-#include <GL/glu.h>
-#endif
-#ifdef WIN32
-#include "GLee.h"
-#include <GL\glu.h>
+#ifdef OPENB3D_GLEW
+	#include "glew.h"
+#else
+	#ifdef linux
+	#define GL_GLEXT_PROTOTYPES
+	#include <GL/gl.h>
+	#include <GL/glext.h>
+	#include <GL/glu.h>
+	#endif
+
+	#ifdef WIN32
+	#include <gl\GLee.h>
+	#include <GL\glu.h>
+	#endif
+
+	#ifdef __APPLE__
+	#include "GLee.h"
+	#include <OpenGL/glu.h>
+	#endif
 #endif
-#ifdef __APPLE__
-#include "GLee.h"
-#include <OpenGL/glu.h>
-#endif
-*/
+
 #include "surface.h"
 #include "camera.h"
 #include "shadermat.h"
@@ -32,13 +35,6 @@ list<ProgramObject*> ProgramObject::ProgramObjectList;
 int Shader::ShaderIDCount;
 
 
-/*ShaderObject* ShaderObject::CreateVertShader(string shaderFileName);
-ShaderObject* ShaderObject::CreateFragShader(string shaderFileName);
-ShaderObject* ShaderObject::CreateVertShaderFromString(string shadercode);
-ShaderObject* ShaderObject::CreateFragShaderFromString(string shadercode);
-*/
-
-
 ShaderObject* ShaderObject::CreateVertShader(string shaderFileName){
 	// Load the shader and dump it into a Byte Array
 	File* file=File::ReadFile(shaderFileName); // opens as ASCII!
@@ -46,48 +42,37 @@ ShaderObject* ShaderObject::CreateVertShader(string shaderFileName){
 		return 0;
 	}
 
-/*	unsigned long pos=file.tellg();
-	file.seekg(0,ios::end);
-	unsigned long FileLength = file.tellg();
-	file.seekg(ios::beg);
-*/	
 	fseek(file->pFile, 0L, SEEK_END);
 	unsigned long FileLength = ftell(file->pFile);
 	fseek(file->pFile, 0L, SEEK_SET);
+	// wrong size "void main(){}"
+	if (FileLength<13){
+		file->CloseFile();
+		return 0;
+	}
+	char* shaderSrc = new char[FileLength+1];
+	// out of memory
+	if (shaderSrc == 0) {
+		file->CloseFile();
+		return 0;
+	}
 
-	//int ShaderObject;
-	ShaderObject* myShader = new ShaderObject;
-	
-	myShader->ShaderObj = glCreateShader(GL_VERTEX_SHADER);
-	myShader->ShaderType = 1; // 1 = Vert, 2 = Frag/Pixel
-
-	char* shaderSrc;
-
-	shaderSrc = new char[FileLength+1];
-	if (shaderSrc == 0) return 0;   // can't reserve memory
-   
 	// FileLength isn't always strlen cause some characters are stripped in ascii read...
-	// it is important to 0-terminate the real length later, len is just max possible value... 
-	shaderSrc[FileLength] = 0; 
-
+	// it is important to 0-terminate the real length later, len is just max possible value...
+	shaderSrc[FileLength] = 0;
 	unsigned int i=0;
-	while (!file->Eof())
-	{
+	while (!file->Eof()){
 		shaderSrc[i] = file->ReadByte();       // get character from file.
 		i++;
 	}
-    
 	shaderSrc[i] = 0;  // 0-terminate it at the correct position
-    
 	file->CloseFile();
 
-
+	//int ShaderObject;
+	ShaderObject* myShader = new ShaderObject;
 	
-	int shaderLen[1];
-	shaderLen[0] = i;
-
-	//Local shaderPtr:Byte Ptr[1]
-	//shaderPtr[0] = Varptr(shaderSrc[0])
+	myShader->ShaderObj = glCreateShader(GL_VERTEX_SHADER);
+	myShader->ShaderType = 1; // 1 = Vert, 2 = Frag/Pixel
 
 	// Send shader to ShaderObject, then compile it
 	glShaderSource(myShader->ShaderObj,1, (const GLchar**)&shaderSrc, 0);
@@ -98,14 +83,16 @@ ShaderObject* ShaderObject::CreateVertShader(string shaderFileName){
 	glGetShaderiv(myShader->ShaderObj,GL_COMPILE_STATUS, &compiled);
 
 	if (!compiled){
+		delete [] shaderSrc;
 		delete myShader;
 		return 0;
-		}
+	}
 
 
 	//myShader.Attached = New TList
 	myShader->shaderName = shaderFileName;
 	ShaderObject::ShaderObjectList.push_back(myShader);
+	delete [] shaderSrc;
 	
 	return myShader;
 }
@@ -127,53 +114,41 @@ ShaderObject* ShaderObject::CreateVertShader(string shaderFileName){
 ShaderObject* ShaderObject::CreateFragShader(string shaderFileName){
 	// Load the shader and dump it into a Byte Array
 	File* file=File::ReadFile(shaderFileName); // opens as ASCII!
-
 	if(file==0) {
 		return 0;
 	}
 
-/*	unsigned long pos=file.tellg();
-	file.seekg(0,ios::end);
-	unsigned long FileLength = file.tellg();
-	file.seekg(ios::beg);
-*/	
 	fseek(file->pFile, 0L, SEEK_END);
 	unsigned long FileLength = ftell(file->pFile);
 	fseek(file->pFile, 0L, SEEK_SET);
+	// wrong size "void main(){}"
+	if (FileLength<13){
+		file->CloseFile();
+		return 0;
+	}
+	char* shaderSrc = new char[FileLength+1];
+	// out of memory
+	if (shaderSrc == 0) {
+		file->CloseFile();
+		return 0;
+	}
 
-	//int ShaderObject;
-	ShaderObject* myShader = new ShaderObject;
-	
-	myShader->ShaderObj = glCreateShader(GL_FRAGMENT_SHADER);
-	myShader->ShaderType = 2; // 1 = Vert, 2 = Frag/Pixel
-
-	char* shaderSrc;
-
-	shaderSrc = new char[FileLength+1];
-	if (shaderSrc == 0) return 0;   // can't reserve memory
-   
 	// FileLength isn't always strlen cause some characters are stripped in ascii read...
-	// it is important to 0-terminate the real length later, len is just max possible value... 
-	shaderSrc[FileLength] = 0; 
-
+	// it is important to 0-terminate the real length later, len is just max possible value...
+	shaderSrc[FileLength] = 0;
 	unsigned int i=0;
-	while (!file->Eof())
-	{
+	while (!file->Eof()){
 		shaderSrc[i] = file->ReadByte();       // get character from file.
 		i++;
 	}
-    
 	shaderSrc[i] = 0;  // 0-terminate it at the correct position
-    
 	file->CloseFile();
 
-
+	//int ShaderObject;
+	ShaderObject* myShader = new ShaderObject;
 	
-	int shaderLen[1];
-	shaderLen[0] = i;
-
-	//Local shaderPtr:Byte Ptr[1]
-	//shaderPtr[0] = Varptr(shaderSrc[0])
+	myShader->ShaderObj = glCreateShader(GL_FRAGMENT_SHADER);
+	myShader->ShaderType = 2; // 1 = Vert, 2 = Frag/Pixel
 
 	// Send shader to ShaderObject, then compile it
 	glShaderSource(myShader->ShaderObj,1, (const GLchar**)&shaderSrc, 0);
@@ -184,14 +159,17 @@ ShaderObject* ShaderObject::CreateFragShader(string shaderFileName){
 	glGetShaderiv(myShader->ShaderObj,GL_COMPILE_STATUS, &compiled);
 
 	if (!compiled){
+		delete [] shaderSrc;
 		delete myShader;
 		return 0;
-		}
+	}
 
 
 	//myShader.Attached = New TList
 	myShader->shaderName = shaderFileName;
 	ShaderObject::ShaderObjectList.push_back(myShader);
+	delete [] shaderSrc;
+	
 	return myShader;
 }
 /*
@@ -212,7 +190,11 @@ ShaderObject* ShaderObject::CreateVertShaderFromString(string shadercode){
 	
 	//Local tempShaderName:String = "Code"+Rand(10000)
 	unsigned int FileLength = shadercode.size();
-	//int ShaderObject;
+	// wrong size "void main(){}"
+	if (FileLength<13){
+		return 0;
+	}
+
 	ShaderObject* myShader = new ShaderObject;
 	
 	myShader->ShaderObj = glCreateShader(GL_VERTEX_SHADER);
@@ -248,14 +230,16 @@ ShaderObject* ShaderObject::CreateVertShaderFromString(string shadercode){
 	glGetShaderiv(myShader->ShaderObj,GL_COMPILE_STATUS, &compiled);
 
 	if (!compiled){
+		delete [] shaderSrc;
 		delete myShader;
 		return 0;
-		}
+	}
 
 
 	//myShader.Attached = New TList
 	//myShader->shaderName = shaderFileName;
 	ShaderObject::ShaderObjectList.push_back(myShader);
+	delete [] shaderSrc;
 	
 	return myShader;
 }
@@ -277,6 +261,10 @@ ShaderObject* ShaderObject::CreateFragShaderFromString(string shadercode){
 	
 	//Local tempShaderName:String = "Code"+Rand(10000)
 	unsigned int FileLength = shadercode.size();
+	// wrong size "void main(){}"
+	if (FileLength<13){
+		return 0;
+	}
 	//int ShaderObject;
 	ShaderObject* myShader = new ShaderObject;
 	
@@ -313,14 +301,16 @@ ShaderObject* ShaderObject::CreateFragShaderFromString(string shadercode){
 	glGetShaderiv(myShader->ShaderObj,GL_COMPILE_STATUS, &compiled);
 
 	if (!compiled){
+		delete [] shaderSrc;
 		delete myShader;
 		return 0;
-		}
+	}
 
 
 	//myShader.Attached = New TList
 	//myShader->shaderName = shaderFileName;
 	ShaderObject::ShaderObjectList.push_back(myShader);
+	delete [] shaderSrc;
 	
 	return myShader;
 }
@@ -462,7 +452,7 @@ Shader* Shader::CreateShaderMaterial(string Name){
 }
 	*/
 // internal 
-void Shader::TurnOn(Surface* surf, Matrix& mat){
+void Shader::TurnOn(Matrix& mat, Surface* surf, vector<float>* vertices){
 	ProgramAttriBegin();
 	// Update Data
 
@@ -503,21 +493,44 @@ void Shader::TurnOn(Surface* surf, Matrix& mat){
 			Parameters[i].ent->EntityZ());}
 			break;
 		case 13:
-			if (arb_program !=0){arb_program->SetParameterArray(Parameters[i].name,Parameters[i].surf,Parameters[i].vbo);}
+			if (arb_program !=0){
+				if(Parameters[i].surf!=0){
+					arb_program->SetParameterArray(Parameters[i].name,Parameters[i].surf,Parameters[i].vbo);
+				}else{
+					if (surf!=0){
+						arb_program->SetParameterArray(Parameters[i].name,surf,Parameters[i].vbo);
+					}else{
+						arb_program->SetParameterArray(Parameters[i].name,vertices,Parameters[i].vbo);
+					}
+				}
+			}
 			break;
 		case 14:
 			if (arb_program !=0){
-				Matrix new_mat=Global::camera_in_use->mat.Inverse();
-				new_mat.Multiply(mat);
+				arb_program->SetMatrix4F(Parameters[i].name, &mat.grid[0][0]);
+			}
+			break;
+		case 15:
+			if (arb_program !=0){
+				Matrix new_mat;
+				Global::camera_in_use->mat.GetInverse(new_mat);
 				arb_program->SetMatrix4F(Parameters[i].name, &new_mat.grid[0][0]);
 			}
 			break;
 
-		case 15:
+		case 16:
 			if (arb_program !=0){
 				arb_program->SetMatrix4F(Parameters[i].name, &Global::camera_in_use->proj_mat[0]);
 			}
 			break;
+		case 17:
+			if (arb_program !=0){
+				Matrix new_mat;
+				Global::camera_in_use->mat.GetInverse(new_mat);
+				new_mat.Multiply(mat);
+				arb_program->SetMatrix4F(Parameters[i].name, &new_mat.grid[0][0]);
+			}
+			break;
 
 
 		//default:
@@ -837,12 +850,16 @@ void Shader::AddShader(string _vert, string _frag){
 	
 	if (_vert != ""){
 		Vert = ShaderObject::CreateVertShader(_vert);
-		arb_program->AttachVertShader(Vert);
+		if (Vert!=0) {
+			arb_program->AttachVertShader(Vert);
+		}
 	}
 		
 	if (_frag != ""){
 		Frag = ShaderObject::CreateFragShader(_frag);
-		arb_program->AttachFragShader(Frag);
+		if (Frag!=0) {
+			arb_program->AttachFragShader(Frag);
+		}
 	}
 }
 	
@@ -853,12 +870,16 @@ void Shader::AddShaderFromString(string _vert, string _frag){
 		
 	if (_vert != ""){
 		Vert = ShaderObject::CreateVertShaderFromString(_vert);
-		arb_program->AttachVertShader(Vert);
+		if (Vert!=0) {
+			arb_program->AttachVertShader(Vert);
+		}
 	}
 		
 	if (_frag != ""){
 		Frag = ShaderObject::CreateFragShaderFromString(_frag);
-		arb_program->AttachFragShader(Frag);
+		if (Frag!=0) {
+			arb_program->AttachFragShader(Frag);
+		}
 	}
 }
 
@@ -1030,10 +1051,14 @@ void Shader::UseSurface(string name, Surface* surf, int vbo){
 void Shader::UseMatrix(string name, int mode){
 	ShaderData data;
 	data.name=name;
-	if (mode==1) {
+	if (mode==0) {		//model matrix
 		data.type=14;
-	}else{
+	}else if(mode==1){	//view matrix
 		data.type=15;
+	}else if(mode==2){	//projection matrix
+		data.type=16;
+	}else if(mode==3){	//modelview matrix
+		data.type=17;
 	}
 	Parameters.push_back(data);
 }
@@ -1164,6 +1189,7 @@ ProgramObject* ProgramObject::Create(string name){
 	//Create a new GL ProgramObject
 	p->Program = glCreateProgram();
 	if (p->Program == 0){
+		delete p;
 		p = 0;
 		return 0;
 	}
@@ -1337,6 +1363,7 @@ void ProgramObject::SetParameter4D(string name, double v1, double v2, double v3,
 
 void ProgramObject::SetParameterArray(string name, Surface* surf, int vbo){
 	int loc= glGetAttribLocation(Program, name.c_str());
+
 	if(surf->vbo_enabled!=0){
 		surf->reset_vbo=vbo;
 
@@ -1350,7 +1377,7 @@ void ProgramObject::SetParameterArray(string name, Surface* surf, int vbo){
 		case 2:
 			glBindBuffer(GL_ARRAY_BUFFER,surf2.vbo_id[1]);
 			glVertexAttribPointer(loc, 2, GL_FLOAT, GL_FALSE, 0, 0);
-
+			break;
 		case 3:
 			glBindBuffer(GL_ARRAY_BUFFER,surf2.vbo_id[2]);
 			glVertexAttribPointer(loc, 2, GL_FLOAT, GL_FALSE, 0, 0);
@@ -1399,6 +1426,29 @@ void ProgramObject::SetParameterArray(string name, Surface* surf, int vbo){
 	glEnableVertexAttribArray(loc);
 }
 
+void ProgramObject::SetParameterArray(string name, vector<float>* verticesPtr, int vbo){
+	vector<float>&vertices=*verticesPtr;
+	int loc= glGetAttribLocation(Program, name.c_str());
+
+	//special case, terrain surface
+	glBindBuffer(GL_ARRAY_BUFFER,0);
+	switch (vbo){
+	case 1:
+		glVertexAttribPointer(loc, 3, GL_FLOAT, GL_FALSE, 32, &vertices[0]);
+		break;
+	case 2:
+	case 3:
+		glVertexAttribPointer(loc, 2, GL_FLOAT, GL_FALSE, 32, &vertices[6]);
+		break;
+	case 4:
+		glVertexAttribPointer(loc, 3, GL_FLOAT, GL_FALSE, 32, &vertices[3]);
+		break;
+	}
+	glEnableVertexAttribArray(loc);
+	return;
+}
+
+
 //-------------------------------------------------------------------------------------
 // Float Parameter
 
@@ -1648,7 +1698,7 @@ void CopyPixels (unsigned char *src, unsigned int srcWidth, unsigned int srcHeig
 
 Material* Material::LoadMaterial(string filename,int flags, int frame_width,int frame_height,int first_frame,int frame_count){
 
-	//filename=Strip(filename); // get rid of path info
+	filename=Strip(filename); // get rid of path info
 
 	if(File::ResourceFilePath(filename)==""){
 		cout << "Error: Cannot Find Texture: " << filename << endl;

+ 9 - 7
openb3dlib.mod/openb3d/src/matrix.cpp

@@ -36,15 +36,17 @@ void Quaternion_MultiplyQuat( float x1, float y1, float z1, float w1, float x2,
 	
 }
 
-Matrix* InterpolateMatrix(Matrix* a, float alpha){
+void InterpolateMatrix(Matrix &m, Matrix &a, float alpha){
 
-	Matrix* m=new Matrix();
-	m->LoadIdentity();
+	m.LoadIdentity();
 	float q1_x, q1_y, q1_z, q1_w;
 	float dd;
 	
-	a->ToQuat(q1_x, q1_y, q1_z, q1_w);
-	if (q1_w == 0) return a->Copy();
+	a.ToQuat(q1_x, q1_y, q1_z, q1_w);
+	if (q1_w == 0) {
+		m.Overwrite(a);
+		return;
+	}
 
 	//normalize
 	if (q1_w > 1) {
@@ -75,8 +77,8 @@ Matrix* InterpolateMatrix(Matrix* a, float alpha){
 
 	angle = angle * alpha;
 	Quaternion_FromAngleAxis(angle, x,y,z, q1_x, q1_y, q1_z, q1_w);
-	m->FromQuaternion(q1_x, q1_y, q1_z, q1_w);
+	m.FromQuaternion(q1_x, q1_y, q1_z, q1_w);
 	
-	return m;
+	return;
 	
 }

+ 2 - 4
openb3dlib.mod/openb3d/src/matrix.h

@@ -102,9 +102,7 @@ public:
 
 	}
 
-	Matrix Inverse(){
-
-		Matrix mat;
+	Matrix GetInverse(Matrix &mat){
 
 		float tx=0;
 		float ty=0;
@@ -607,6 +605,6 @@ public:
 
 void Quaternion_FromAngleAxis( float angle, float ax, float ay, float az, float &rx, float &ry, float &rz, float &rw);
 void Quaternion_MultiplyQuat( float x1, float y1, float z1, float w1, float x2, float y2, float z2, float w2, float &rx, float &ry, float &rz, float &rw );
-Matrix* InterpolateMatrix(Matrix* a, float alpha);
+void InterpolateMatrix(Matrix &m, Matrix &a, float alpha);
 #endif
 

+ 12 - 6
openb3dlib.mod/openb3d/src/md2.cpp

@@ -186,19 +186,25 @@ Mesh* LoadMD2(string filename,Entity* parent_ent){
 	Surface* surf = mesh->CreateSurface();
 
 	int skinwidth=Stream->ReadInt(); int skinheight=Stream->ReadInt();
-	int framesize=Stream->ReadInt();
-	int num_skins=Stream->ReadInt();
+	//int framesize=
+	Stream->ReadInt();
+	//int num_skins=
+	Stream->ReadInt();
 	int num_vertices=Stream->ReadInt();
 	int num_st=Stream->ReadInt();
 	int num_tris=Stream->ReadInt();
-	int num_glcmds=Stream->ReadInt();
+	//int num_glcmds=
+	Stream->ReadInt();
 	int num_frames=Stream->ReadInt();
-	int offset_skins=Stream->ReadInt();
+	//int offset_skins=
+	Stream->ReadInt();
 	int offset_st=Stream->ReadInt();
 	int offset_tris=Stream->ReadInt();
 	int offset_frames=Stream->ReadInt();
-	int offset_glcmds=Stream->ReadInt();
-	int offset_end=Stream->ReadInt();
+	//int offset_glcmds=
+	Stream->ReadInt();
+	//int offset_end=
+	Stream->ReadInt();
 	//string skin[num_skins];
 	float* st=new float[num_st*2];
 	surf->vert_tex_coords0.reserve(num_vertices*2);

+ 113 - 16
openb3dlib.mod/openb3d/src/mesh.cpp

@@ -7,21 +7,24 @@
  *
  */
 
-#include "glew.h"
-/*
-#ifdef linux
-#define GL_GLEXT_PROTOTYPES
-#include <GL/gl.h>
-#include <GL/glext.h>
+#ifdef OPENB3D_GLEW
+	#include "glew.h"
+#else
+	#ifdef linux
+	#define GL_GLEXT_PROTOTYPES
+	#include <GL/gl.h>
+	#include <GL/glext.h>
+	#endif
+
+	#ifdef WIN32
+	#include <gl\GLee.h>
+	#endif
+
+	#ifdef __APPLE__
+	#include "GLee.h"
+	#endif
 #endif
 
-#ifdef WIN32
-#include "GLee.h"
-#endif
-#ifdef __APPLE__
-#include "GLee.h"
-#endif
-*/
 #include "mesh.h"
 
 #include "global.h"
@@ -223,7 +226,7 @@ Mesh* Mesh::CopyEntity(Entity* parent_ent){
 
 	mesh->reset_bounds=reset_bounds;
 
-	mesh->no_bones=no_bones;
+	//mesh->no_bones=no_bones;
 	CopyBonesList(mesh,mesh->bones);
 
 	return mesh;
@@ -309,6 +312,68 @@ Surface* Mesh::CreateSurface(Brush* bru){
 
 }
 
+Bone* Mesh::CreateBone(Entity* parent_ent){
+	// new bone
+	Bone* bone=new Bone;
+
+	bones.push_back(bone);
+	bone->class_name="Bone";
+	bone->keys=new AnimationKeys();
+	
+	// add parent, add to list
+	bone->AddParent(*parent_ent);
+	entity_list.push_back(bone);
+	
+	// update matrix
+	if(bone->parent){
+		bone->mat.Overwrite(bone->parent->mat);
+	}else{
+		bone->mat.LoadIdentity();
+	}
+
+	if (anim==false){
+		anim=1;
+		anim_render=true;
+
+		anim_seqs_first[0]=0;
+		anim_seqs_last[0]=0;
+
+		// create anim surfs, copy vertex coords array, add to anim_surf_list
+
+		list<Surface*>::iterator it;
+
+
+		for(it=surf_list.begin();it!=surf_list.end();it++){
+			Surface& surf=**it;
+
+			Surface* anim_surf=new Surface();
+
+			anim_surf_list.push_back(anim_surf);
+			anim_surf->no_verts=surf.no_verts;
+
+			//First frame
+			anim_surf->vert_coords=surf.vert_coords;
+
+			anim_surf->vert_bone1_no.resize(surf.no_verts+1);
+			anim_surf->vert_bone2_no.resize(surf.no_verts+1);
+			anim_surf->vert_bone3_no.resize(surf.no_verts+1);
+			anim_surf->vert_bone4_no.resize(surf.no_verts+1);
+			anim_surf->vert_weight1.resize(surf.no_verts+1);
+			anim_surf->vert_weight2.resize(surf.no_verts+1);
+			anim_surf->vert_weight3.resize(surf.no_verts+1);
+			anim_surf->vert_weight4.resize(surf.no_verts+1);
+
+			// transfer vmin/vmax values for using with TrimVerts func after
+			anim_surf->vmin=surf.vmin;
+			anim_surf->vmax=surf.vmax;
+		}
+	}
+
+
+	return bone;
+}
+
+
 Mesh* Mesh::LoadMesh(string filename,Entity* parent_ent){
 
 	if(Right(filename,4)==".3ds") return load3ds::Load3ds(filename, parent_ent);//filename=Replace(filename,".3ds",".b3d");
@@ -1042,7 +1107,7 @@ Mesh* Mesh::RepeatMesh(Entity* parent_ent){
 
 	mesh->reset_bounds=reset_bounds;
 
-	mesh->no_bones=0;
+	//mesh->no_bones=0;
 
 	//CopyBonesList(mesh,mesh->bones);
 
@@ -1635,6 +1700,38 @@ Surface* Mesh::GetSurface(int surf_no_get){
 
 }
 
+void Mesh::SkinMesh(int surf_no_get, int vid, int bone1, float weight1, int bone2, float weight2, int bone3, float weight3, int bone4, float weight4){
+
+	int surf_no=0;
+
+	list<Surface*>::iterator it;
+
+	Surface* anim_surf=0;
+
+	for(it=anim_surf_list.begin();it!=anim_surf_list.end();it++){
+
+		anim_surf=*it;
+
+		surf_no=surf_no+1;
+
+		if(surf_no_get==surf_no) break;
+
+	}
+
+	anim_surf->vert_bone1_no[vid]=bone1;
+	anim_surf->vert_weight1[vid]=weight1;
+
+	anim_surf->vert_bone2_no[vid]=bone2;
+	anim_surf->vert_weight2[vid]=weight2;
+
+	anim_surf->vert_bone3_no[vid]=bone3;
+	anim_surf->vert_weight3[vid]=weight3;
+
+	anim_surf->vert_bone4_no[vid]=bone4;
+	anim_surf->vert_weight4[vid]=weight4;
+
+
+}
 /*
 	Method FindSurface:TSurface(brush:TBrush)
 
@@ -2340,7 +2437,7 @@ void Mesh::Render(){
 		int tex_count=0;
 
 		if(surf.ShaderMat!=NULL){
-			surf.ShaderMat->TurnOn(&surf, mat);
+			surf.ShaderMat->TurnOn(mat, &surf);
 		}
 		else
 		{

+ 5 - 2
openb3dlib.mod/openb3d/src/mesh.h

@@ -40,7 +40,7 @@ public:
 	list<Surface*> surf_list;
 	list<Surface*> anim_surf_list; // only used if mesh contains anim info, only contains vertex coords array, initialised upon loading b3d
 	
-	int no_bones;
+	//int no_bones;
 	vector<Bone*> bones;
 	
 	Matrix mat_sp; // mat_sp used in TMesh's Update to provide necessary additional transform matrix for sprites
@@ -56,7 +56,7 @@ public:
 	Mesh(){
 
 		no_surfs=0;
-		no_bones=0;
+		//no_bones=0;
 		
 		c_col_tree=NULL;
 		reset_col_tree=0;
@@ -72,6 +72,7 @@ public:
 	
 	static Mesh* CreateMesh(Entity* parent_ent=NULL);
 	Surface* CreateSurface(Brush* Bru=NULL);
+	Bone* CreateBone(Entity* parent_ent=NULL);
 	static Mesh* LoadMesh(string filename,Entity* parent_ent=NULL);
 	static Mesh* LoadAnimMesh(string filename,Entity* parent_ent=NULL);
 	static Mesh* CreateQuad(Entity* parent_ent=NULL);
@@ -101,6 +102,8 @@ public:
 	float MeshDepth();
 	int CountSurfaces();
 	Surface* GetSurface(int surf_no_get);
+	void SkinMesh(int surf_no_get, int vid, int bone1, float weight1=1.0, int bone2=0, float weight2=0, int bone3=0, float weight3=0, int bone4=0, float weight4=0);
+
 	static void CopyBonesList(Entity* ent,vector<Bone*>& bones);
 	Mesh* CollapseAnimMesh(Mesh* mesh=NULL);
 	Mesh* CollapseChildren(Entity* ent0,Mesh* mesh=NULL);

+ 11 - 9
openb3dlib.mod/openb3d/src/model.cpp

@@ -68,7 +68,8 @@ Mesh* LoadAnimB3D(string f_name,Entity* parent_ent_ext){
 	file->ReadInt();
 	file->ReadInt();
 
-	int vno=file->ReadInt();
+	//int vno=
+	file->ReadInt();
 
 
 	//if(tag!="BB3D") RuntimeError(tag.c_str());//"Invalid b3d file");
@@ -85,7 +86,6 @@ Mesh* LoadAnimB3D(string f_name,Entity* parent_ent_ext){
 	int tex_no=0;
 	vector<Texture*> tex;
 	string te_file="";
-	string te_filepath="";
 	int te_flags=0;
 	int te_blend=0;
 	int te_coords=0;
@@ -154,16 +154,16 @@ Mesh* LoadAnimB3D(string f_name,Entity* parent_ent_ext){
 	// tris local vars
 	Surface* surf=NULL;
 	int tr_brush_id=0;
-	int tr_sz=0;
+	//int tr_sz=0;
 	int tr_vid0=0;
 	int tr_vid1=0;
 	int tr_vid2=0;
 
 
 	// anim local vars
-	int a_flags=0;
+	//int a_flags=0;
 	int a_frames=0;
-	int a_fps=0;
+	//int a_fps=0;
 
 	// bone local vars
 	Bone* bo_bone=0;
@@ -605,7 +605,7 @@ Mesh* LoadAnimB3D(string f_name,Entity* parent_ent_ext){
 
 			}
 
-			tr_sz=12;
+			//tr_sz=12;
 
 			new_tag=ReadTag(file);
 
@@ -641,9 +641,11 @@ Mesh* LoadAnimB3D(string f_name,Entity* parent_ent_ext){
 
 		}else if(tag_id==ANIM){
 
-			a_flags=file->ReadInt();
+			//a_flags=
+			file->ReadInt();
 			a_frames=file->ReadInt();
-			a_fps=file->ReadFloat();
+			//a_fps=
+			file->ReadFloat();
 
 			if(mesh!=NULL){
 
@@ -819,7 +821,7 @@ Mesh* LoadAnimB3D(string f_name,Entity* parent_ent_ext){
 				bo_bone->mat.Overwrite(*new_mat);
 			}
 
-			bo_bone->inv_mat=bo_bone->mat.Inverse();
+			bo_bone->mat.GetInverse(bo_bone->inv_mat);
 
 			if(new_tag!="KEYS"){
 				Entity::entity_list.push_back(bo_bone);

+ 175 - 159
openb3dlib.mod/openb3d/src/particle.cpp

@@ -1,159 +1,175 @@
-#include "glew.h"
-/*
-#ifdef linux
-#define GL_GLEXT_PROTOTYPES
-#include <GL/gl.h>
-#include <GL/glext.h>
-#endif
-#ifdef WIN32
-#include <gl\GLee.h>
-#endif
-*/
-
-#include "camera.h"
-#include "particle.h"
-#include "surface.h"
-
-list<ParticleBatch*> ParticleBatch::particle_batch_list;
-
-void ParticleBatch::Render(){
-	int depth_mask_disabled=false;
-
-	Surface* surf=*surf_list.begin();
-
-	glDisable(GL_ALPHA_TEST); // ?
-
-	if(Global::fx1!=true){
-		Global::fx1=true;
-		glDisableClientState(GL_NORMAL_ARRAY);
-	}
-
-	if(Global::fx2!=true){
-		Global::fx2=true;
-		glEnableClientState(GL_COLOR_ARRAY);
-		glEnable(GL_COLOR_MATERIAL);
-	}
-
-	if(surf->alpha_enable==true){
-		if(Global::alpha_enable!=true){
-			Global::alpha_enable=true;
-			glEnable(GL_BLEND);
-		}
-		glDepthMask(GL_FALSE); // must be set to false every time, as it's always equal to true before it's called
-		depth_mask_disabled=true; // set this to true to we know when to enable depth mask at bottom of function
-	}else{
-		if(Global::alpha_enable!=false){
-			Global::alpha_enable=false;
-			glDisable(GL_BLEND);
-			//glDepthMask(GL_TRUE); already set to true
-		}
-	}
-
-	if(brush.blend!=Global::blend_mode){
-		Global::blend_mode=brush.blend;
-
-		switch(brush.blend){
-			case 0:
-				glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); // alpha
-				break;
-			case 1:
-				glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); // alpha
-				break;
-			case 2:
-				glBlendFunc(GL_DST_COLOR,GL_ZERO); // multiply
-				break;
-			case 3:
-				glBlendFunc(GL_SRC_ALPHA,GL_ONE); // additive and alpha
-				break;
-		}
-
-	}
-
-
-	glEnable( GL_POINT_SPRITE ); 
-
-	float quadratic[] = {0,0,1};
-	glPointParameterfv( GL_POINT_DISTANCE_ATTENUATION, quadratic );
-
-	glEnable( GL_POINT_SMOOTH );
-	glPointSize(brush.tex[0]->width * Global::camera_in_use->vheight*.5);
-	glActiveTexture(GL_TEXTURE0);
-	glEnable( GL_TEXTURE_2D );
-
-	if(brush.tex[0]->flags&4){
-		glEnable(GL_ALPHA_TEST);
-	}
-
-	switch(brush.tex[0]->blend){
-		case 0: glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_REPLACE);
-		break;
-		case 1: glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_DECAL);
-		break;
-		case 2: glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE);
-		//case 2 glTexEnvf(GL_TEXTURE_ENV,GL_COMBINE_RGB_EXT,GL_MODULATE);
-		break;
-		case 3: glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_ADD);
-		break;
-		case 4:
-			glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT);
-			glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT, GL_DOT3_RGB_EXT);
-			break;
-		case 5:
-			glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_COMBINE);
-			glTexEnvi(GL_TEXTURE_ENV,GL_COMBINE_RGB,GL_MODULATE);
-			glTexEnvi(GL_TEXTURE_ENV,GL_RGB_SCALE,2.0);
-			break;
-		default: glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE);
-	}
-
-
-	glTexEnvf(GL_POINT_SPRITE, GL_COORD_REPLACE, GL_TRUE);
-	glBindTexture(GL_TEXTURE_2D, brush.tex[0]->texture);
-
-
-
-
-	glColorPointer(4,GL_FLOAT,0,&surf->vert_col[0]);
-
-	glVertexPointer(3,GL_FLOAT,0,&surf->vert_coords[0]);
-	glDrawArrays(GL_POINTS,0,surf->no_verts);
-
-	glDisable( GL_POINT_SPRITE ); 
-	glDisable( GL_POINT_SMOOTH );
-
-	// enable depth mask again if it was disabled when blend was enabled
-	if(depth_mask_disabled==true){
-		glDepthMask(GL_TRUE);
-		depth_mask_disabled=false; // set to false again for when we repeat loop
-	}
-
-
-
-	//Trails
-
-	for(int i=0;i<=surf->no_verts-1;i++){
-		surf->vert_col[i*4+3]*=.99;
-		surf->vert_coords[i*3]+=0;
-		surf->vert_coords[i*3+1]+=.1;
-		surf->vert_coords[i*3+2]+=0;
-
-	}
-
-
-int del_trail_points=surf->no_verts/1;//3000;
-
-	if (del_trail_points!=0){
-		surf->vert_tex_coords0.clear();
-		surf->vert_tex_coords1.clear();
-		if (surf->no_verts<=del_trail_points){
-			surf->vert_coords.clear();
-			surf->vert_col.clear();
-			surf->no_verts=0;
-		}else{
-			surf->vert_coords.erase(surf->vert_coords.begin(),surf->vert_coords.begin()+del_trail_points*3);
-			surf->vert_col.erase(surf->vert_col.begin(),surf->vert_col.begin()+del_trail_points*4);
-			surf->no_verts-=del_trail_points;
-		}
-	}
-
-}
+
+#ifdef OPENB3D_GLEW
+	#include "glew.h"
+#else
+	#ifdef linux
+	#define GL_GLEXT_PROTOTYPES
+	#include <GL/gl.h>
+	#include <GL/glext.h>
+	#endif
+
+	#ifdef WIN32
+	#include <gl\GLee.h>
+	#endif
+
+	#ifdef __APPLE__
+	#include "GLee.h"
+	#endif
+#endif
+
+#include "camera.h"
+#include "particle.h"
+#include "surface.h"
+
+list<ParticleBatch*> ParticleBatch::particle_batch_list;
+
+void ParticleBatch::Render(){
+	int depth_mask_disabled=false;
+
+	Surface* surf=*surf_list.begin();
+
+	glDisable(GL_ALPHA_TEST); // ?
+
+	if(Global::fx1!=true){
+		Global::fx1=true;
+		glDisableClientState(GL_NORMAL_ARRAY);
+	}
+
+	if(Global::fx2!=true){
+		Global::fx2=true;
+		glEnableClientState(GL_COLOR_ARRAY);
+		glEnable(GL_COLOR_MATERIAL);
+	}
+
+	if(surf->alpha_enable==true){
+		if(Global::alpha_enable!=true){
+			Global::alpha_enable=true;
+			glEnable(GL_BLEND);
+		}
+		glDepthMask(GL_FALSE); // must be set to false every time, as it's always equal to true before it's called
+		depth_mask_disabled=true; // set this to true to we know when to enable depth mask at bottom of function
+	}else{
+		if(Global::alpha_enable!=false){
+			Global::alpha_enable=false;
+			glDisable(GL_BLEND);
+			//glDepthMask(GL_TRUE); already set to true
+		}
+	}
+
+	if(brush.blend!=Global::blend_mode){
+		Global::blend_mode=brush.blend;
+
+		switch(brush.blend){
+			case 0:
+				glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); // alpha
+				break;
+			case 1:
+				glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); // alpha
+				break;
+			case 2:
+				glBlendFunc(GL_DST_COLOR,GL_ZERO); // multiply
+				break;
+			case 3:
+				glBlendFunc(GL_SRC_ALPHA,GL_ONE); // additive and alpha
+				break;
+		}
+
+	}
+
+
+	glEnable( GL_POINT_SPRITE ); 
+
+	float quadratic[] = {0,0,1};
+	glPointParameterfv( GL_POINT_DISTANCE_ATTENUATION, quadratic );
+
+	glEnable( GL_POINT_SMOOTH );
+	glPointSize(brush.tex[0]->width * Global::camera_in_use->vheight*.5);
+	glActiveTexture(GL_TEXTURE0);
+	glEnable( GL_TEXTURE_2D );
+
+	if(brush.tex[0]->flags&4){
+		glEnable(GL_ALPHA_TEST);
+	}
+
+	switch(brush.tex[0]->blend){
+		case 0: glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_REPLACE);
+		break;
+		case 1: glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_DECAL);
+		break;
+		case 2: glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE);
+		//case 2 glTexEnvf(GL_TEXTURE_ENV,GL_COMBINE_RGB_EXT,GL_MODULATE);
+		break;
+		case 3: glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_ADD);
+		break;
+		case 4:
+			glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT);
+			glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT, GL_DOT3_RGB_EXT);
+			break;
+		case 5:
+			glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_COMBINE);
+			glTexEnvi(GL_TEXTURE_ENV,GL_COMBINE_RGB,GL_MODULATE);
+			glTexEnvi(GL_TEXTURE_ENV,GL_RGB_SCALE,2.0);
+			break;
+		default: glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE);
+	}
+
+
+	glTexEnvf(GL_POINT_SPRITE, GL_COORD_REPLACE, GL_TRUE);
+	glBindTexture(GL_TEXTURE_2D, brush.tex[0]->texture);
+
+
+
+
+	glColorPointer(4,GL_FLOAT,0,&surf->vert_col[0]);
+
+	glVertexPointer(3,GL_FLOAT,0,&surf->vert_coords[0]);
+	glDrawArrays(GL_POINTS,0,surf->no_verts);
+
+	glDisable( GL_POINT_SPRITE ); 
+	glDisable( GL_POINT_SMOOTH );
+
+	// enable depth mask again if it was disabled when blend was enabled
+	if(depth_mask_disabled==true){
+		glDepthMask(GL_TRUE);
+		depth_mask_disabled=false; // set to false again for when we repeat loop
+	}
+
+
+
+	//Trails
+
+	if (trail>1){
+		float r=(brush.red-2)/trail;
+		float g=(brush.green-2)/trail;
+		float b=(brush.blue-2)/trail;
+		float a=(brush.alpha-2)/trail;
+		for(int i=0;i<=surf->no_verts-1;i++){
+			surf->vert_col[i*4]+=r;
+			surf->vert_col[i*4+1]+=g;
+			surf->vert_col[i*4+2]+=b;
+			surf->vert_col[i*4+3]+=a;
+			surf->vert_coords[i*3]+=px;
+			surf->vert_coords[i*3+1]+=py;
+			surf->vert_coords[i*3+2]+=pz;
+
+		}
+	}
+
+
+	int del_trail_points=surf->no_verts/trail;
+
+	if (del_trail_points!=0){
+		surf->vert_tex_coords0.clear();
+		surf->vert_tex_coords1.clear();
+		if (surf->no_verts<=del_trail_points){
+			surf->vert_coords.clear();
+			surf->vert_col.clear();
+			surf->no_verts=0;
+		}else{
+			surf->vert_coords.erase(surf->vert_coords.begin(),surf->vert_coords.begin()+del_trail_points*3);
+			surf->vert_col.erase(surf->vert_col.begin(),surf->vert_col.begin()+del_trail_points*4);
+			surf->no_verts-=del_trail_points;
+		}
+	}
+
+}

+ 7 - 4
openb3dlib.mod/openb3d/src/particle.h

@@ -24,22 +24,25 @@ public:
 
 	static list<ParticleBatch*> particle_batch_list;
 
+	int trail;
+
 	void Render();
 
 	
 	ParticleBatch(){
 		no_surfs=1;
-		no_bones=0;
 		
 		c_col_tree=NULL;
 		reset_col_tree=0;
 		
 		reset_bounds=true;
+
+		trail=1;
 		
 		min_x=-999999999;;min_y=-999999999;;min_z=-999999999;;max_x=999999999;;max_y=999999999;;max_z=999999999;;
 	};
 	
-	static Surface* GetParticleBatchSurface(Texture* tex,int blend,int order){
+	static ParticleBatch* GetParticleBatch(Texture* tex,int blend,int order){
 	
 		ParticleBatch* particle_batch=NULL;
 	
@@ -48,7 +51,7 @@ public:
 		for(it=particle_batch_list.begin();it!=particle_batch_list.end();it++){
 			particle_batch=*it;
 			if(particle_batch->brush.tex[0]==tex && particle_batch->brush.blend==blend && particle_batch->order==order){
-				return *particle_batch->surf_list.begin();
+				return particle_batch;		//*particle_batch->surf_list.begin();
 			}
 		}
 		
@@ -67,7 +70,7 @@ public:
 		particle_batch->brush.blend=blend;
 		particle_batch->order=order;
 		particle_batch_list.push_back(particle_batch);
-		return surf;
+		return particle_batch;
 		
 	}
 

+ 2 - 2
openb3dlib.mod/openb3d/src/pick.cpp

@@ -30,13 +30,13 @@ Entity* Pick::CameraPick(Camera* cam,float vx,float vy){
 	float py=0.0;
 	float pz=0.0;
 
-	int r=gluUnProject(vx,vy,0.0,&cam->mod_mat[0],&cam->proj_mat[0],&cam->viewport[0],&px,&py,&pz);
+	gluUnProject(vx,vy,0.0,&cam->mod_mat[0],&cam->proj_mat[0],&cam->viewport[0],&px,&py,&pz);
 
 	float x=px;
 	float y=py;
 	float z=-pz;
 		
-	r=gluUnProject(vx,vy,1.0,&cam->mod_mat[0],&cam->proj_mat[0],&cam->viewport[0],&px,&py,&pz);
+	gluUnProject(vx,vy,1.0,&cam->mod_mat[0],&cam->proj_mat[0],&cam->viewport[0],&px,&py,&pz);
 
 	float x2=px;
 	float y2=py;

+ 1 - 1
openb3dlib.mod/openb3d/src/project.h

@@ -21,7 +21,6 @@
 #ifndef PROJECT_H
 #define PROJECT_H
 
-//#import <OpenGLES/ES1/gl.h>
 #ifdef linux
 #include <GL/gl.h>
 #endif
@@ -32,6 +31,7 @@
 #include <OpenGL/gl.h>
 #endif
 
+
 #ifdef PC_HEADER
 #include "all.h"
 #else

+ 1 - 2
openb3dlib.mod/openb3d/src/shadermat.h

@@ -10,7 +10,6 @@
 
 #include <string>
 #include <sstream>
-#include <vector>
 
 class Surface;
 class Entity;
@@ -74,7 +73,7 @@ class Shader {//: public MaterialPlugin{
 	// internal 
 public:
 	static Shader* CreateShaderMaterial(string Name = "");
-	void TurnOn(Surface* surf, Matrix& mat);
+	void TurnOn(Matrix& mat, Surface* surf, vector<float>* vertices=0);
 	void TurnOff();
 	void AddShader(string _vert, string _frag);
 	void AddShaderFromString(string _vert, string _frag);

+ 2 - 0
openb3dlib.mod/openb3d/src/shaderobject.h

@@ -1,5 +1,6 @@
 ;
 #include <map>
+#include <vector>
 
 
 
@@ -83,6 +84,7 @@ class ProgramObject{
 	//-------------------------------------------------------------------------------------
 	//  Array Parameter
 	void SetParameterArray(string name, Surface* surf, int vbo);
+	void SetParameterArray(string name, vector<float>* vertices, int vbo);
 
 	//-------------------------------------------------------------------------------------
 	// Float Parameter

+ 21 - 18
openb3dlib.mod/openb3d/src/shadow.cpp

@@ -1,18 +1,21 @@
 
-#include "glew.h"
-/*
-#ifdef linux
-#define GL_GLEXT_PROTOTYPES
-#include <GL/gl.h>
-#include <GL/glext.h>
+#ifdef OPENB3D_GLEW
+	#include "glew.h"
+#else
+	#ifdef linux
+	#define GL_GLEXT_PROTOTYPES
+	#include <GL/gl.h>
+	#include <GL/glext.h>
+	#endif
+
+	#ifdef WIN32
+	#include <gl\GLee.h>
+	#endif
+
+	#ifdef __APPLE__
+	#include "GLee.h"
+	#endif
 #endif
-#ifdef WIN32
-#include "GLee.h"
-#endif
-#ifdef __APPLE__
-#include "GLee.h"
-#endif
-*/
 
 #include "shadow.h"
 #include "light.h"
@@ -326,7 +329,8 @@ void ShadowObject::UpdateCaster(){
 	char check2=0;
 	char check3=0;
 
-	Matrix* mat1 = Parent->MQ_GetMatrix(true);
+	Matrix mat1;
+	Parent->MQ_GetMatrix(mat1, true);
 
 	vector<ShadowTriangle*>::iterator it;
 
@@ -353,17 +357,17 @@ void ShadowObject::UpdateCaster(){
 		etet->tf_v1x= etet->v1x;
 		etet->tf_v1y= etet->v1y;
 		etet->tf_v1z= etet->v1z;
-		mat1->TransformVec(etet->tf_v1x, etet->tf_v1y, etet->tf_v1z, 1);
+		mat1.TransformVec(etet->tf_v1x, etet->tf_v1y, etet->tf_v1z, 1);
 
 		etet->tf_v2x= etet->v2x;
 		etet->tf_v2y= etet->v2y;
 		etet->tf_v2z= etet->v2z;
-		mat1->TransformVec(etet->tf_v2x, etet->tf_v2y, etet->tf_v2z, 1);
+		mat1.TransformVec(etet->tf_v2x, etet->tf_v2y, etet->tf_v2z, 1);
 
 		etet->tf_v3x= etet->v3x;
 		etet->tf_v3y= etet->v3y;
 		etet->tf_v3z= etet->v3z;
-		mat1->TransformVec(etet->tf_v3x, etet->tf_v3y, etet->tf_v3z, 1);
+		mat1.TransformVec(etet->tf_v3x, etet->tf_v3y, etet->tf_v3z, 1);
 
 		e0x= etet->tf_v3x - etet->tf_v2x;
 		e0y= etet->tf_v3y - etet->tf_v2y;
@@ -376,7 +380,6 @@ void ShadowObject::UpdateCaster(){
 		normlight_z  = (etet->tf_v1z  - light_z ) * (e0x  * e1y  - e0y  * e1x );
 		etet->cull = (normlight_x  + normlight_y  + normlight_z  > 0);
 	}
-	delete mat1;
 
 //	for (int v = 0;v<=cnt_tris;v++){
 //		ShadowTriangle* etet = Tri[v];

+ 16 - 13
openb3dlib.mod/openb3d/src/stencil.cpp

@@ -1,18 +1,21 @@
-#include "glew.h"
 
-/*
-#ifdef linux
-#define GL_GLEXT_PROTOTYPES
-#include <GL/gl.h>
-#include <GL/glext.h>
+#ifdef OPENB3D_GLEW
+	#include "glew.h"
+#else
+	#ifdef linux
+	#define GL_GLEXT_PROTOTYPES
+	#include <GL/gl.h>
+	#include <GL/glext.h>
+	#endif
+
+	#ifdef WIN32
+	#include <gl\GLee.h>
+	#endif
+
+	#ifdef __APPLE__
+	#include "GLee.h"
+	#endif
 #endif
-#ifdef WIN32
-#include "GLee.h"
-#endif
-#ifdef __APPLE__
-#include "GLee.h"
-#endif
-*/
 
 #include "stencil.h"
 #include "mesh.h"

+ 1 - 1
openb3dlib.mod/openb3d/src/string_helper.cpp

@@ -19,7 +19,7 @@ string Left(string s,int length){
 
 }
 
-string Right(string s,int length){
+string Right(string s,unsigned int length){
 
 	if (length > s.size()) return ""; // SK: fix out of bounds.
 	return s.substr(s.length()-length);

+ 1 - 1
openb3dlib.mod/openb3d/src/string_helper.h

@@ -14,7 +14,7 @@
 using namespace std;
  
 string Left(string s,int length);
-string Right(string s,int length);
+string Right(string s,unsigned int length);
 string Mid(string s,int offset,int characters=0);
 string Replace(string s,string find,string replace);
 int Instr(string s1,string s2,int offset=0);

+ 16 - 13
openb3dlib.mod/openb3d/src/surface.cpp

@@ -7,20 +7,23 @@
  *
  */
 
-#include "glew.h"
-/*
-#ifdef linux
-#define GL_GLEXT_PROTOTYPES
-#include <GL/gl.h>
-#include <GL/glext.h>
-#endif
-#ifdef WIN32
-#include "GLee.h"
+#ifdef OPENB3D_GLEW
+	#include "glew.h"
+#else
+	#ifdef linux
+	#define GL_GLEXT_PROTOTYPES
+	#include <GL/gl.h>
+	#include <GL/glext.h>
+
+	#endif
+	#ifdef WIN32
+	#include <gl\GLee.h>
+	#endif
+
+	#ifdef __APPLE__
+	#include "GLee.h"
+	#endif
 #endif
-#ifdef __APPLE__
-#include "GLee.h"
-#endif
-*/
 
 #include "surface.h"
 

+ 23 - 23
openb3dlib.mod/openb3d/src/terrain.cpp

@@ -5,20 +5,23 @@
  *
  */
 
-#include "glew.h"
-/*
-#ifdef linux
-#define GL_GLEXT_PROTOTYPES
-#include <GL/gl.h>
-#include <GL/glext.h>
-#endif
-#ifdef WIN32
-#include "GLee.h"
+#ifdef OPENB3D_GLEW
+	#include "glew.h"
+#else
+	#ifdef linux
+	#define GL_GLEXT_PROTOTYPES
+	#include <GL/gl.h>
+	#include <GL/glext.h>
+
+	#endif
+	#ifdef WIN32
+	#include <gl\GLee.h>
+	#endif
+
+	#ifdef __APPLE__
+	#include "GLee.h"
+	#endif
 #endif
-#ifdef __APPLE__
-#include "GLee.h"
-#endif
-*/
 
 
 #include "global.h"
@@ -290,7 +293,7 @@ void Terrain::UpdateTerrain(){
 	int tex_count=0;
 
 	if(ShaderMat!=NULL){
-		ShaderMat->TurnOn(0, mat);
+		ShaderMat->TurnOn(mat, 0, &vertices);
 	}
 
 	tex_count=brush.no_texs;
@@ -302,7 +305,7 @@ void Terrain::UpdateTerrain(){
 
 			// Main brush texture takes precedent over surface brush texture
 			unsigned int texture=0;
-			int tex_flags=0,tex_blend=0,tex_coords=0;
+			int tex_flags=0,tex_blend=0;
 			float tex_u_scale=1.0,tex_v_scale=1.0,tex_u_pos=0.0,tex_v_pos=0.0,tex_ang=0.0;
 			int tex_cube_mode=0;
 
@@ -310,7 +313,7 @@ void Terrain::UpdateTerrain(){
 			texture=brush.cache_frame[ix];
 			tex_flags=brush.tex[ix]->flags;
 			tex_blend=brush.tex[ix]->blend;
-			tex_coords=brush.tex[ix]->coords;
+			//tex_coords=brush.tex[ix]->coords;
 			tex_u_scale=brush.tex[ix]->u_scale;
 			tex_v_scale=brush.tex[ix]->v_scale;
 			tex_u_pos=brush.tex[ix]->u_pos;
@@ -574,7 +577,7 @@ void Terrain::RecreateROAM(){
 	}
 
 
-	tmat = MQ_GetMatrix(true);
+	MQ_GetMatrix(tmat, true);
 
 
 
@@ -586,8 +589,6 @@ void Terrain::RecreateROAM(){
 	drawsub(0, v[0], v[1], v[2]);
 	drawsub(0, v[2], v[3], v[0]);
 
-	delete tmat;
-
 
 }
 
@@ -641,7 +642,7 @@ void Terrain::drawsub(int l, float v0[], float v1[], float v2[]){
 		float vcx=vc[0];
 		float vcy=vc[1];
 		float vcz=-vc[2];
-		tmat->TransformVec(vcx, vcy, vcz, 1);
+		tmat.TransformVec(vcx, vcy, vcz, 1);
 
 		for (int i = 0 ;i<= 5; i++){
 			float d = eyepoint->frustum[i][0] * vcx + eyepoint->frustum[i][1] * vcy - eyepoint->frustum[i][2] * vcz + eyepoint->frustum[i][3];
@@ -813,7 +814,7 @@ void Terrain::TreeCheck(CollisionInfo* ci){
 	}
 
 
-	tmat = MQ_GetMatrix(true);
+	MQ_GetMatrix(tmat, true);
 
 
 
@@ -832,7 +833,6 @@ void Terrain::TreeCheck(CollisionInfo* ci){
 
 	c_col_tree=C_CreateColTree(mesh_info);
 	C_DeleteMeshInfo(mesh_info);
-	delete tmat;
 
 
 
@@ -888,7 +888,7 @@ void Terrain::col_tree_sub(int l, float v0[], float v1[], float v2[]){
 		float vcx=vc[0];
 		float vcy=vc[1];
 		float vcz=-vc[2];
-		tmat->TransformVec(vcx, vcy, vcz, 1);
+		tmat.TransformVec(vcx, vcy, vcz, 1);
 
 
 		/*Is triangle on the collision line?*/

+ 2 - 2
openb3dlib.mod/openb3d/src/terrain.h

@@ -20,8 +20,8 @@ using namespace std;
 const int ROAM_LMAX = 20; 		//<-----------terrain detail here	
 
 class Terrain : public Entity{
-private:
-	Matrix* tmat;
+protected:
+	Matrix tmat;
 	float dradius;
 	float* NormalsMap;
 	float xcf,ycf,zcf; 			//used to store camera position

+ 29 - 19
openb3dlib.mod/openb3d/src/texture.cpp

@@ -7,23 +7,26 @@
  *
  */
 
-#include "glew.h"
-/*
-#ifdef linux
-#define GL_GLEXT_PROTOTYPES
-#include <GL/gl.h>
-#include <GL/glext.h>
-#include <GL/glu.h>
-#endif
-#ifdef WIN32
-#include "GLee.h"
-#include <GL\glu.h>
+#ifdef OPENB3D_GLEW
+	#include "glew.h"
+#else
+	#ifdef linux
+	#define GL_GLEXT_PROTOTYPES
+	#include <GL/gl.h>
+	#include <GL/glext.h>
+	#include <GL/glu.h>
+	#endif
+
+	#ifdef WIN32
+	#include <gl\GLee.h>
+	#include <GL\glu.h>
+	#endif
+
+	#ifdef __APPLE__
+	#include "GLee.h"
+	#include <OpenGL/glu.h>
+	#endif
 #endif
-#ifdef __APPLE__
-#include "GLee.h"
-#include <OpenGL/glu.h>
-#endif
-*/
 
 #include "texture.h"
 #include "stb_image.h"
@@ -44,7 +47,9 @@ void CopyPixels (unsigned char *src, unsigned int srcWidth, unsigned int srcHeig
 
 Texture* Texture::LoadTexture(string filename,int flags){
 	if (flags&128) {
-		//filename=Strip(filename); // get rid of path info
+		#ifndef OPENB3D_BMX
+		filename=Strip(filename); // get rid of path info
+		#endif
 		if (File::ResourceFilePath(filename)==""){
 			cout << "Error: Cannot Find Texture: " << filename << endl;
 			return NULL;
@@ -120,7 +125,9 @@ Texture* Texture::LoadTexture(string filename,int flags){
 
 Texture* Texture::LoadAnimTexture(string filename,int flags, int frame_width,int frame_height,int first_frame,int frame_count){
 
-	//filename=Strip(filename); // get rid of path info
+	#ifndef OPENB3D_BMX
+	filename=Strip(filename); // get rid of path info
+	#endif
 
 	if(File::ResourceFilePath(filename)==""){
 		cout << "Error: Cannot Find Texture: " << filename << endl;
@@ -301,6 +308,7 @@ void Texture::FilterFlags(){
 	}
 }
 
+#ifdef OPENB3D_BMX
 // used in LoadTexture, strips path info from filename
 string Texture::Strip(string filename){
 	string stripped_filename=filename;
@@ -317,6 +325,7 @@ string Texture::Strip(string filename){
 	}
 
 	return stripped_filename;
+
 }
 
 // strips file info from filepath
@@ -367,10 +376,11 @@ string Texture::NewFilePath(string filepath, string filename){
 		ifs.close();
 		return fpath+"\\"+fname; // windows
 	}
-	
+
 	cout << "Error: Can't Find Resource File '"+filename+"'" << endl;
 	return filename;
 }
+#endif
 
 void Texture::BufferToTex(unsigned char* buffer, int frame){
 	if(flags&128){

+ 2 - 0
openb3dlib.mod/openb3d/src/texture.h

@@ -75,8 +75,10 @@ public:
 	Texture* TexInList();
 	void FilterFlags();
 	static string Strip(string filename);
+#ifdef OPENB3D_BMX
 	static string StripFile(string filename);
 	static string NewFilePath(string filepath, string filename);
+#endif
 };
 
 #endif

+ 20 - 14
openb3dlib.mod/openb3d/src/voxel.cpp

@@ -1,19 +1,21 @@
 
-
-#include "glew.h"
-/*
-#ifdef linux
-#define GL_GLEXT_PROTOTYPES
-#include <GL/gl.h>
-#include <GL/glext.h>
-#endif
-#ifdef WIN32
-#include "GLee.h"
-#endif
-#ifdef __APPLE__
-#include "GLee.h"
+#ifdef OPENB3D_GLEW
+	#include "glew.h"
+#else
+	#ifdef linux
+	#define GL_GLEXT_PROTOTYPES
+	#include <GL/gl.h>
+	#include <GL/glext.h>
+	#endif
+
+	#ifdef WIN32
+	#include <gl\GLee.h>
+	#endif
+
+	#ifdef __APPLE__
+	#include "GLee.h"
+	#endif
 #endif
-*/
 
 #include "voxel.h"
 #include "global.h"
@@ -306,7 +308,11 @@ void VoxelSprite::Render(){
 		glColorPointer(4,GL_FLOAT,0,NULL);
 
 		glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,surf.vbo_id[5]);
+		#ifdef __x86_64__
+		glDrawElements(GL_QUADS,surf.no_tris*4/(1<<lod),GL_UNSIGNED_SHORT, (GLvoid *)(long long)(LOD[surf_number*16+lod]*2));
+		#else
 		glDrawElements(GL_QUADS,surf.no_tris*4/(1<<lod),GL_UNSIGNED_SHORT, (GLvoid *)(LOD[surf_number*16+lod]*2));
+		#endif
 
 	}else{
 

+ 939 - 0
openb3dlib.mod/openb3d/src/voxterrain.cpp

@@ -0,0 +1,939 @@
+/*
+ *  voxterrain.cpp
+ *  openb3d
+ *
+ *
+ */
+
+#ifdef OPENB3D_GLEW
+	#include "glew.h"
+#else
+	#ifdef linux
+	#define GL_GLEXT_PROTOTYPES
+	#include <GL/gl.h>
+	#include <GL/glext.h>
+	#endif
+
+	#ifdef WIN32
+	#include <gl\GLee.h>
+	#endif
+
+	#ifdef __APPLE__
+	#include "GLee.h"
+	#endif
+#endif
+
+#include "global.h"
+#include "entity.h"
+#include "camera.h"
+#include "brush.h"
+#include "voxterrain.h"
+#include "pick.h"
+
+
+#include "stb_image.h"
+#include "string_helper.h"
+#include "file.h"
+#include "tree.h"
+
+//static int _terrSize;
+
+static vector<float> vertices;
+
+
+VoxelTerrain* VoxelTerrain::CreateVoxelTerrain(int xsize, int ysize, int zsize, Entity* parent_ent){
+
+	VoxelTerrain* terr=new VoxelTerrain;
+
+	terr->ShaderMat=0;
+
+	//terr->brush=new brush;
+	mesh_info=C_NewMeshInfo();
+	terr->c_col_tree=C_CreateColTree(mesh_info);
+	C_DeleteMeshInfo(mesh_info);
+	terr->AddParent(*parent_ent);
+	terrain_list.push_back(terr);
+	if (xsize!=0){
+		terr->size=xsize;
+
+		terr->tbuffer=new float**[xsize];
+
+		for (int i=0;i<xsize;i++){
+			terr->tbuffer[i]=new float*[ysize];
+			for (int i1=0;i1<ysize;i1++){
+				terr->tbuffer[i][i1]=new float[zsize];
+			}
+
+		}
+
+
+
+	}
+
+
+
+	return terr;
+
+}
+
+void VoxelTerrain::UpdateTerrain(){
+
+	glBindBuffer(GL_ARRAY_BUFFER,0);
+
+	RecreateOctree();
+
+	glDisable(GL_ALPHA_TEST);
+
+	if (order!=0){
+		glDisable(GL_DEPTH_TEST);
+		glDepthMask(GL_FALSE);
+	}else{
+		glEnable(GL_DEPTH_TEST);
+		glDepthMask(GL_TRUE);
+	}
+
+	switch(brush.blend){
+		case 0:
+			glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); // alpha
+			break;
+		case 1:
+			glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); // alpha
+			break;
+		case 2:
+			glBlendFunc(GL_DST_COLOR,GL_ZERO); // multiply
+			break;
+		case 3:
+			glBlendFunc(GL_SRC_ALPHA,GL_ONE); // additive and alpha
+			break;
+		}
+
+	float ambient_red,ambient_green,ambient_blue;
+
+	// fx flag 1 - full bright ***todo*** disable all lights?
+	if (brush.fx & 1){
+		if(Global::fx1!=true){
+			Global::fx1=true;
+			glDisableClientState(GL_NORMAL_ARRAY);
+		}
+		ambient_red  =1.0;
+		ambient_green=1.0;
+		ambient_blue =1.0;
+	}else{
+		if(Global::fx1!=false){
+			Global::fx1=false;
+			glEnableClientState(GL_NORMAL_ARRAY);
+		}
+		ambient_red  =Global::ambient_red;
+		ambient_green=Global::ambient_green;
+		ambient_blue =Global::ambient_blue;
+	}
+
+	// fx flag 2 - vertex colours
+	/*if(brush.fx&2){
+
+			glEnable(GL_COLOR_MATERIAL);
+	}else{
+			glDisable(GL_COLOR_MATERIAL);
+	}*/
+	if(Global::fx2!=false){
+		Global::fx2=false;
+		glDisableClientState(GL_COLOR_ARRAY);
+		glDisable(GL_COLOR_MATERIAL);
+	}
+
+
+	// fx flag 4 - flatshaded
+	if(brush.fx&4){
+		glShadeModel(GL_FLAT);
+	}else{
+		glShadeModel(GL_SMOOTH);
+	}
+
+	// fx flag 8 - disable fog
+	if(brush.fx&8){
+		if(Global::fog_enabled==true){ // only disable if fog enabled in camera update
+			glDisable(GL_FOG);
+		}
+	}
+
+	// fx flag 16 - disable backface culling
+	if(brush.fx&16){
+		glDisable(GL_CULL_FACE);
+	}else{
+		glEnable(GL_CULL_FACE);
+	}
+
+	// light + material color
+
+	float ambient[]={ambient_red,ambient_green,ambient_blue};
+	glLightModelfv(GL_LIGHT_MODEL_AMBIENT,ambient);
+
+	float mat_ambient[]={brush.red,brush.green,brush.blue,brush.alpha};
+	float mat_diffuse[]={brush.red,brush.green,brush.blue,brush.alpha};
+	float mat_specular[]={brush.shine,brush.shine,brush.shine,brush.shine};
+	float mat_shininess[]={100.0}; // upto 128
+
+	glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT,mat_ambient);
+	glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,mat_diffuse);
+	glMaterialfv(GL_FRONT_AND_BACK,GL_SPECULAR,mat_specular);
+	glMaterialfv(GL_FRONT_AND_BACK,GL_SHININESS,mat_shininess);
+
+	// textures
+
+	int tex_count=0;
+
+	if(ShaderMat!=NULL){
+		ShaderMat->TurnOn(mat, 0, &vertices);
+	}
+
+	tex_count=brush.no_texs;
+
+	int DisableCubeSphereMapping=0;
+	for(int ix=0;ix<tex_count;ix++){
+
+		if(brush.tex[ix]){
+
+			// Main brush texture takes precedent over surface brush texture
+			unsigned int texture=0;
+			int tex_flags=0,tex_blend=0;
+			float tex_u_scale=1.0,tex_v_scale=1.0,tex_u_pos=0.0,tex_v_pos=0.0,tex_ang=0.0;
+			int tex_cube_mode=0;
+
+
+			texture=brush.cache_frame[ix];
+			tex_flags=brush.tex[ix]->flags;
+			tex_blend=brush.tex[ix]->blend;
+			//tex_coords=brush.tex[ix]->coords;
+			tex_u_scale=brush.tex[ix]->u_scale;
+			tex_v_scale=brush.tex[ix]->v_scale;
+			tex_u_pos=brush.tex[ix]->u_pos;
+			tex_v_pos=brush.tex[ix]->v_pos;
+			tex_ang=brush.tex[ix]->angle;
+			tex_cube_mode=brush.tex[ix]->cube_mode;
+			//frame=brush.tex_frame;
+
+			glActiveTexture(GL_TEXTURE0+ix);
+			glClientActiveTexture(GL_TEXTURE0+ix);
+
+			glEnable(GL_TEXTURE_2D);
+			glBindTexture(GL_TEXTURE_2D,texture); // call before glTexParameteri
+
+			// masked texture flag
+			if(tex_flags&4){
+				glEnable(GL_ALPHA_TEST);
+			}else{
+				glDisable(GL_ALPHA_TEST);
+			}
+
+			// mipmapping texture flag
+			if(tex_flags&8){
+				glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
+				glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_LINEAR);
+			}else{
+				glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
+				glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
+			}
+
+			// clamp u flag
+			if(tex_flags&16){
+				glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP_TO_EDGE);
+			}else{
+				glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT);
+			}
+
+			// clamp v flag
+			if(tex_flags&32){
+				glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP_TO_EDGE);
+			}else{
+				glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT);
+			}
+
+				// ***!ES***
+
+			// spherical environment map texture flag
+			if(tex_flags&64){
+				glTexGeni(GL_S,GL_TEXTURE_GEN_MODE,GL_SPHERE_MAP);
+				glTexGeni(GL_T,GL_TEXTURE_GEN_MODE,GL_SPHERE_MAP);
+				glEnable(GL_TEXTURE_GEN_S);
+				glEnable(GL_TEXTURE_GEN_T);
+				DisableCubeSphereMapping=1;
+			}/*else{
+				glDisable(GL_TEXTURE_GEN_S);
+				glDisable(GL_TEXTURE_GEN_T);
+			}*/
+
+				// cubic environment map texture flag
+				if(tex_flags&128){
+
+					glEnable(GL_TEXTURE_CUBE_MAP);
+					glBindTexture(GL_TEXTURE_CUBE_MAP,texture); // call before glTexParameteri
+
+					glTexParameteri(GL_TEXTURE_CUBE_MAP,GL_TEXTURE_WRAP_S,GL_CLAMP_TO_EDGE);
+					glTexParameteri(GL_TEXTURE_CUBE_MAP,GL_TEXTURE_WRAP_T,GL_CLAMP_TO_EDGE);
+					glTexParameteri(GL_TEXTURE_CUBE_MAP,GL_TEXTURE_WRAP_R,GL_CLAMP_TO_EDGE);
+					glTexParameteri(GL_TEXTURE_CUBE_MAP,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
+					glTexParameteri(GL_TEXTURE_CUBE_MAP,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
+
+					glEnable(GL_TEXTURE_GEN_S);
+					glEnable(GL_TEXTURE_GEN_T);
+					glEnable(GL_TEXTURE_GEN_R);
+					//glEnable(GL_TEXTURE_GEN_Q)
+
+					if(tex_cube_mode==1){
+						glTexGeni(GL_S,GL_TEXTURE_GEN_MODE,GL_REFLECTION_MAP);
+						glTexGeni(GL_T,GL_TEXTURE_GEN_MODE,GL_REFLECTION_MAP);
+						glTexGeni(GL_R,GL_TEXTURE_GEN_MODE,GL_REFLECTION_MAP);
+					}
+
+					if(tex_cube_mode==2){
+						glTexGeni(GL_S,GL_TEXTURE_GEN_MODE,GL_NORMAL_MAP);
+						glTexGeni(GL_T,GL_TEXTURE_GEN_MODE,GL_NORMAL_MAP);
+						glTexGeni(GL_R,GL_TEXTURE_GEN_MODE,GL_NORMAL_MAP);
+					}
+					DisableCubeSphereMapping=1;
+
+				}else  if (DisableCubeSphereMapping!=0){
+
+					glDisable(GL_TEXTURE_CUBE_MAP);
+
+					// only disable tex gen s and t if sphere mapping isn't using them
+					if((tex_flags & 64)==0){
+						glDisable(GL_TEXTURE_GEN_S);
+						glDisable(GL_TEXTURE_GEN_T);
+					}
+
+					glDisable(GL_TEXTURE_GEN_R);
+					//glDisable(GL_TEXTURE_GEN_Q)
+
+				}
+
+
+			switch(tex_blend){
+				case 0: glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_REPLACE);
+				break;
+				case 1: glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_DECAL);
+				break;
+				case 2: glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE);
+				//case 2 glTexEnvf(GL_TEXTURE_ENV,GL_COMBINE_RGB_EXT,GL_MODULATE);
+				break;
+				case 3: glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_ADD);
+				break;
+				case 4:
+					glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT);
+					glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT, GL_DOT3_RGB_EXT);
+					break;
+				case 5:
+					glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_COMBINE);
+					glTexEnvi(GL_TEXTURE_ENV,GL_COMBINE_RGB,GL_MODULATE);
+					glTexEnvi(GL_TEXTURE_ENV,GL_RGB_SCALE,2.0);
+					break;
+				default: glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE);
+			}
+
+			glEnableClientState(GL_TEXTURE_COORD_ARRAY);
+			glTexCoordPointer(2,GL_FLOAT,32,&vertices[6]);
+
+
+			// reset texture matrix
+			glMatrixMode(GL_TEXTURE);
+			glLoadIdentity();
+
+			if(tex_u_pos!=0.0 || tex_v_pos!=0.0){
+				glTranslatef(tex_u_pos,tex_v_pos,0.0);
+			}
+			if(tex_ang!=0.0){
+				glRotatef(tex_ang,0.0,0.0,1.0);
+			}
+			if(tex_u_scale!=1.0 || tex_v_scale!=1.0){
+				glScalef(tex_u_scale,tex_v_scale,1.0);
+			}
+
+			// ***!ES***
+			// if spheremap flag=true then flip tex
+			if(tex_flags&64){
+				glScalef(1.0,-1.0,-1.0);
+			}
+
+			// if cubemap flag=true then manipulate texture matrix so that cubemap is displayed properly
+			if(tex_flags&128){
+
+				glScalef(1.0,-1.0,-1.0);
+
+				// get current modelview matrix (set in last camera update)
+				float mod_mat[16];
+				glGetFloatv(GL_MODELVIEW_MATRIX,&mod_mat[0]);
+
+				// get rotational inverse of current modelview matrix
+				Matrix new_mat;
+				new_mat.LoadIdentity();
+
+				new_mat.grid[0][0] = mod_mat[0];
+				new_mat.grid[1][0] = mod_mat[1];
+				new_mat.grid[2][0] = mod_mat[2];
+
+				new_mat.grid[0][1] = mod_mat[4];
+				new_mat.grid[1][1] = mod_mat[5];
+				new_mat.grid[2][1] = mod_mat[6];
+
+				new_mat.grid[0][2] = mod_mat[8];
+				new_mat.grid[1][2] = mod_mat[9];
+				new_mat.grid[2][2] = mod_mat[10];
+
+				glMultMatrixf(&new_mat.grid[0][0]);
+
+			}
+
+
+		}
+
+	}
+
+	// draw tris
+	glMatrixMode(GL_MODELVIEW);
+
+	glPushMatrix();
+	glMultMatrixf(&mat.grid[0][0]);
+	glVertexPointer(3,GL_FLOAT,32,&vertices[0]);
+	glNormalPointer(GL_FLOAT,32,&vertices[3]);
+
+	glDrawArrays(GL_TRIANGLES, 0, triangleindex*3);
+	glPopMatrix();
+
+	// disable all texture layers
+	for(int ix=0;ix<tex_count;ix++){
+
+		glActiveTexture(GL_TEXTURE0+ix);
+		glClientActiveTexture(GL_TEXTURE0+ix);
+
+		// reset texture matrix
+		glMatrixMode(GL_TEXTURE);
+		glLoadIdentity();
+
+		glDisable(GL_TEXTURE_2D);
+
+		// ***!ES***
+		if (DisableCubeSphereMapping!=0){
+			glDisable(GL_TEXTURE_CUBE_MAP);
+			glDisable(GL_TEXTURE_GEN_S);
+			glDisable(GL_TEXTURE_GEN_T);
+			glDisable(GL_TEXTURE_GEN_R);
+			DisableCubeSphereMapping=0;
+		}
+
+	}
+	glDisableClientState(GL_TEXTURE_COORD_ARRAY);
+
+
+	if (brush.fx&8 && Global::fog_enabled==true){
+		glEnable(GL_FOG);
+	}
+
+	if(ShaderMat!=NULL){
+		ShaderMat->TurnOff();
+	}
+
+}
+
+void VoxelTerrain::RecreateOctree(){
+	TFormPoint(eyepoint->EntityX(true), eyepoint->EntityY(true), eyepoint->EntityZ(true), 0, this);
+	xcf = tformed_x;
+	ycf = tformed_y;
+	zcf = -tformed_z;
+
+	BuildCubeGrid (Xcf, Ycf, Zcf, eyepoint->range_far,0,0,0,0,0,0,0,0);
+
+}
+
+void VoxelTerrain::MarchingCube(float x, float y, float z, float x1, float y1, float z1, float F[8]){
+
+	float EdgeX[12], EdgeY[12], EdgeZ[12];
+
+	Surface* surf=*surf_list.begin();
+
+	unsigned char cubeIndex=0;
+	
+	if(F[6] < .5)
+		cubeIndex |= 1;
+	if(F[7] < .5)
+		cubeIndex |= 2;
+	if(F[3] < .5)
+		cubeIndex |= 4;
+	if(F[2] < .5)
+		cubeIndex |= 8;
+	if(F[4] < .5)
+		cubeIndex |= 16;
+	if(F[5] < .5)
+		cubeIndex |= 32;
+	if(F[1] < .5)
+		cubeIndex |= 64;
+	if(F[0] < .5)
+		cubeIndex |= 128;
+
+	//look this value up in the edge table to see which edges to interpolate along
+	int usedEdges=edgeTable[cubeIndex];
+
+	//if the cube is entirely within/outside surface, no faces			
+	if(usedEdges==0 || usedEdges==255)
+		return;
+
+	if(usedEdges & 1){
+		float Ratio = ( .5 - F[6] )/( F[7] - F[6] );
+
+		EdgeX[0] = x  + Ratio*(x1 - x );
+		EdgeY[0] = y1 + Ratio*(y1 - y1);
+		EdgeZ[0] = z1 + Ratio*(z1 - z1);
+
+
+	}
+	if(usedEdges & 2){
+		float Ratio = ( .5 - F[7] )/( F[3] - F[7] );
+
+		EdgeX[1] = x1 + Ratio*(x1 - x1);
+		EdgeY[1] = y1 + Ratio*(y1 - y1);
+		EdgeZ[1] = z1 + Ratio*(z  - z1);
+
+	}
+	if(usedEdges & 4){
+		float Ratio = ( .5 - F[3] )/( F[2] - F[3] );
+
+		EdgeX[2] = x1 + Ratio*(x  - x1);
+		EdgeY[2] = y1 + Ratio*(y1 - y1);
+		EdgeZ[2] = z  + Ratio*(z  - z );
+
+	}
+	if(usedEdges & 8){
+		float Ratio = ( .5 - F[2] )/( F[6] - F[2] );
+
+		EdgeX[3] = x  + Ratio*(x  - x );
+		EdgeY[3] = y1 + Ratio*(y1 - y1);
+		EdgeZ[3] = z  + Ratio*(z1 - z );
+
+	}
+
+
+	if(usedEdges & 16){
+		float Ratio = ( .5 - F[4] )/( F[5] - F[4] );
+
+		EdgeX[4] = x  + Ratio*(x1 - x );
+		EdgeY[4] = y  + Ratio*(y  - y );
+		EdgeZ[4] = z1 + Ratio*(z1 - z1);
+
+	}
+	if(usedEdges & 32){
+		float Ratio = ( .5 - F[5] )/( F[1] - F[5] );
+
+		EdgeX[5] = x1 + Ratio*(x1 - x1);
+		EdgeY[5] = y  + Ratio*(y  - y );
+		EdgeZ[5] = z1 + Ratio*(z  - z1);
+
+	}
+	if(usedEdges & 64){
+		float Ratio = ( .5 - F[1] )/( F[0] - F[1] );
+
+		EdgeX[6] = x1 + Ratio*(x  - x1);
+		EdgeY[6] = y  + Ratio*(y  - y );
+		EdgeZ[6] = z  + Ratio*(z  - z );
+
+	}
+	if(usedEdges & 128){
+		float Ratio = ( .5 - F[0] )/( F[4] - F[0] );
+
+		EdgeX[7] = x  + Ratio*(x  - x );
+		EdgeY[7] = y  + Ratio*(y  - y );
+		EdgeZ[7] = z  + Ratio*(z1 - z );
+	}
+
+
+	if(usedEdges & 256){
+		float Ratio = ( .5 - F[4] )/( F[6] - F[4] );
+
+		EdgeX[8] = x  + Ratio*(x  - x );
+		EdgeY[8] = y  + Ratio*(y1 - y );
+		EdgeZ[8] = z1 + Ratio*(z1 - z1);
+	}
+	if(usedEdges & 512){
+		float Ratio = ( .5 - F[5] )/( F[7] - F[5] );
+
+		EdgeX[9] = x1 + Ratio*(x1 - x1);
+		EdgeY[9] = y  + Ratio*(y1 - y );
+		EdgeZ[9] = z1 + Ratio*(z1 - z1);
+	}
+	if(usedEdges & 1024){
+		float Ratio = ( .5 - F[1] )/( F[3] - F[1] );
+
+		EdgeX[10] = x1 + Ratio*(x1 - x1);
+		EdgeY[10] = y  + Ratio*(y1 - y );
+		EdgeZ[10] = z  + Ratio*(z  - z );
+	}
+	if(usedEdges & 2048){
+		float Ratio = ( .5 - F[0] )/( F[2] - F[0] );
+
+		EdgeX[11] = x  + Ratio*(x  - x );
+		EdgeY[11] = y  + Ratio*(y1 - y );
+		EdgeZ[11] = z  + Ratio*(z  - z );
+	}
+
+	for(int k=0; triTable[cubeIndex][k]!=-1; k+=3){
+
+
+
+		vertices.push_back( EdgeX[triTable[cubeIndex][k+0]]);
+		vertices.push_back( EdgeY[triTable[cubeIndex][k+0]]);
+		vertices.push_back(-EdgeZ[triTable[cubeIndex][k+0]]);
+
+		vertices.push_back( EdgeX[triTable[cubeIndex][k+1]]);
+		vertices.push_back( EdgeY[triTable[cubeIndex][k+1]]);
+		vertices.push_back(-EdgeZ[triTable[cubeIndex][k+1]]);
+
+		vertices.push_back( EdgeX[triTable[cubeIndex][k+2]]);
+		vertices.push_back( EdgeY[triTable[cubeIndex][k+2]]);
+		vertices.push_back(-EdgeZ[triTable[cubeIndex][k+2]]);
+
+		if(brush.fx&4){
+			float ax,ay,az,bx,by,bz;
+			float nx,ny,nz;
+			ax = EdgeX[triTable[cubeIndex][k+1]]-EdgeX[triTable[cubeIndex][k+0]];
+			ay = EdgeY[triTable[cubeIndex][k+1]]-EdgeY[triTable[cubeIndex][k+0]];
+			az = EdgeZ[triTable[cubeIndex][k+1]]-EdgeZ[triTable[cubeIndex][k+0]];
+			bx = EdgeX[triTable[cubeIndex][k+2]]-EdgeX[triTable[cubeIndex][k+1]];
+			by = EdgeY[triTable[cubeIndex][k+2]]-EdgeY[triTable[cubeIndex][k+1]];
+			bz = EdgeZ[triTable[cubeIndex][k+2]]-EdgeZ[triTable[cubeIndex][k+1]];
+			nx = ( ay * bz ) - ( az * by );
+			ny = ( az * bx ) - ( ax * bz );
+			nz = ( ax * by ) - ( ay * bx );
+
+
+			surf->vert_norm.push_back(nx); surf->vert_norm.push_back(ny);surf->vert_norm.push_back(nz);
+			surf->vert_norm.push_back(nx); surf->vert_norm.push_back(ny);surf->vert_norm.push_back(nz);
+			surf->vert_norm.push_back(nx); surf->vert_norm.push_back(ny);surf->vert_norm.push_back(nz);
+		}else{
+
+			surf->vert_norm.push_back(ScalarField(EdgeX[triTable[cubeIndex][k+0]]+1,EdgeY[triTable[cubeIndex][k+0]],EdgeZ[triTable[cubeIndex][k+0]])-ScalarField(EdgeX[triTable[cubeIndex][k+0]]-1,EdgeY[triTable[cubeIndex][k+0]],EdgeZ[triTable[cubeIndex][k+0]]));
+			surf->vert_norm.push_back(ScalarField(EdgeX[triTable[cubeIndex][k+0]],EdgeY[triTable[cubeIndex][k+0]]+1,EdgeZ[triTable[cubeIndex][k+0]])-ScalarField(EdgeX[triTable[cubeIndex][k+0]],EdgeY[triTable[cubeIndex][k+0]]-1,EdgeZ[triTable[cubeIndex][k+0]]));
+			surf->vert_norm.push_back(ScalarField(EdgeX[triTable[cubeIndex][k+0]],EdgeY[triTable[cubeIndex][k+0]],EdgeZ[triTable[cubeIndex][k+0]]+1)-ScalarField(EdgeX[triTable[cubeIndex][k+0]],EdgeY[triTable[cubeIndex][k+0]],EdgeZ[triTable[cubeIndex][k+0]]-1));
+
+			surf->vert_norm.push_back(ScalarField(EdgeX[triTable[cubeIndex][k+1]]+1,EdgeY[triTable[cubeIndex][k+1]],EdgeZ[triTable[cubeIndex][k+1]])-ScalarField(EdgeX[triTable[cubeIndex][k+1]]-1,EdgeY[triTable[cubeIndex][k+1]],EdgeZ[triTable[cubeIndex][k+1]]));
+			surf->vert_norm.push_back(ScalarField(EdgeX[triTable[cubeIndex][k+1]],EdgeY[triTable[cubeIndex][k+1]]+1,EdgeZ[triTable[cubeIndex][k+1]])-ScalarField(EdgeX[triTable[cubeIndex][k+1]],EdgeY[triTable[cubeIndex][k+1]]-1,EdgeZ[triTable[cubeIndex][k+1]]));
+			surf->vert_norm.push_back(ScalarField(EdgeX[triTable[cubeIndex][k+1]],EdgeY[triTable[cubeIndex][k+1]],EdgeZ[triTable[cubeIndex][k+1]]+1)-ScalarField(EdgeX[triTable[cubeIndex][k+1]],EdgeY[triTable[cubeIndex][k+1]],EdgeZ[triTable[cubeIndex][k+1]]-1));
+
+			surf->vert_norm.push_back(ScalarField(EdgeX[triTable[cubeIndex][k+2]]+1,EdgeY[triTable[cubeIndex][k+2]],EdgeZ[triTable[cubeIndex][k+2]])-ScalarField(EdgeX[triTable[cubeIndex][k+2]]-1,EdgeY[triTable[cubeIndex][k+2]],EdgeZ[triTable[cubeIndex][k+2]]));
+			surf->vert_norm.push_back(ScalarField(EdgeX[triTable[cubeIndex][k+2]],EdgeY[triTable[cubeIndex][k+2]]+1,EdgeZ[triTable[cubeIndex][k+2]])-ScalarField(EdgeX[triTable[cubeIndex][k+2]],EdgeY[triTable[cubeIndex][k+2]]-1,EdgeZ[triTable[cubeIndex][k+2]]));
+			surf->vert_norm.push_back(ScalarField(EdgeX[triTable[cubeIndex][k+2]],EdgeY[triTable[cubeIndex][k+2]],EdgeZ[triTable[cubeIndex][k+2]]+1)-ScalarField(EdgeX[triTable[cubeIndex][k+2]],EdgeY[triTable[cubeIndex][k+2]],EdgeZ[triTable[cubeIndex][k+2]]-1));
+		}
+
+
+
+
+
+/*surf->vert_col.push_back(1.0);
+surf->vert_col.push_back(1.0);
+surf->vert_col.push_back(1.0);
+surf->vert_col.push_back(1.0);
+surf->vert_col.push_back(1.0);
+surf->vert_col.push_back(1.0);
+surf->vert_col.push_back(1.0);
+surf->vert_col.push_back(1.0);
+surf->vert_col.push_back(1.0);*/
+
+		surf->no_verts+=3;
+
+	}
+
+
+
+
+
+}
+
+
+float VoxelTerrain::MiddlePoint (float A, float B, float C, float D){
+
+	unsigned char sideIndex=0;
+	
+	if(A < .5)
+		sideIndex |= 1;
+	if(B < .5)
+		sideIndex |= 2;
+	if(C < .5)
+		sideIndex |= 4;
+	if(D < .5)
+		sideIndex |= 8;
+
+	switch (sideIndex){
+		case 9:
+		case 14:
+		case 1:{
+			float c1=(.5-A) / (C - A);
+			float c2=(.5-A) / (B - A);
+			return (.5-A) / (2*(c1*c2) / (c1+c2))+A;
+			}
+		case 2:
+		case 13:
+		case 6:{
+			float c1=(.5-B) / (A - B);
+			float c2=(.5-B) / (D - B);
+			return (.5-B) / (2*(c1*c2) / (c1+c2))+B;
+			}
+		case 12:
+		case 3:{
+			float m=(.5-A) / (C - A) + (.5-B) / (D - B);
+			if (m<1)
+				{
+					float m2=(A+B)/2;
+					return (.5-m2)/m +m2;
+				}else{
+					float m2=(C+D)/2;
+					return (.5-m2)/(2-m) +m2;
+				}
+			}
+		case 11:
+		case 4:{
+			float c1=(.5-C) / (A - C);
+			float c2=(.5-C) / (D - C);
+			return (.5-C) / (2*(c1*c2) / (c1+c2))+C;
+			}
+		case 10:
+		case 5:{
+			float m=(.5-A) / (B - A) + (.5-C) / (D - C);
+			if (m<1)
+				{
+					float m2=(A+C)/2;
+					return (.5-m2)/m +m2;
+				}else{
+					float m2=(B+D)/2;
+					return (.5-m2)/(2-m) +m2;
+				}
+			}
+		case 7:
+		case 8:{
+			float c1=(.5-D) / (C - D);
+			float c2=(.5-D) / (B - D);
+			return (.5-D) / (2*(c1*c2) / (c1+c2))+D;
+			}
+		default:
+			return (A+B+C+D)/4;
+	}
+	
+}
+
+
+void VoxelTerrain::BuildCubeGrid(float x, float y, float z, float l, float f1, float f2, float f3, float f4, float f5, float f6, float f7, float f8){
+
+	float vcx=x;
+	float vcy=y;
+	float vcz=-z;
+	tmat.TransformVec(vcx, vcy, vcz, 1);
+
+	for (int i = 0 ;i<= 5; i++){
+		float d = eyepoint->frustum[i][0] * vcx + eyepoint->frustum[i][1] * vcy - eyepoint->frustum[i][2] * vcz + eyepoint->frustum[i][3];
+		if (d <= -l*sqrt(6)) return;//{ds=ds/10; break;}
+	}
+
+
+	float dx,dy,dz;	
+	float rc;	
+
+	/* compute distance from node To camera (approximated for speed, don't need to be exact) */
+	dx = abs(x - Xcf); dy = abs(y - Ycf); dz = abs(z - Zcf);
+	rc = dx+dy+dz;
+
+	if (rc*.1<=3*l){
+
+		float F[27];
+		F[0] =tbuffer[(int)(x-l)][(int)(y-l)][(int)(z-l)];
+		F[1] =tbuffer[(int)(x)][(int)(y-l)][(int)(z-l)];
+		F[2] =tbuffer[(int)(x+l)][(int)(y-l)][(int)(z-l)];
+		F[3] =tbuffer[(int)(x-l)][(int)(y)][(int)(z-l)];
+		F[4] =tbuffer[(int)(x)][(int)(y)][(int)(z-l)];
+		F[5] =tbuffer[(int)(x+l)][(int)(y)][(int)(z-l)];
+		F[6] =tbuffer[(int)(x-l)][(int)(y+l)][(int)(z-l)];
+		F[7] =tbuffer[(int)(x)][(int)(y+l)][(int)(z-l)];
+		F[8] =tbuffer[(int)(x+l)][(int)(y+l)][(int)(z-l)];
+
+		F[9] =tbuffer[(int)(x-l)][(int)(y-l)][(int)(z)];
+		F[10]=tbuffer[(int)(x)][(int)(y-l)][(int)(z)];
+		F[11]=tbuffer[(int)(x+l)][(int)(y-l)][(int)(z)];
+		F[12]=tbuffer[(int)(x-l)][(int)(y)][(int)(z)];
+		F[13]=tbuffer[(int)(x)][(int)(y)][(int)(z)];
+		F[14]=tbuffer[(int)(x+l)][(int)(y)][(int)(z)];
+		F[15]=tbuffer[(int)(x-l)][(int)(y+l)][(int)(z)];
+		F[16]=tbuffer[(int)(x)][(int)(y+l)][(int)(z)];
+		F[17]=tbuffer[(int)(x+l)][(int)(y+l)][(int)(z)];
+
+		F[18]=tbuffer[(int)(x-l)][(int)(y-l)][(int)(z+l)];
+		F[19]=tbuffer[(int)(x)][(int)(y-l)][(int)(z+l)];
+		F[20]=tbuffer[(int)(x+l)][(int)(y-l)][(int)(z+l)];
+		F[21]=tbuffer[(int)(x-l)][(int)(y)][(int)(z+l)];
+		F[22]=tbuffer[(int)(x)][(int)(y)][(int)(z+l)];
+		F[23]=tbuffer[(int)(x+l)][(int)(y)][(int)(z+l)];
+		F[24]=tbuffer[(int)(x-l)][(int)(y+l)][(int)(z+l)];
+		F[25]=tbuffer[(int)(x)][(int)(y+l)][(int)(z+l)];
+		F[26]=tbuffer[(int)(x+l)][(int)(y+l)][(int)(z+l)];
+
+		//fix cracks
+
+		dx = abs(x - Xcf); dy = abs(y - Ycf); dz = abs(z - 2 * l - Zcf);	//Back
+		rc = dx+dy+dz;
+		if (rc*.1>3*l){
+			F[1] = (f1+f2)/2;
+			F[3] = (f1+f3)/2;
+			F[4] = MiddlePoint(f1,f2,f3,f4);
+			F[5] = (f2+f4)/2;
+			F[7] = (f3+f4)/2;
+		}
+
+		dx = abs(x - Xcf); dy = abs(y - Ycf); dz = abs(z + 2 * l - Zcf);	//Front
+		rc = dx+dy+dz;
+		if (rc*.1>3*l){
+			F[19] = (f5+f6)/2;
+			F[21] = (f5+f7)/2;
+			F[22] = MiddlePoint(f5,f6,f7,f8);
+			F[23] = (f6+f8)/2;
+			F[25] = (f7+f8)/2;
+		}
+
+		dx = abs(x - 2 * l - Xcf); dy = abs(y - Ycf); dz = abs(z - Zcf);	//Left
+		rc = dx+dy+dz;
+		if (rc*.1>3*l){
+			F[3] = (f1+f3)/2;
+			F[9] = (f1+f5)/2;
+			F[12] = MiddlePoint(f1,f3,f5,f7);
+			F[15] = (f3+f7)/2;
+			F[21] = (f5+f7)/2;
+		}
+
+		dx = abs(x + 2 * l - Xcf); dy = abs(y - Ycf); dz = abs(z - Zcf);	//Right
+		rc = dx+dy+dz;
+		if (rc*.1>3*l){
+			F[5] = (f2+f4)/2;
+			F[11] = (f2+f6)/2;
+			F[14] = MiddlePoint(f2,f4,f6,f8);
+			F[17] = (f4+f8)/2;
+			F[23] = (f6+f8)/2;
+		}
+
+		dx = abs(x - Xcf); dy = abs(y - 2 * l - Ycf); dz = abs(z - Zcf);	//Up
+		rc = dx+dy+dz;
+		if (rc*.1>3*l){
+			F[1] = (f1+f2)/2;
+			F[9] = (f1+f5)/2;
+			F[10] = MiddlePoint(f1,f2,f5,f6);
+			F[11] = (f2+f6)/2;
+			F[19] = (f5+f6)/2;
+		}
+
+		dx = abs(x - Xcf); dy = abs(y + 2 * l - Ycf); dz = abs(z - Zcf);	//Down
+		rc = dx+dy+dz;
+		if (rc*.1>3*l){
+			F[7] = (f3+f4)/2;
+			F[15] = (f3+f7)/2;
+			F[16] = MiddlePoint(f3,f4,f7,f8);
+			F[17] = (f4+f8)/2;
+			F[25] = (f7+f8)/2;
+		}
+
+		//Edges
+		dx = abs(x - Xcf); dy = abs(y - 2 * l - Ycf); dz = abs(z - 2 * l - Zcf);
+		rc = dx+dy+dz;
+		if (rc*.1>3*l){
+			F[1] = (f1+f2)/2;
+		}
+
+		dx = abs(x - Xcf); dy = abs(y + 2 * l - Ycf); dz = abs(z - 2 * l - Zcf);
+		rc = dx+dy+dz;
+		if (rc*.1>3*l){
+			F[7] = (f3+f4)/2;
+		}
+
+		dx = abs(x - Xcf); dy = abs(y - 2 * l - Ycf); dz = abs(z + 2 * l - Zcf);
+		rc = dx+dy+dz;
+		if (rc*.1>3*l){
+			F[19] = (f5+f6)/2;
+		}
+
+		dx = abs(x - Xcf); dy = abs(y + 2 * l - Ycf); dz = abs(z + 2 * l - Zcf);
+		rc = dx+dy+dz;
+		if (rc*.1>3*l){
+			F[25] = (f7+f8)/2;
+		}
+
+
+		dx = abs(x - 2 * l - Xcf); dy = abs(y - 2 * l - Ycf); dz = abs(z - Zcf);
+		rc = dx+dy+dz;
+		if (rc*.1>3*l){
+			F[9] = (f1+f5)/2;
+		}
+
+		dx = abs(x + 2 * l - Xcf); dy = abs(y - 2 * l - Ycf); dz = abs(z - Zcf);
+		rc = dx+dy+dz;
+		if (rc*.1>3*l){
+			F[11] = (f2+f6)/2;
+		}
+
+		dx = abs(x - 2 * l - Xcf); dy = abs(y + 2 * l - Ycf); dz = abs(z - Zcf);
+		rc = dx+dy+dz;
+		if (rc*.1>3*l){
+			F[15] = (f3+f7)/2;
+		}
+
+		dx = abs(x + 2 * l - Xcf); dy = abs(y + 2 * l - Ycf); dz = abs(z - Zcf);
+		rc = dx+dy+dz;
+		if (rc*.1>3*l){
+			F[17] = (f4+f8)/2;
+		}
+
+		dx = abs(x - 2 * l - Xcf); dy = abs(y - Ycf); dz = abs(z - 2 * l - Zcf);
+		rc = dx+dy+dz;
+		if (rc*.1>3*l){
+			F[3] = (f1+f3)/2;
+		}
+
+		dx = abs(x + 2 * l - Xcf); dy = abs(y - Ycf); dz = abs(z - 2 * l - Zcf);
+		rc = dx+dy+dz;
+		if (rc*.1>3*l){
+			F[5] = (f2+f4)/2;
+		}
+
+		dx = abs(x - 2 * l - Xcf); dy = abs(y - Ycf); dz = abs(z + 2 * l - Zcf);
+		rc = dx+dy+dz;
+		if (rc*.1>3*l){
+			F[21] = (f5+f7)/2;
+		}
+
+		dx = abs(x + 2 * l - Xcf); dy = abs(y - Ycf); dz = abs(z + 2 * l - Zcf);
+		rc = dx+dy+dz;
+		if (rc*.1>3*l){
+			F[23] = (f6+f8)/2;
+		}
+
+
+		l=l/2;
+		level+=1;
+
+		BuildCubeGrid (x-l, y-l, z-l,l,  F[0], F[1], F[3], F[4], F[9], F[10], F[12], F[13]);
+		BuildCubeGrid (x+l, y-l, z-l,l,  F[1], F[2], F[4], F[5], F[10], F[11], F[13], F[14]);
+		BuildCubeGrid (x-l, y+l, z-l,l,  F[3], F[4], F[6], F[7], F[12], F[13], F[15], F[16]);
+		BuildCubeGrid (x+l, y+l, z-l,l,  F[4], F[5], F[7], F[8], F[13], F[14], F[16], F[17]);
+		BuildCubeGrid (x-l, y-l, z+l,l,  F[9], F[10], F[12], F[13], F[18], F[19], F[21], F[22]);
+		BuildCubeGrid (x+l, y-l, z+l,l,  F[10], F[11], F[13], F[14], F[19], F[20], F[22], F[23]);
+		BuildCubeGrid (x-l, y+l, z+l,l,  F[12], F[13], F[15], F[16], F[21], F[22], F[24], F[25]);
+		BuildCubeGrid (x+l, y+l, z+l,l,  F[13], F[14], F[16], F[17], F[22], F[23], F[25], F[26]);
+
+		level-=1;
+	} else {
+		float F[8];
+		F[0] =f1;
+		F[1] =f2;
+		F[2] =f3;
+		F[3] =f4;
+		F[4] =f5;
+		F[5] =f6;
+		F[6] =f7;
+		F[7] =f8;
+
+
+		MarchingCube (x-l, y-l, z-l,x+l,y+l,z+l, F);
+	}
+
+}
+

+ 32 - 0
openb3dlib.mod/openb3d/src/voxterrain.h

@@ -0,0 +1,32 @@
+#ifndef VOXTERRAIN_H
+#define VOXTERRAIN_H
+
+#include "terrain.h"
+#include "metaball.h"
+
+class VoxelTerrain : public Terrain{
+
+private:
+	float ***tbuffer;
+
+	void MarchingCube(float x, float y, float z, float x1, float y1, float z1, float F[8]);
+	float MiddlePoint (float A, float B, float C, float D);
+	void BuildCubeGrid (float x, float y, float z, float l,
+		float f1, float f2, float f3, float f4, float f5, float f6, float f7, float f8);
+
+
+public:
+
+	static VoxelTerrain* CreateVoxelTerrain(int w=1, int h=1, int d=1, Entity* parent_ent=0);
+	static VoxelTerrain* LoadVoxelTerrain(string filename, Entity* parent_ent=0);
+	VoxelTerrain* CopyEntity(Entity* parent_ent=NULL);
+	void FreeEntity(void);
+
+	void RecreateOctree();
+	void UpdateTerrain();
+
+	void TreeCheck(CollisionInfo* ci);
+
+};
+
+#endif

+ 1 - 1
openb3dlib.mod/openb3d/src/x.cpp

@@ -419,7 +419,7 @@ Mesh* LoadX(string URL, Entity* parent_ent){
 										float x = vertx * tformmat.grid[0][0] + verty * tformmat.grid[0][1] + vertz * tformmat.grid[0][2] + tformmat.grid[0][3];
 										float y = vertx * tformmat.grid[1][0] + verty * tformmat.grid[1][1] + vertz * tformmat.grid[1][2] + tformmat.grid[1][3];
 										float z = vertx * tformmat.grid[2][0] + verty * tformmat.grid[2][1] + vertz * tformmat.grid[2][2] + tformmat.grid[2][3];
-										float w = tformmat.grid[3][0] + tformmat.grid[3][1] + tformmat.grid[3][2] + tformmat.grid[3][3];
+										//float w = tformmat.grid[3][0] + tformmat.grid[3][1] + tformmat.grid[3][2] + tformmat.grid[3][3];
 											
 										surf->AddVertex(x, y, z);
 									}

+ 3 - 0
openb3dlib.mod/openb3dlib.bmx

@@ -34,6 +34,9 @@ ModuleInfo "Copyright: Openb3d - Angelo Rosina"
 
 ModuleInfo "History: 1.00 Initial Release"
 
+ModuleInfo "CC_OPTS: -DOPENB3D_GLEW"
+ModuleInfo "CC_OPTS: -DOPENB3D_BMX"
+
 ?win32
 Import Pub.Glew
 Import Pub.OpenGL ' order is important, glew before OpenGL

+ 1 - 1
openb3dlib.mod/source.bmx

@@ -41,13 +41,13 @@ Import "openb3d/src/functions.cpp"
 Import "openb3d/src/geom.cpp"
 Import "openb3d/src/geosphere.cpp"
 Import "openb3d/src/global.cpp"
+Import "openb3d/src/isosurface.cpp"
 Import "openb3d/src/light.cpp"
 Import "openb3d/src/material.cpp"
 Import "openb3d/src/maths_helper.cpp"
 Import "openb3d/src/matrix.cpp"
 Import "openb3d/src/md2.cpp"
 Import "openb3d/src/mesh.cpp"
-Import "openb3d/src/metaball.cpp"
 Import "openb3d/src/model.cpp"
 Import "openb3d/src/octree.cpp"
 Import "openb3d/src/particle.cpp"