Просмотр исходного кода

Vehicle physics, default shaders and material

Ivan Safrin 14 лет назад
Родитель
Сommit
69b72fe5a4

BIN
Assets/Default asset pack/default.pak


+ 107 - 0
Assets/Default asset pack/default/DefaultShader.frag

@@ -0,0 +1,107 @@
+float calculateAttenuation(in int i, in float dist)
+{
+    return(1.0 / (gl_LightSource[i].constantAttenuation +
+                  gl_LightSource[i].linearAttenuation * dist +
+                  gl_LightSource[i].quadraticAttenuation * dist * dist));
+}
+
+void pointLight(in int i, in vec3 N, in vec3 V, in float shininess,
+                inout vec4 ambient, inout vec4 diffuse, inout vec4 specular)
+{
+    vec3 D = gl_LightSource[i].position.xyz - V;
+    vec3 L = normalize(D);
+
+    float dist = length(D);
+    float attenuation = calculateAttenuation(i, dist);
+
+    float nDotL = dot(N,L);
+
+    if (nDotL > 0.0)
+    {   
+        vec3 E = normalize(-V);
+        vec3 R = reflect(-L, N);
+       
+        float pf = pow(max(dot(R,E), 0.0), shininess);
+
+        diffuse  += gl_LightSource[i].diffuse  * attenuation * nDotL;
+        specular += gl_LightSource[i].specular * attenuation * pf;
+    }
+   
+    ambient  += gl_LightSource[i].ambient * attenuation;
+}
+
+void spotLight(in int i, in vec3 N, in vec3 V, in float shininess,
+               inout vec4 ambient, inout vec4 diffuse, inout vec4 specular)
+{
+    vec3 D = gl_LightSource[i].position.xyz - V;
+    vec3 L = normalize(D);
+
+    float dist = length(D);
+    float attenuation = calculateAttenuation(i, dist);
+
+    float nDotL = dot(N,L);
+
+    if (nDotL > 0.0)
+    {   
+        float spotEffect = dot(normalize(gl_LightSource[i].spotDirection), -L);
+       
+        if (spotEffect > gl_LightSource[i].spotCosCutoff)
+        {
+            attenuation *=  pow(spotEffect, gl_LightSource[i].spotExponent);
+
+            vec3 E = normalize(-V);
+            vec3 R = reflect(-L, N);
+       
+            float pf = pow(max(dot(R,E), 0.0), shininess);
+
+            diffuse  += gl_LightSource[i].diffuse  * attenuation * nDotL;
+            specular += gl_LightSource[i].specular * attenuation * pf;
+        }
+    }
+   
+    ambient  += gl_LightSource[i].ambient * attenuation;
+}
+
+void calculateLighting(in int numLights, in vec3 N, in vec3 V, in float shininess,
+                       inout vec4 ambient, inout vec4 diffuse, inout vec4 specular)
+{
+    // Just loop through each light, and if its enabled add
+    // its contributions to the color of the pixel.
+    for (int i = 0; i < numLights; i++)
+    {
+		if (gl_LightSource[i].spotCutoff == 180.0)
+                pointLight(i, N, V, shininess, ambient, diffuse, specular);
+            else
+                 spotLight(i, N, V, shininess, ambient, diffuse, specular);
+
+    }
+}
+varying vec3 normal;
+varying vec3 vertex;
+varying vec4 vertexColor;
+void main()
+{
+    // Normalize the normal. A varying variable CANNOT
+    // be modified by a fragment shader. So a new variable
+    // needs to be created.
+    vec3 n = normalize(normal);
+   
+    vec4 ambient  = vec4(0.0);
+    vec4 diffuse  = vec4(0.0);
+    vec4 specular = vec4(0.0);
+
+    // In this case the built in uniform gl_MaxLights is used
+    // to denote the number of lights. A better option may be passing
+    // in the number of lights as a uniform or replacing the current
+    // value with a smaller value.
+    calculateLighting(1, n, vertex, gl_FrontMaterial.shininess,
+                      ambient, diffuse, specular);
+   
+    vec4 color = gl_FrontLightModelProduct.sceneColor  +
+                 (ambient  * 1.0) +
+                 (diffuse  * 1.0) +
+                 (specular * 0.0);
+    color = clamp(color*vertexColor, 0.0, 1.0);
+    color.a = vertexColor.a;
+    gl_FragColor = color;
+}

