1. SirPolly
  2. PolyEngine

Commits

TWO  committed 5eacf98

Added BoxColliderComponent
Remove ShapeDesc from PhysicsComponent

  • Participants
  • Parent commits d19485b
  • Branches default

Comments (0)

Files changed (12)

File PolyMain/PolyMain.vcxproj

View file
  • Ignore whitespace
     <ClInclude Include="include\game\PolyLevelManager.h" />
     <ClInclude Include="include\game\PolyLightComponent.h" />
     <ClInclude Include="include\game\PolyMeshComponent.h" />
+    <ClInclude Include="include\game\PolyBoxColliderComponent.h" />
     <ClInclude Include="include\game\PolyPhysicsComponent.h" />
     <ClInclude Include="include\game\PolyPhysicsDynamicComponent.h" />
     <ClInclude Include="include\game\PolyPhysicsEntityLogic.h" />
     <ClCompile Include="include\core\PolySystemManager.cpp" />
     <ClCompile Include="include\core\PolyTaskManager.cpp" />
     <ClCompile Include="include\game\PolyAudioListenerComponent.cpp" />
+    <ClCompile Include="include\game\PolyBoxColliderComponent.cpp" />
     <ClCompile Include="include\game\PolyCameraComponent.cpp" />
     <ClCompile Include="include\game\PolyCharacterControllerComponent.cpp" />
     <ClCompile Include="include\game\PolyComponent.cpp" />

File PolyMain/PolyMain.vcxproj.filters

View file
  • Ignore whitespace
     <ClInclude Include="include\game\PolyCharacterControllerComponent.h">
       <Filter>game\phyics</Filter>
     </ClInclude>
+    <ClInclude Include="include\game\PolyBoxColliderComponent.h">
+      <Filter>game\phyics</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <ClCompile Include="include\PolyPrerequisites.cpp" />
     <ClCompile Include="include\game\PolyCharacterControllerComponent.cpp">
       <Filter>game\phyics</Filter>
     </ClCompile>
+    <ClCompile Include="include\game\PolyBoxColliderComponent.cpp">
+      <Filter>game\phyics</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <Filter Include="audio">

File PolyMain/include/game/PolyBoxColliderComponent.cpp

View file
  • Ignore whitespace
+/*
+    Copyright (c) Oliver 'SirPolly' Weitzel
+                                                                                  
+    Permission is hereby granted, free of charge, to any person obtaining a copy
+    of this software and associated documentation files (the "Software"), to deal
+    in the Software without restriction, including without limitation the rights
+    to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+    copies of the Software, and to permit persons to whom the Software is
+    furnished to do so, subject to the following conditions:
+                                                                                  
+    The above copyright notice and this permission notice shall be included in
+    all copies or substantial portions of the Software.
+                                                                                  
+    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+    THE SOFTWARE. 
+    
+*/
+
+#include "PolyPrerequisites.h"
+#include "physics/PolyPhysicsSystem.h"
+#include "PolyPhysicsComponent.h"
+
+#include "PolyBoxColliderComponent.h"
+
+
+namespace Poly {
+	POLY_COMPONENT_BASE_IMPL(BoxColliderComponent, "BoxCollider", "BoxCollider");
+
+	BoxColliderComponent::BoxColliderComponent() {
+		mProperties.addProperty("BoxCollider/Extends", &mExtends);
+		mProperties.addProperty("BoxCollider/Offset", &mOffset);
+	}
+
+	void BoxColliderComponent::_notifyOtherComponentAdded(Component* other) {
+		if(other->getFamilyName() != PhysicsComponent::GetFamilyName())
+			return;
+
+		physx::PxMaterial* defaultMaterial = gEnv.physics->getDefaultMaterial();
+
+		physx::PxTransform transform = PhysicsUtil::convert(mOffset, Quaternion::IDENTITY);
+
+		PhysicsComponent* physicsC = static_cast<PhysicsComponent*>(other);
+		physicsC->rigidActor->createShape(physx::PxBoxGeometry(mExtends.x, mExtends.y, mExtends.z), *defaultMaterial, transform);
+	}
+}

