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

Physics scene tweaks, Sprite editor preview now set to correct blending, will size correctly

Ivan Safrin 12 лет назад
Родитель
Сommit
8ffa458e82

+ 6 - 0
IDE/Contents/Source/PolycodeEntityEditor.cpp

@@ -441,6 +441,11 @@ Entity *EntityEditorMainView::getSelectedEntity() {
 
 void EntityEditorMainView::Paste(EntityEditorClipboardData *data) {
     
+    if(!hasFocus) {
+        return;
+    }
+    
+    
     selectNone(false);
     
     for(int i=0; i < data->entities.size(); i++) {
@@ -1635,6 +1640,7 @@ void PolycodeEntityEditor::saveShaderOptionsToEntry(ObjectEntry *entry, Material
 }
 
 String PolycodeEntityEditor::Copy(void **data) {
+    
     std::vector<Entity*> selectedEntities = mainView->getSelectedEntities();
     
     if(selectedEntities.size() > 0) {

+ 1 - 1
IDE/Contents/Source/PolycodeMeshEditor.cpp

@@ -124,7 +124,7 @@ void PolycodeMeshEditor::handleEvent(Event *event) {
 
 PolycodeMeshEditor::~PolycodeMeshEditor() {
     printf("CALLED IT!\n");
-    CoreServices::getInstance()->getResourceManager()->removeAllHandlersForListener(this);
+    CoreServices::getInstance()->getResourceManager()->getGlobalPool()->removeAllHandlersForListener(this);
 }
 
 bool PolycodeMeshEditor::openFile(OSFileEntry filePath) {

+ 4 - 1
IDE/Contents/Source/PolycodeSpriteEditor.cpp

@@ -177,7 +177,8 @@ void SpritePreviewProp::setPropWidth(Number width) {
 
 void SpritePreviewProp::setSprite(SceneSprite *sprite) {
 	previewSprite = sprite;
-	propContents->addChild(sprite);	
+	propContents->addChild(sprite);
+    setSpriteScale(1.0);
 }
 
 void SpritePreviewProp::setSpriteScale(Number scale) {
@@ -186,6 +187,7 @@ void SpritePreviewProp::setSpriteScale(Number scale) {
 	}
 	previewSprite->setScale(scale, scale);
 	setPropWidth(propWidth);
+    this->setHeight((previewSprite->getHeight() * scale) + 20);
 }
 
 SpriteAnimationsSheet::SpriteAnimationsSheet() : PropSheet("ANIMATIONS", "") {
@@ -363,6 +365,7 @@ bool PolycodeSpriteEditor::openFile(OSFileEntry filePath) {
 	initialLoad = true;
 		
 	previewSprite = new SceneSprite(filePath.fullPath);
+    previewSprite->setBlendingMode(Renderer::BLEND_MODE_NORMAL);
 	previewSprite->setAnchorPoint(-1.0, -1.0, 0.0);
 	previewSprite->setPosition(400, 80);				
 	previewSprite->getTexture()->reloadOnFileModify = true;	

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

@@ -128,6 +128,8 @@ namespace Polycode {
 		void applyImpulse(Entity *entity, Vector3 force, Vector3 point);
 		
 		PhysicsVehicle *addVehicleChild(Entity *newEntity, Number mass, Number friction, int group  = 1);
+
+		PhysicsVehicle *trackVehicleChild(Entity *newEntity, Number mass, Number friction, int group  = 1);
 		
 		void setGravity(Vector3 gravity);
 		

+ 24 - 18
Modules/Contents/3DPhysics/Source/PolyCollisionSceneEntity.cpp

@@ -87,40 +87,43 @@ btCollisionShape *CollisionEntity::createCollisionShape(Entity *entity, int type
 	
 	btCollisionShape *collisionShape = NULL;	
 	
-	Vector3 entityScale = entity->getScale();
-	Number largestScale = entityScale.x;
-	if(entityScale.y > largestScale)
-		largestScale = entityScale.y;
-	if(entityScale.z > largestScale)
-		largestScale = entityScale.z;
-
+    Vector3 scale = entity->getCompoundScale();
+    Vector3 bBox = entity->bBox;// * scale;
 	
+    Number largestSize = bBox.x;
+    if(bBox.y > largestSize) {
+        largestSize = bBox.y;
+    }
+    if(bBox.z > largestSize) {
+        largestSize = bBox.z;
+    }
+    
 	switch(type) {
 		case SHAPE_CAPSULE:
 		case CHARACTER_CONTROLLER:
-			collisionShape = new btCapsuleShape(entity->bBox.x/2.0f, entity->bBox.y/2.0f);			
+			collisionShape = new btCapsuleShape(bBox.x/2.0f, bBox.y/2.0f);
 		break;
 		case SHAPE_CONE: {
-			Number largest = entity->bBox.x;
-			if(entity->bBox.z > largest) {
-				largest = entity->bBox.z;
+			Number largest = bBox.x;
+			if(bBox.z > largest) {
+				largest = bBox.z;
 			}
-			collisionShape = new btConeShape(largest/2.0f, entity->bBox.y);					
+			collisionShape = new btConeShape(largest/2.0f, bBox.y);
 			}
 		break;
 		case SHAPE_CYLINDER:
 		{
-			collisionShape = new btCylinderShape(btVector3(entity->bBox.x/2.0, entity->bBox.y/2.0f,entity->bBox.z/2.0));
+			collisionShape = new btCylinderShape(btVector3(bBox.x/2.0, bBox.y/2.0f,bBox.z/2.0));
 		}
 		break;
 		case SHAPE_PLANE:
-			collisionShape = new btBoxShape(btVector3(entity->bBox.x/2.0f, 0.05,entity->bBox.z/2.0f));			
+			collisionShape = new btBoxShape(btVector3(bBox.x/2.0f, 0.05,bBox.z/2.0f));
 			break;
 		case SHAPE_BOX:
-			collisionShape = new btBoxShape(btVector3(entity->bBox.x/2.0f*entityScale.x, entity->bBox.y/2.0f*entityScale.y,entity->bBox.z/2.0f*entityScale.z));			
+			collisionShape = new btBoxShape(btVector3(bBox.x/2.0f, bBox.y/2.0f,bBox.z/2.0f));
 			break;
 		case SHAPE_SPHERE:
-			collisionShape = new btSphereShape(entity->bBox.x/2.0f*largestScale);
+			collisionShape = new btSphereShape(largestSize/2.0f);
 			break;
 		case SHAPE_MESH:
 		{
@@ -135,11 +138,14 @@ btCollisionShape *CollisionEntity::createCollisionShape(Entity *entity, int type
 				
 			} else {
 				Logger::log("Tried to make a mesh collision object from a non-mesh\n");
-				collisionShape = new btBoxShape(btVector3(entity->bBox.x/2.0f, entity->bBox.y/2.0f,entity->bBox.z/2.0f));			
+				collisionShape = new btBoxShape(btVector3(bBox.x/2.0f, bBox.y/2.0f,bBox.z/2.0f));
 			}
 		}
 		break;
-	}	
+	}
+    
+    collisionShape->setLocalScaling(btVector3(scale.x, scale.y, scale.z));
+    
 	return collisionShape; 
 }
 

+ 34 - 20
Modules/Contents/3DPhysics/Source/PolyPhysicsScene.cpp

@@ -231,34 +231,42 @@ void PhysicsScene::removeCharacterChild(PhysicsCharacter *character) {
 	
 }
 
-
-PhysicsVehicle *PhysicsScene::addVehicleChild(Entity *newEntity, Number mass, Number friction, int group) {
-	addEntity(newEntity);		
-	
+PhysicsVehicle *PhysicsScene::trackVehicleChild(Entity *newEntity, Number mass, Number friction, int group) {
+    
+    
 	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);	
+	PhysicsVehicle *newPhysicsEntity = new PhysicsVehicle(newEntity, mass, friction,m_vehicleRayCaster);
+    
+    newEntity->ignoreParentMatrix = true;
+    newEntity->setScale(newEntity->getCompoundScale());
+    
+	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;
-			
+    
+	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);
 	collisionChildren.push_back(newPhysicsEntity);
-		
-	return newPhysicsEntity;
+    
+ 	return newPhysicsEntity;
+}
+
+PhysicsVehicle *PhysicsScene::addVehicleChild(Entity *newEntity, Number mass, Number friction, int group) {
+	addEntity(newEntity);
+    return trackVehicleChild(newEntity, mass, friction, group);
 }
 
 void PhysicsScene::removePhysicsChild(Entity *entity) {
@@ -416,9 +424,15 @@ void PhysicsScene::wakeUp(Entity *entity) {
 
 PhysicsEntity *PhysicsScene::trackPhysicsChild(Entity *newEntity, int type, Number mass, Number friction, Number restitution, int group, bool compoundChildren) {
 	PhysicsEntity *newPhysicsEntity = new PhysicsEntity(newEntity, type, mass, friction,restitution, compoundChildren);
-	physicsWorld->addRigidBody(newPhysicsEntity->rigidBody, group,  btBroadphaseProxy::AllFilter); //btBroadphaseProxy::StaticFilter|btBroadphaseProxy::DefaultFilter);	
-//	world->addCollisionObject(newPhysicsEntity->collisionObject, group);	
-	//newPhysicsEntity->rigidBody->setActivationState(ISLAND_SLEEPING);	
+    
+    newEntity->ignoreParentMatrix = true;
+    newEntity->setScale(newEntity->getCompoundScale());
+    
+	physicsWorld->addRigidBody(newPhysicsEntity->rigidBody, group,  btBroadphaseProxy::AllFilter); //btBroadphaseProxy::StaticFilter|btBroadphaseProxy::DefaultFilter);
+    if(mass == 0.0) {
+//        world->addCollisionObject(newPhysicsEntity->collisionObject, group);
+    }
+	newPhysicsEntity->rigidBody->setActivationState(DISABLE_DEACTIVATION);	
 	physicsChildren.push_back(newPhysicsEntity);
 	collisionChildren.push_back(newPhysicsEntity);	
 	return newPhysicsEntity;	

+ 19 - 15
Modules/Contents/3DPhysics/Source/PolyPhysicsSceneEntity.cpp

@@ -45,7 +45,13 @@ void PhysicsVehicle::warpVehicle(Vector3 position) {
 }
 
 void PhysicsVehicle::addWheel(Entity *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),
+    entity->ignoreParentMatrix = true;
+    entity->setScale(entity->getCompoundScale());
+    
+    Vector3 vehicleScale = getEntity()->getScale();
+    btVector3 conn = btVector3(connection.x * vehicleScale.x, connection.y  * vehicleScale.y, connection.z * vehicleScale.z);
+    
+	vehicle->addWheel(conn,
 					btVector3(direction.x, direction.y, direction.z),
 					btVector3(axle.x, axle.y, axle.z),	
 					suspentionRestLength,
@@ -59,7 +65,6 @@ void PhysicsVehicle::addWheel(Entity *entity, Vector3 connection, Vector3 direct
 	wheel_info.wheelEntity = entity;
 	wheel_info.wheelIndex = wheels.size();
 	
-	
 			btWheelInfo& wheel = vehicle->getWheelInfo(wheel_info.wheelIndex);
 			wheel.m_suspensionStiffness = suspensionStiffness;
 			wheel.m_wheelsDampingRelaxation = suspensionDamping;
@@ -67,7 +72,6 @@ void PhysicsVehicle::addWheel(Entity *entity, Vector3 connection, Vector3 direct
 			wheel.m_frictionSlip = wheelFriction;
 			wheel.m_rollInfluence = rollInfluence;
 	
-	
 	wheels.push_back(wheel_info);
 	
 }
@@ -95,16 +99,11 @@ void PhysicsVehicle::Update() {
 	
 	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);		
+		vehicle->updateWheelTransform(i,true);        
+        btVector3 t = vehicle->getWheelInfo(i).m_worldTransform.getOrigin();
+        btQuaternion q = vehicle->getWheelInfo(i).m_worldTransform.getRotation();
+        wheel_info.wheelEntity->setRotationQuat(q.getW(), q.getX(), q.getY(), q.getZ());
+        wheel_info.wheelEntity->setPosition(t.getX(), t.getY(), t.getZ());
 	}
 	
 	PhysicsEntity::Update();
@@ -286,10 +285,15 @@ void PhysicsEntity::warpTo(Vector3 position, bool resetRotation) {
 			mat[i] = ent_mat.ml[i];
 		}	
 		transform.setFromOpenGLMatrix(mat);	
-	}
+	} else {
+        rigidBody->setAngularVelocity(btVector3());
+    }
 	
-	transform.setOrigin(btVector3(position.x,position.y,position.z));	
+	transform.setOrigin(btVector3(position.x,position.y,position.z));
+    
 	rigidBody->setCenterOfMassTransform(transform);
+    
+    
 }
 
 PhysicsEntity::~PhysicsEntity() {