+ 10 - 0
Assets/Default asset pack/default/DefaultShader.vert

@@ -0,0 +1,10 @@
+varying vec3 normal;
+varying vec3 vertex;
+varying vec4 vertexColor;
+void main()
+{
+    normal = normalize(gl_NormalMatrix * gl_Normal);   
+    vertex = vec3(gl_ModelViewMatrix * gl_Vertex);     
+   vertexColor = gl_Color;
+    gl_Position = ftransform();
+}

+ 21 - 0
Assets/Default asset pack/default/default.mat

@@ -0,0 +1,21 @@
+<?xml version="1.0" ?>
+<tau>
+	<shaders>		
+		<shader type="glsl" name="DefaultShader">		
+			<vp source="DefaultShader.vert">
+				<params>
+				</params>
+			</vp>
+			<fp source="DefaultShader.frag">
+				<params>			
+				</params>					
+			</fp>
+		</shader>	
+	</shaders>
+	<materials>
+		<material name="default">
+			<shader name="DefaultShader">
+			</shader>
+		</material>		
+	</materials>
+</tau>

Разница между файлами не показана из-за своего большого размера
+ 192 - 402
Core/Build/Mac OS X/PolyCore.xcodeproj/project.xcworkspace/xcuserdata/ivansafrin.xcuserdatad/UserInterfaceState.xcuserstate


+ 18 - 1
Core/Contents/Include/PolyMesh.h