File PolyMain/include/game/PolyBoxColliderComponent.h

View file
  • Ignore whitespace
+/*
+    Copyright (c) Oliver 'SirPolly' Weitzel
+                                                                                  
+    Permission is hereby granted, free of charge, to any person obtaining a copy
+    of this software and associated documentation files (the "Software"), to deal
+    in the Software without restriction, including without limitation the rights
+    to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+    copies of the Software, and to permit persons to whom the Software is
+    furnished to do so, subject to the following conditions:
+                                                                                  
+    The above copyright notice and this permission notice shall be included in
+    all copies or substantial portions of the Software.
+                                                                                  
+    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+    THE SOFTWARE. 
+    
+*/
+
+#ifndef PolyBoxColliderComponent_h
+#define PolyBoxColliderComponent_h
+
+#include "PolyComponent.h"
+
+
+namespace Poly {
+	class _PolyExport BoxColliderComponent : public Component {
+	public:
+		BoxColliderComponent();
+
+		virtual void _notifyOtherComponentAdded(Component* other);
+
+		POLY_COMPONENT_BASE;
+
+	protected:
+		Vector3 mExtends;
+		Vector3 mOffset;
+	};
+}
+
+#endif

File PolyMain/include/game/PolyEntityManager.h

View file
  • Ignore whitespace
 
 		virtual uint		getUpdateBitMask() const;
 
+		// Implement ScriptTranslatorManager
 		size_t				getNumTranslators() const { return 1; }
-
 		Ogre::ScriptTranslator* getTranslator(const Ogre::AbstractNodePtr& node);
 
 	private:

File PolyMain/include/game/PolyGame.h

View file
  • Ignore whitespace
 #include "PolyMeshComponent.h"
 #include "PolyCameraComponent.h"
 #include "PolyLightComponent.h"
+#include "PolyBoxColliderComponent.h"
 #include "PolyPhysicsDynamicComponent.h"
 #include "PolyPhysicsStaticComponent.h"
 #include "PolyCharacterControllerComponent.h"

File PolyMain/include/game/PolyPhysicsComponent.cpp

View file
  • Ignore whitespace
 	POLY_COMPONENT_BASE_IMPL(PhysicsComponent, "Physics", "Physics");
 
 	PhysicsComponent::PhysicsComponent() {
-		mProperties.addProperty("Physics/ShapeDescription", &mShapeDescription, true);
-	}
-
-	void PhysicsComponent::parseAndCreateShapes(physx::PxRigidActor* rigidBody, const String& shapeDesc) {
-		physx::PxMaterial* defaultMaterial = gEnv.physics->getDefaultMaterial();
-
-
-		StringVector descs = StringUtil::split(shapeDesc, ";");
-
-		BOOST_FOREACH(const String& desc, descs) {
-			StringVector tokens = StringUtil::split(desc, ":");
-
-			if(tokens[0] == "Plane") {
-				Vector3 offset = Vector3::ZERO;
-				if(tokens.size() >= 3)
-					offset = StringConverter::parseVector3(tokens[2]);
-
-				physx::PxTransform transform = PhysicsUtil::convert(offset, Quaternion::IDENTITY);
-
-				rigidBody->createShape(physx::PxPlaneGeometry(), *defaultMaterial, transform);
-			}
-			else if(tokens[0] == "Box") {
-				Vector3 size = Vector3::UNIT_SCALE;
-				if(tokens.size() >= 2)
-					size = StringConverter::parseVector3(tokens[1]);
-
-				Vector3 offset = Vector3::ZERO;
-				if(tokens.size() >= 3)
-					offset = StringConverter::parseVector3(tokens[2]);
-
-				physx::PxTransform transform = PhysicsUtil::convert(offset, Quaternion::IDENTITY);
-
-				rigidBody->createShape(physx::PxBoxGeometry(size.x, size.y, size.z), *defaultMaterial, transform);
-			}
-			else if(tokens[0] == "Mesh") {
-				if(tokens.size() >= 2) {
-					Ogre::MeshPtr mesh = Ogre::MeshManager::getSingleton().getByName(tokens[1]);
-
-					RenderMeshInfo meshInfo;
-					RenderUtil::getMeshInfo(mesh, meshInfo);
-
-					PhysicsCookingParams params;
-					physx::PxTriangleMesh* physicsMesh = gEnv.physics->createTriangleMesh(meshInfo, params);
-
-					Vector3 offset = Vector3::ZERO;
-					if(tokens.size() >= 3)
-						offset = StringConverter::parseVector3(tokens[2]);
-
-					physx::PxTransform transform = PhysicsUtil::convert(offset, Quaternion::IDENTITY);
-
-					rigidBody->createShape(physx::PxTriangleMeshGeometry(physicsMesh), *defaultMaterial, transform);
-				}
-				else
-					POLY_LOG_CRITICAL("PhysicsComponent - Mesh shape without mesh name!");
-			}
-			else {
-				POLY_LOG_WARNING("Unknown physical shape desc: '" << desc << "'!");
-			}
-		}
 	}
 }

File PolyMain/include/game/PolyPhysicsComponent.h

View file
  • Ignore whitespace
 								POLY_COMPONENT_BASE;
 
 	protected:
-		String					mShapeDescription;
-
 								PhysicsComponent();
-
-		void					parseAndCreateShapes(physx::PxRigidActor* rigidBody, const String& shapeDesc);
 	};
 
 	POLY_INLINE void PhysicsComponent::setPosition(const Vector3& pos) {

File PolyMain/include/game/PolyPhysicsDynamicComponent.cpp

View file
  • Ignore whitespace
 		rigidActor = rigidDynamic = gEnv.physics->createDynamicRigidBody(Vector3::ZERO, Quaternion::IDENTITY, entity);
 		rigidDynamic->setRigidDynamicFlag(physx::PxRigidDynamicFlag::eKINEMATIC, mKinematic);
 
-		parseAndCreateShapes(rigidDynamic, mShapeDescription);
-
 		gEnv.physics->addRigidBodyToScene(mEntity.getScene(), rigidDynamic);
 	}
 

File PolyMain/include/game/PolyPhysicsStaticComponent.cpp

View file
  • Ignore whitespace
 
 		rigidActor = rigidStatic = gEnv.physics->createStaticRigidBody(Vector3::ZERO, Quaternion::IDENTITY, entity);
 
-		parseAndCreateShapes(rigidStatic, mShapeDescription);
-
 		gEnv.physics->addRigidBodyToScene(entity.getScene(), rigidStatic);
 	}
 }

File PolyMain/include/physics/PolyPhysicsSystem.cpp

View file
  • Ignore whitespace
 #include "core/PolyConfigurationManager.h"
 #include "game/PolyEntityManager.h"
 #include "game/PolyComponentManager.h"
+#include "game/PolyBoxColliderComponent.h"
 #include "game/PolyPhysicsDynamicComponent.h"
 #include "game/PolyPhysicsStaticComponent.h"
 #include "game/PolyCharacterControllerComponent.h"
 
 		gEnv.engine->addListener(this);
 
+		gEnv.componentMgr->addComponentType<BoxColliderComponent>();
 		gEnv.componentMgr->addComponentType<PhysicsDynamicComponent>();
 		gEnv.componentMgr->addComponentType<PhysicsStaticComponent>();
 		gEnv.componentMgr->addComponentType<CharacterControllerComponent>();

File PolyMain/include/util/PolyException.h

View file
  • Ignore whitespace
 }
 
 #ifndef POLY_EXCEPT
-#	define POLY_EXCEPT(num, desc, src) {throw ExceptionFactory::create(ExceptionCodeType<num>(), desc, src, __FILE__, __LINE__);}
+#	define POLY_EXCEPT(num, desc, src) {POLY_LOG_CRITICAL("Exception " << desc << " in " << src); \
+		throw ExceptionFactory::create(ExceptionCodeType<num>(), desc, src, __FILE__, __LINE__);}
 #endif
 
 #endif