@@ -168,12 +168,29 @@ namespace Polycode {
 			void createBox(Number w, Number d, Number h);
 			
 			/**
-			* Creates a sphere mesh of specified size. (Not fully implemented!).
+			* Creates a sphere mesh of specified size.
 			* @param radius Radius of sphere.
 			* @param numRings Number of rings.	
 			* @param numSegments Number of segments.
 			*/ 						
 			void createSphere(Number radius, Number numRings, Number numSegments);
+
+			/**
+			* Creates a cylinder mesh.
+			* @param height Height of the cylinder.
+			* @param radius Radius of the cylinder.
+			* @param numSegments Number of segments.
+			*/ 								
+			void createCylinder(Number height, Number radius, int numSegments);
+
+			/**
+			* Creates a cone mesh.
+			* @param height Height of the cone.
+			* @param radius Radius of the cone.
+			* @param numSegments Number of segments.
+			*/ 								
+			void createCone(Number height, Number radius, int numSegments);
+
 		
 			/**
 			* Recenters the mesh with all vertices being as equidistant from origin as possible.

+ 9 - 0
Core/Contents/Include/PolyScenePrimitive.h

@@ -56,6 +56,15 @@ namespace Polycode {
 			* A sphere.
 			*/			
 			static const int TYPE_SPHERE = 2;
+			/**
+			* A cylinder.
+			*/			
+			static const int TYPE_CYLINDER = 3;
+			/**
+			* A cone.
+			*/			
+			static const int TYPE_CONE = 4;
+
 		
 		private:
 		

+ 3 - 0
Core/Contents/Source/PolyGLRenderer.cpp

@@ -685,12 +685,15 @@ void OpenGLRenderer::clearShader() {
 
 void OpenGLRenderer::setTexture(Texture *texture) {
 	if(texture == NULL) {
+		glActiveTexture(GL_TEXTURE0);		
 		glDisable(GL_TEXTURE_2D);
 		return;
 	}
 	
 	if(renderMode == RENDER_MODE_NORMAL) {
 		glEnable (GL_TEXTURE_2D);
+		glActiveTexture(GL_TEXTURE0);	
+		
 		if(currentTexture != texture) {			
 			OpenGLTexture *glTexture = (OpenGLTexture*)texture;
 			glBindTexture (GL_TEXTURE_2D, glTexture->getTextureID());

+ 123 - 0
Core/Contents/Source/PolyMesh.cpp

@@ -350,6 +350,129 @@ namespace Polycode {
 		
 	}
 
+	void Mesh::createCylinder(Number height, Number radius, int numSegments) {
+	
+		setMeshType(Mesh::TRI_MESH);
+		Number lastx = -1;
+		Number lastz = -1;		
+		for (int i=0 ; i < numSegments+1; i++) {
+			Number pos = ((PI*2.0)/((Number)numSegments)) * i;
+			Number x = sinf(pos) * radius;
+			Number z = cosf(pos) * radius;
+			
+			if(lastx > -1) {
+				Polygon *polygon = new Polygon();
+				polygon->addVertex(lastx,0,lastz,0,0);				
+				polygon->addVertex(x,0,z, 1, 0);
+				polygon->addVertex(x,height,z, 1, 1);				
+				addPolygon(polygon);							
+
+				polygon = new Polygon();	
+				polygon->addVertex(x,height,z, 1, 1);								
+				polygon->addVertex(lastx,height,lastz, 1, 1);																												
+				polygon->addVertex(lastx,0,lastz,0,0);												
+				addPolygon(polygon);	
+				
+				polygon = new Polygon();	
+				polygon->addVertex(lastx,height,lastz, 1, 1);				
+				polygon->addVertex(x,height,z, 1, 1);														
+				polygon->addVertex(0,height,0,0,0);							
+				addPolygon(polygon);			
+
+				polygon = new Polygon();	
+				polygon->addVertex(lastx,0,lastz, 1, 1);						
+				polygon->addVertex(0,0,0,0,0);																																					
+				polygon->addVertex(x,0,z, 1, 1);								
+				addPolygon(polygon);			
+
+								
+			}
+			lastx = x;
+			lastz = z;			
+		/*
+			Polygon *polygon = new Polygon();
+			polygon->addVertex(w,0,h, 1, 1);
+			polygon->addVertex(0,0,h, 1, 0);
+			polygon->addVertex(0,0,0,0,0);
+			polygon->addVertex(w,0,0,0,1);
+			addPolygon(polygon);			
+			*/
+        }
+		
+		for(int i=0; i < polygons.size(); i++) {
+			for(int j=0; j < polygons[i]->getVertexCount(); j++) {
+//				polygons[i]->getVertex(j)->x = polygons[i]->getVertex(j)->x - (radius/2.0f);
+				polygons[i]->getVertex(j)->y = polygons[i]->getVertex(j)->y - (height/2.0f);
+//				polygons[i]->getVertex(j)->z = polygons[i]->getVertex(j)->z - (radius/2.0f);	
+			}
+		}
+		
+		
+		calculateNormals();
+		arrayDirtyMap[RenderDataArray::VERTEX_DATA_ARRAY] = true;		
+		arrayDirtyMap[RenderDataArray::COLOR_DATA_ARRAY] = true;				
+		arrayDirtyMap[RenderDataArray::TEXCOORD_DATA_ARRAY] = true;						
+		arrayDirtyMap[RenderDataArray::NORMAL_DATA_ARRAY] = true;										
+		
+	}
+	
+	void Mesh::createCone(Number height, Number radius, int numSegments) {
+	
+	
+		setMeshType(Mesh::TRI_MESH);
+		Number lastx = -1;
+		Number lastz = -1;		
+		for (int i=0 ; i < numSegments+1; i++) {
+			Number pos = ((PI*2.0)/((Number)numSegments)) * i;
+			Number x = sinf(pos) * radius;
+			Number z = cosf(pos) * radius;
+			
+			if(lastx > -1) {
+				Polygon *polygon = new Polygon();
+				polygon->addVertex(lastx,0,lastz,0,0);				
+				polygon->addVertex(x,0,z, 1, 0);
+				polygon->addVertex(0,height,0, 1, 1);				
+				addPolygon(polygon);							
+			
+
+				polygon = new Polygon();	
+				polygon->addVertex(x,0,z, 1, 1);												
+				polygon->addVertex(lastx,0,lastz, 1, 1);																														
+				polygon->addVertex(0,0,0,0,0);												
+				addPolygon(polygon);			
+
+								
+			}
+			lastx = x;
+			lastz = z;			
+		/*
+			Polygon *polygon = new Polygon();
+			polygon->addVertex(w,0,h, 1, 1);
+			polygon->addVertex(0,0,h, 1, 0);
+			polygon->addVertex(0,0,0,0,0);
+			polygon->addVertex(w,0,0,0,1);
+			addPolygon(polygon);			
+			*/
+        }
+		
+		for(int i=0; i < polygons.size(); i++) {
+			for(int j=0; j < polygons[i]->getVertexCount(); j++) {
+//				polygons[i]->getVertex(j)->x = polygons[i]->getVertex(j)->x - (radius/2.0f);
+				polygons[i]->getVertex(j)->y = polygons[i]->getVertex(j)->y - (height/2.0f);
+//				polygons[i]->getVertex(j)->z = polygons[i]->getVertex(j)->z - (radius/2.0f);	
+			}
+		}
+		
+		
+		calculateNormals();
+		arrayDirtyMap[RenderDataArray::VERTEX_DATA_ARRAY] = true;		
+		arrayDirtyMap[RenderDataArray::COLOR_DATA_ARRAY] = true;				
+		arrayDirtyMap[RenderDataArray::TEXCOORD_DATA_ARRAY] = true;						
+		arrayDirtyMap[RenderDataArray::NORMAL_DATA_ARRAY] = true;										
+			
+	
+	}
+
 	void Mesh::createBox(Number w, Number d, Number h) {
 		Polygon *polygon = new Polygon();
 		polygon->addVertex(w,0,h, 1, 1);

+ 12 - 0
Core/Contents/Source/PolyScenePrimitive.cpp

@@ -45,6 +45,18 @@ ScenePrimitive::ScenePrimitive(int type, Number v1, Number v2, Number v3) : Scen
 			bBox.y = v2;
 			bBox.z = v3;						
 		break;
+		case TYPE_CYLINDER:
+			mesh->createCylinder(v1,v2,v3);
+			bBox.x = v2*2;
+			bBox.y = v1;
+			bBox.z = v2*2;						
+		break;		
+		case TYPE_CONE:
+			mesh->createCone(v1,v2,v3);
+			bBox.x = v2*2;
+			bBox.y = v1;
+			bBox.z = v2*2;						
+		break;				
 	}
 }
 

Разница между файлами не показана из-за своего большого размера
+ 354 - 363
Modules/Build/Mac OS X/Modules.xcodeproj/project.xcworkspace/xcuserdata/ivansafrin.xcuserdatad/UserInterfaceState.xcuserstate


+ 4 - 2
Modules/Contents/3DPhysics/Include/PolyCollisionSceneEntity.h

@@ -58,8 +58,10 @@ namespace Polycode {
 		static const int SHAPE_MESH = 3;			
 		static const int CHARACTER_CONTROLLER = 4;
 		static const int SHAPE_CAPSULE = 5;		
-		static const int SHAPE_PLANE = 6;		
-		
+		static const int SHAPE_PLANE = 6;
+		static const int SHAPE_CONE = 7;
+		static const int SHAPE_CYLINDER = 8;
+						
 			bool enabled;
 			btCollisionShape *shape;
 		

+ 2 - 0
Modules/Contents/3DPhysics/Include/PolyPhysicsScene.h

@@ -45,6 +45,8 @@ namespace Polycode {
 		PhysicsSceneEntity *trackPhysicsChild(SceneEntity *newEntity, int type=0, Number mass = 0.0f, Number friction=1, Number restitution=0, int group=1);		
 		
 		PhysicsCharacter *addCharacterChild(SceneEntity *newEntity, Number mass, Number friction, Number stepSize, int group  = 1);
+		
+		PhysicsVehicle *addVehicleChild(SceneEntity *newEntity, Number mass, Number friction, int group  = 1);
 
 		
 	protected:

+ 33 - 1
Modules/Contents/3DPhysics/Include/PolyPhysicsSceneEntity.h

@@ -48,13 +48,17 @@ namespace Polycode {
 		
 		int getType() { return type; }	
 		
+		
 		static const int SHAPE_BOX = 0;
 		static const int SHAPE_TERRAIN = 1;
 		static const int SHAPE_SPHERE = 2;	
 		static const int SHAPE_MESH = 3;			
 		static const int CHARACTER_CONTROLLER = 4;
 		static const int SHAPE_CAPSULE = 5;		
-		static const int SHAPE_PLANE = 6;		
+		static const int SHAPE_PLANE = 6;
+		static const int SHAPE_CONE = 7;
+		static const int SHAPE_CYLINDER = 8;						
+
 		
 		bool enabled;
 		
@@ -81,4 +85,32 @@ namespace Polycode {
 		
 		protected:
 	};
+	
+	class PhysicsVehicleWheelInfo {
+		public:
+			unsigned int wheelIndex;
+			SceneEntity *wheelEntity;
+	};
+	
+	class _PolyExport PhysicsVehicle : public PhysicsSceneEntity {
+		public:
+			PhysicsVehicle(SceneEntity *entity, Number mass, Number friction, btDefaultVehicleRaycaster *rayCaster);
+
+			void addWheel(SceneEntity *entity, Vector3 connection, Vector3 direction, Vector3 axle, Number suspentionRestLength, Number wheelRadius, bool isFrontWheel,Number suspensionStiffness = 20.0f, Number suspensionDamping = 1.0f, Number suspensionCompression = 4.0f, Number wheelFriction = 10000.0f, Number rollInfluence = 0.05f);
+			void applyEngineForce(Number force, unsigned int wheelIndex);
+			void setSteeringValue(Number value, unsigned int wheelIndex);
+			void setBrake(Number value, unsigned int wheelIndex);
+						
+			void Update();
+			virtual ~PhysicsVehicle();
+						
+		
+		btRaycastVehicle::btVehicleTuning tuning;
+		btDefaultVehicleRaycaster *rayCaster;
+		btRaycastVehicle *vehicle;
+		
+		protected:
+			vector<PhysicsVehicleWheelInfo> wheels;
+
+	};
 }

+ 14 - 1
Modules/Contents/3DPhysics/Source/PolyCollisionSceneEntity.cpp

@@ -67,6 +67,19 @@ btCollisionShape *CollisionSceneEntity::createCollisionShape(SceneEntity *entity
 		case CHARACTER_CONTROLLER:
 			collisionShape = new btCapsuleShape(entity->bBox.x/2.0f, entity->bBox.y/2.0f);			
 		break;
+		case SHAPE_CONE: {
+			Number largest = entity->bBox.x;
+			if(entity->bBox.z > largest) {
+				largest = entity->bBox.z;
+			}
+			collisionShape = new btConeShape(largest/2.0f, entity->bBox.y);					
+			}
+		break;
+		case SHAPE_CYLINDER:
+		{
+			collisionShape = new btCylinderShape(btVector3(entity->bBox.x/2.0f, entity->bBox.y/2.0f,entity->bBox.z/2.0f));
+		}
+		break;
 		case SHAPE_PLANE:
 			collisionShape = new btBoxShape(btVector3(entity->bBox.x/2.0f, entity->bBox.y/2.0f,0.1f));			
 			break;
@@ -94,7 +107,7 @@ btCollisionShape *CollisionSceneEntity::createCollisionShape(SceneEntity *entity
 				btConvexHullShape *hullShape = new btConvexHullShape();
 				for(int i=0; i < sceneMesh->getMesh()->getPolygonCount(); i++) {
 					Polygon *poly = sceneMesh->getMesh()->getPolygon(i);
-					for(int j=0; j < poly->getVertexCount(); j++) {					
+					for(int j=0; j < 3; j++) {					
 						hullShape->addPoint(btVector3((btScalar)poly->getVertex(j)->x, (btScalar)poly->getVertex(j)->y,(btScalar)poly->getVertex(j)->z));
 					}
 				}

+ 30 - 1
Modules/Contents/3DPhysics/Source/PolyPhysicsScene.cpp

@@ -66,7 +66,7 @@ void PhysicsScene::Update() {
 	Number elapsed = CoreServices::getInstance()->getCore()->getElapsed();
 	physicsWorld->stepSimulation(elapsed);	
 
-	
+	physicsWorld->debugDrawWorld();
 	CollisionScene::Update();
 	
 }
@@ -90,6 +90,35 @@ PhysicsCharacter *PhysicsScene::addCharacterChild(SceneEntity *newEntity,Number
 	
 }
 
+PhysicsVehicle *PhysicsScene::addVehicleChild(SceneEntity *newEntity, Number mass, Number friction, int group) {
+	addEntity(newEntity);		
+	
+	btDefaultVehicleRaycaster *m_vehicleRayCaster = new btDefaultVehicleRaycaster(physicsWorld);
+	
+	PhysicsVehicle *newPhysicsEntity = new PhysicsVehicle(newEntity, mass, friction,m_vehicleRayCaster);		
+	physicsWorld->addRigidBody(newPhysicsEntity->rigidBody, group, btBroadphaseProxy::StaticFilter|btBroadphaseProxy::DefaultFilter);	
+		
+	newPhysicsEntity->vehicle = new btRaycastVehicle(newPhysicsEntity->tuning,newPhysicsEntity->rigidBody,m_vehicleRayCaster);	
+	
+	newPhysicsEntity->rigidBody->setActivationState(DISABLE_DEACTIVATION);
+	
+		
+	int rightIndex = 0; 
+		int upIndex = 1; 
+		int forwardIndex = 2;
+			
+	physicsWorld->addVehicle(newPhysicsEntity->vehicle);
+	
+	newPhysicsEntity->vehicle->setCoordinateSystem(rightIndex,upIndex,forwardIndex);
+
+	newPhysicsEntity->vehicle->resetSuspension();
+
+	physicsChildren.push_back(newPhysicsEntity);
+	
+	return newPhysicsEntity;
+}
+
+
 PhysicsSceneEntity *PhysicsScene::trackPhysicsChild(SceneEntity *newEntity, int type, Number mass, Number friction, Number restitution, int group) {
 	PhysicsSceneEntity *newPhysicsEntity = new PhysicsSceneEntity(newEntity, type, mass, friction,restitution);
 	physicsWorld->addRigidBody(newPhysicsEntity->rigidBody, group, btBroadphaseProxy::StaticFilter|btBroadphaseProxy::DefaultFilter);	

+ 73 - 0
Modules/Contents/3DPhysics/Source/PolyPhysicsSceneEntity.cpp

@@ -24,6 +24,79 @@ THE SOFTWARE.
 
 using namespace Polycode;
 
+PhysicsVehicle::PhysicsVehicle(SceneEntity *entity, Number mass, Number friction,btDefaultVehicleRaycaster *rayCaster): PhysicsSceneEntity(entity, PhysicsSceneEntity::SHAPE_BOX, mass, friction, 1) {
+	
+}
+
+void PhysicsVehicle::addWheel(SceneEntity *entity, Vector3 connection, Vector3 direction, Vector3 axle, Number suspentionRestLength, Number wheelRadius, bool isFrontWheel,Number  suspensionStiffness, Number  suspensionDamping, Number suspensionCompression, Number  wheelFriction, Number rollInfluence) {
+	vehicle->addWheel(btVector3(connection.x, connection.y, connection.z),
+					btVector3(direction.x, direction.y, direction.z),
+					btVector3(axle.x, axle.y, axle.z),	
+					suspentionRestLength,
+					wheelRadius, 
+					tuning, 
+					isFrontWheel);
+					
+					
+					
+	PhysicsVehicleWheelInfo wheel_info;
+	wheel_info.wheelEntity = entity;
+	wheel_info.wheelIndex = wheels.size();
+	
+	
+			btWheelInfo& wheel = vehicle->getWheelInfo(wheel_info.wheelIndex);
+			wheel.m_suspensionStiffness = suspensionStiffness;
+			wheel.m_wheelsDampingRelaxation = suspensionDamping;
+			wheel.m_wheelsDampingCompression = suspensionCompression;
+			wheel.m_frictionSlip = wheelFriction;
+			wheel.m_rollInfluence = rollInfluence;
+	
+	
+	wheels.push_back(wheel_info);
+	
+}
+
+void PhysicsVehicle::setBrake(Number value, unsigned int wheelIndex) {
+	if ( wheelIndex < wheels.size()) {
+		vehicle->setBrake(value, wheelIndex);
+	}
+}
+
+void PhysicsVehicle::setSteeringValue(Number value, unsigned int wheelIndex) {
+	if ( wheelIndex < wheels.size()) {
+		vehicle->setSteeringValue(value, wheelIndex);
+	}
+}
+
+void PhysicsVehicle::applyEngineForce(Number force, unsigned int wheelIndex) {
+	if ( wheelIndex < wheels.size()) {
+		vehicle->applyEngineForce(force, wheelIndex);
+	}
+}
+
+void PhysicsVehicle::Update() {
+	Matrix4 m;
+	
+	for(int i=0; i < wheels.size(); i++) {	
+		PhysicsVehicleWheelInfo wheel_info = wheels[i];
+		vehicle->updateWheelTransform(i,true);
+		
+		btScalar mat[16];		
+//		vehicle->getWheelTransformWS(i).getOpenGLMatrix(mat);
+		vehicle->getWheelInfo(i).m_worldTransform.getOpenGLMatrix(mat);
+	
+		for(int j=0; j < 16; j++) {
+			m.ml[j] = mat[j];
+		}			
+		wheel_info.wheelEntity->setTransformByMatrixPure(m);		
+	}
+	
+	PhysicsSceneEntity::Update();
+}
+
+PhysicsVehicle::~PhysicsVehicle() {
+}
+
 PhysicsCharacter::PhysicsCharacter(SceneEntity *entity, Number mass, Number friction, Number stepSize) : PhysicsSceneEntity(entity, PhysicsSceneEntity::CHARACTER_CONTROLLER, mass, friction, 1) {	
 	ghostObject = new btPairCachingGhostObject();
 	

+ 20 - 8
Modules/Contents/GLSL/Source/PolyGLSLShaderModule.cpp

@@ -100,7 +100,12 @@ void GLSLShaderModule::setGLSLAreaLightPositionParameter(Renderer *renderer, GLS
 		vector<LightInfo> areaLights = renderer->getAreaLights();			
 		Vector3 lPos(areaLights[lightIndex].position.x,areaLights[lightIndex].position.y,areaLights[lightIndex].position.z);
 		GLfloat LightPosition[] = {lPos.x, lPos.y, lPos.z, 1};		
+		
 		glLightfv (GL_LIGHT0+lightIndex, GL_POSITION, LightPosition); //change the 	
+		
+//		glLightf(GL_LIGHT0+lightIndex, GL_CONSTANT_ATTENUATION, areaLights[lightIndex].distance);
+//		glLightf(GL_LIGHT0+lightIndex, GL_LINEAR_ATTENUATION, areaLights[lightIndex].intensity);			
+//		glLightf(GL_LIGHT0+lightIndex, GL_QUADRATIC_ATTENUATION, areaLights[lightIndex].intensity);					
 	} else {
 	}	
 }
@@ -332,24 +337,31 @@ bool GLSLShaderModule::applyShaderMaterial(Renderer *renderer, Material *materia
 		GLSLProgramParam param = glslShader->fp->params[i];
 		updateGLSLParam(renderer, param, material->getShaderBinding(shaderIndex), localOptions);
 	}	
-	glUseProgram(glslShader->shader_id);	
-	
-//	glActiveTexture(GL_TEXTURE0);
 	
+	glUseProgram(glslShader->shader_id);	
+	int textureIndex = 0;
 	for(int i=0; i < cgBinding->textures.size(); i++) {
 		int texture_location = glGetUniformLocation(glslShader->shader_id, cgBinding->textures[i].name.c_str());
-		glUniform1i(texture_location, 0);
+		glUniform1i(texture_location, textureIndex);
+		glActiveTexture(GL_TEXTURE0 + textureIndex);		
 		glBindTexture(GL_TEXTURE_2D, ((OpenGLTexture*)cgBinding->textures[i].texture)->getTextureID());	
+		textureIndex++;
 	}	
+		
 	
-	/*
+
 	//			Logger::log("applying %s (%s %s)\n", material->getShader()->getName().c_str(), cgShader->vp->getResourceName().c_str(), cgShader->fp->getResourceName().c_str());
 		
 	for(int i=0; i < cgBinding->cubemaps.size(); i++) {
-		cgGLSetTextureParameter(cgBinding->cubemaps[i].vpParam, ((OpenGLCubemap*)cgBinding->cubemaps[i].cubemap)->getTextureID());
-		cgGLEnableTextureParameter(cgBinding->cubemaps[i].vpParam);
+		int texture_location = glGetUniformLocation(glslShader->shader_id, cgBinding->cubemaps[i].name.c_str());
+		glUniform1i(texture_location, textureIndex);
+		
+		glActiveTexture(GL_TEXTURE0 + textureIndex);	
+			
+		glBindTexture(GL_TEXTURE_CUBE_MAP, ((OpenGLCubemap*)cgBinding->cubemaps[i].cubemap)->getTextureID());	
+		textureIndex++;
 	}
-	
+/*	
 	cgBinding = (GLSLShaderBinding*)localOptions;
 	for(int i=0; i < cgBinding->textures.size(); i++) {
 		cgGLSetTextureParameter(cgBinding->textures[i].vpParam, ((OpenGLTexture*)cgBinding->textures[i].texture)->getTextureID());

Разница между файлами не показана из-за своего большого размера
+ 145 - 144
Player/Build/Mac OS X/Polycode Player.xcodeproj/project.xcworkspace/xcuserdata/ivansafrin.xcuserdatad/UserInterfaceState.xcuserstate


Некоторые файлы не были показаны из-за большого количества измененных файлов