Commits

Anonymous committed 3f8a707

Updated python bindings
Fixed bugs

  • Participants
  • Parent commits 4423a81

Comments (0)

Files changed (14)

File PolyMain/include/game/PolyBoxColliderComponent.cpp

 
 #include "PolyPrerequisites.h"
 #include "physics/PolyPhysicsSystem.h"
-#include "PolyPhysicsComponent.h"
+#include "PolyPhysicsStaticComponent.h"
+#include "PolyPhysicsDynamicComponent.h"
 
 #include "PolyBoxColliderComponent.h"
 
 	}
 
 	void BoxColliderComponent::_notifyOtherComponentAdded(Component* other) {
-		if(other->getRuntimeTypeInfo().name != PhysicsComponent::GetTypeInfo().name)
+		// TODO too ugly
+		if(other->getRuntimeTypeInfo().name != PhysicsStaticComponent::GetTypeInfo().name
+			&& other->getRuntimeTypeInfo().name != PhysicsDynamicComponent::GetTypeInfo().name)
 			return;
 
 		physx::PxMaterial* defaultMaterial = gEnv.physics->getDefaultMaterial();

File PolyMain/include/game/PolyCharacterControllerComponent.cpp

 			controller->setPosition(physx::PxExtendedVec3(position.x + offset.x, position.y + offset.x, position.z + offset.x));
 		}
 	}
+
+	void CharacterControllerComponent::translate(const Vector3& offset) {
+		// TODO expose more options
+		const physx::PxControllerFilters filters;
+		controller->move(PhysicsUtil::convert(offset), 0.001f, 0.060f, filters);
+	}
+
+	void CharacterControllerComponent::setPosition(const Vector3& pos) {
+		controller->setPosition(physx::PxExtendedVec3(pos.x, pos.y, pos.z));
+	}
+
+	Vector3 CharacterControllerComponent::getPosition() const {
+		const physx::PxExtendedVec3& vec = controller->getPosition();
+		return Vector3(vec.x, vec.y, vec.z);
+	}
 }

File PolyMain/include/game/PolyCharacterControllerComponent.h

 
 		virtual void			initialize(Entity entity, const StringVariantMap& values);
 
+		void					translate(const Vector3& offset);
+
+		void					setPosition(const Vector3& pos);
+		Vector3					getPosition() const;
+
 		POLY_CLASS;
 	};
 }

File PolyMain/include/game/PolyMeshColliderComponent.cpp

 	}
 
 	void MeshColliderComponent::_notifyOtherComponentAdded(Component* other) {
-		// TODO fixme
+		// TODO too ugly
 		if(other->getRuntimeTypeInfo().name != PhysicsStaticComponent::GetTypeInfo().name
-			|| other->getRuntimeTypeInfo().name != PhysicsDynamicComponent::GetTypeInfo().name)
+			&& other->getRuntimeTypeInfo().name != PhysicsDynamicComponent::GetTypeInfo().name)
 			return;
 
 		// Cook mesh

File PolyMain/include/game/PolyTransformComponent.cpp

 		Component::initialize(entity, values);
 
 		sceneNode = entity.getLevel().getSceneMgr()->getRootSceneNode()->createChildSceneNode();
-		sceneNode->setPosition(values.get<Vector3>("Transform/Position", Vector3::ZERO));
-		sceneNode->setOrientation(values.get<Quaternion>("Transform/Orientation", Quaternion::IDENTITY));
-		sceneNode->setScale(values.get<Vector3>("Transform/Scale", Vector3::UNIT_SCALE));
+		sceneNode->setPosition(values.get<Vector3>("Position", Vector3::ZERO));
+		sceneNode->setOrientation(values.get<Quaternion>("Orientation", Quaternion::IDENTITY));
+		sceneNode->setScale(values.get<Vector3>("Scale", Vector3::UNIT_SCALE));
 	}
 
 	void TransformComponent::setParent(TransformComponent* other) {

File PolyPython/PolyPython.vcxproj

     <ClInclude Include="include\PolyPythonBindings.h" />
     <ClInclude Include="include\PolyPythonCoreBindings.h" />
     <ClInclude Include="include\PolyPythonGameBindings.h" />
+    <ClInclude Include="include\PolyPythonInputBindings.h" />
     <ClInclude Include="include\PolyPythonPhysicsBindings.h" />
     <ClInclude Include="include\PolyPythonPrerequisites.h" />
     <ClInclude Include="include\PolyPythonRenderBindings.h" />

File PolyPython/PolyPython.vcxproj.filters

     <ClInclude Include="include\PolyPythonGameBindings.h" />
     <ClInclude Include="include\PolyPythonCoreBindings.h" />
     <ClInclude Include="include\PolyPythonPhysicsBindings.h" />
+    <ClInclude Include="include\PolyPythonInputBindings.h" />
   </ItemGroup>
   <ItemGroup>
     <Filter Include="python">

File PolyPython/include/PolyPython.cpp

 			addNativeComponentType<CameraComponent>();
 			addNativeComponentType<PhysicsDynamicComponent>();
 			addNativeComponentType<PhysicsStaticComponent>();
+			addNativeComponentType<CharacterControllerComponent>();
 			addNativeComponentType<AudioListenerComponent>();
 			addNativeComponentType<BoxColliderComponent>();
 			addNativeComponentType<MeshColliderComponent>();

File PolyPython/include/PolyPythonBindings.cpp

 #include "PolyPythonRenderBindings.h"
 #include "PolyPythonPhysicsBindings.h"
 #include "PolyPythonGameBindings.h"
+#include "PolyPythonInputBindings.h"
 
 #include "PolyPythonBindings.h"
 
 	bindGame();
 	bindRender();
 	bindPhysics();
+	bindInput();
 
 	// Runtime environment
 	ComponentManager* componentMgr =  gEnv.componentMgr.get();
 	LevelManager* levelMgr = gEnv.levelMgr.get();
 	bp::scope().attr("levelMgr") = boost::ref(levelMgr); 
 
+	IInputSystem* input =  gEnv.input.get();
+	bp::scope().attr("input") = boost::ref(input); 
+
 	PhysicsSystem* physics =  gEnv.physics.get();
 	bp::scope().attr("physics") = boost::ref(physics); 
 }

File PolyPython/include/PolyPythonCoreBindings.h

 	bp::def("_log_hook", &logDefault);
 	bp::def("_log_error_hook", &logError);
 
-	bp::class_<Radian>("Radian");
+	bp::class_<Radian>("Radian", bp::init<float>());
 
 	bp::class_<Ray>("Ray", bp::init<>())
 		.add_property("origin",
 	v3.attr("NEGATIVE_UNIT_Y") = boost::ref(Vector3::NEGATIVE_UNIT_Y);
 	v3.attr("NEGATIVE_UNIT_Z") = boost::ref(Vector3::NEGATIVE_UNIT_Z);
 
+
 	bp::object q = bp::class_<Quaternion>("Quaternion", bp::init<>())
 		.def_readwrite("w", &Quaternion::w)
 		.def_readwrite("x", &Quaternion::x)
 		.def(bp::self - Quaternion())
 		.def(bp::self * Quaternion())
 		.def(bp::self * float())
+		.def(bp::self * Vector3())
 
 		.def("Dot", &Quaternion::Dot)
 		.def("normalise", &Quaternion::normalise)
 		;
 	q.attr("ZERO") = boost::ref(Quaternion::ZERO);
 	q.attr("IDENTITY") = boost::ref(Quaternion::IDENTITY);
+
+
+	bp::class_<ColourValue>("ColourValue", bp::init<>())
+		.def_readwrite("r", &ColourValue::r)
+		.def_readwrite("g", &ColourValue::g)
+		.def_readwrite("b", &ColourValue::b)
+		.def_readwrite("a", &ColourValue::a)
+
+		.def(bp::init<float, float, float>())
+		.def(bp::init<float, float, float, float>())
+		;
 }
 
 #endif

File PolyPython/include/PolyPythonGameBindings.h

 	self.addComponentType(typeName, factory);
 }
 
-Entity EntityManager_createEntity(EntityManager& self, Level level, const String& typeName) {
-	StringVariantMap _props;
+void parseStringValueMap(bp::dict& props, StringVariantMap& ret) {
+	bp::list keys = props.keys();
 
-	return self.createEntity(level, typeName, _props);
+	for(uint i = 0; i < bp::len(keys); ++i) {
+		bp::object key = keys[i];
+		bp::object val = props.get(key);
+
+		String typeName = bp::extract<String>(val.attr("__class__").attr("__name__"));
+		if(typeName == "dict") {
+			bp::dict innerProps = bp::extract<bp::dict>(val);
+			StringVariantMap innerRet;
+
+			parseStringValueMap(innerProps, innerRet);
+
+			ret[bp::extract<String>(key)] = innerRet;
+		}
+		else {
+			ret[bp::extract<String>(key)] = bp::extract<String>(bp::str(val));
+		}
+	}
+}
+
+Entity EntityManager_createEntity(EntityManager& self, Level level, const String& typeName, bp::dict& props) {
+	StringVariantMap ret;
+	parseStringValueMap(props, ret);
+
+	return self.createEntity(level, typeName, ret);
+}
+
+Entity EntityManager_createEntity_2(EntityManager& self, Level level, const String& typeName) {
+	return EntityManager_createEntity(self, level, typeName, bp::dict());
 }
 
 void bindGame() {
 	// Level
-	bp::class_<Level>("Level", bp::no_init);
+	bp::class_<Level>("Level", bp::no_init)
+		.add_property("sceneMgr", bp::make_function(&Level::getSceneMgr, bp::return_internal_reference<>()));
+		;
 
 	bp::class_<LevelManager, boost::noncopyable>("LevelManager", bp::no_init)
 		.def("createLevel", &LevelManager_createLevel);
 	bp::class_<TransformComponent, bp::bases<Component>>("TransformComponent")
 		.add_property("sceneNode", bp::make_getter(&TransformComponent::sceneNode, bp::return_internal_reference<>()));
 
+	bp::class_<CharacterControllerComponent, bp::bases<Component>>("CharacterControllerComponent")
+		.add_property("position",
+			&CharacterControllerComponent::getPosition,
+			&CharacterControllerComponent::setPosition)
+
+		.def("translate", &CharacterControllerComponent::translate);
+
 	// Entity
 	bp::class_<Entity>("Entity", bp::no_init)
 		.add_property("level", &Entity::getLevel)
 		.def("getComponent", &Entity_GetComponent)
 		.def("getComponent", &Entity_GetComponent_2);
 
-	bp::class_<EntityList>("EntityList")
-		.def("__iter__", bp::iterator<EntityList>())
-		.def("__len__", &EntityList::size);
+	bp::class_<EntityVector>("EntityList")
+		.def("__iter__", bp::iterator<EntityVector>())
+		.def("__len__", &EntityVector::size);
 
 	bp::class_<ComponentNameSet>("ComponentNameSet")
 		.def("add", &ComponentNameSet_add);
 	bp::class_<EntityManager, boost::noncopyable>("EntityManager", bp::no_init)
 		.def("addEntityLogic", &EntityManager::addEntityLogic)
 		
-		.def("createEntity", &EntityManager_createEntity);
+		.def("createEntity", &EntityManager_createEntity)
+		.def("createEntity", &EntityManager_createEntity_2);
 
 	// GameState
  	bp::class_<GameState, PythonGameState, GameStatePtr>("GameState")

File PolyPython/include/PolyPythonInputBindings.h

+/*
+    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 PolyPythonInputBindings_h
+#define PolyPythonInputBindings_h
+
+void bindInput() {
+	bp::enum_<KeyCode>("KeyCode")
+		.value("UNASSIGNED", KC_UNASSIGNED)
+		.value("ESCAPE", KC_ESCAPE)
+		.value("KEY1", KC_1)
+		.value("KEY2", KC_2)
+		.value("KEY3", KC_3)
+		.value("KEY4", KC_4)
+		.value("KEY5", KC_5)
+		.value("KEY6", KC_6)
+		.value("KEY7", KC_7)
+		.value("KEY8", KC_8)
+		.value("KEY9", KC_9)
+		.value("KEY0", KC_0)
+		.value("MINUS", KC_MINUS)
+		.value("EQUALS", KC_EQUALS)
+		.value("BACK", KC_BACK)
+		.value("TAB", KC_TAB)
+		.value("Q", KC_Q)
+		.value("W", KC_W)
+		.value("E", KC_E)
+		.value("R", KC_R)
+		.value("T", KC_T)
+		.value("Y", KC_Y)
+		.value("U", KC_U)
+		.value("I", KC_I)
+		.value("O", KC_O)
+		.value("P", KC_P)
+		.value("LBRACKET", KC_LBRACKET)
+		.value("RBRACKET", KC_RBRACKET)
+		.value("RETURN", KC_RETURN)
+		.value("LCONTROL", KC_LCONTROL)
+		.value("A", KC_A)
+		.value("S", KC_S)
+		.value("D", KC_D)
+		.value("F", KC_F)
+		.value("G", KC_G)
+		.value("H", KC_H)
+		.value("J", KC_J)
+		.value("K", KC_K)
+		.value("L", KC_L)
+		.value("SEMICOLON", KC_SEMICOLON)
+		.value("APOSTROPHE", KC_APOSTROPHE)
+		.value("GRAVE", KC_GRAVE)
+		.value("LSHIFT", KC_LSHIFT)
+		.value("BACKSLASH", KC_BACKSLASH)
+		.value("Z", KC_Z)
+		.value("X", KC_X)
+		.value("C", KC_C)
+		.value("V", KC_V)
+		.value("B", KC_B)
+		.value("N", KC_N)
+		.value("M", KC_M)
+		.value("COMMA", KC_COMMA)
+		.value("PERIOD", KC_PERIOD)
+		.value("SLASH", KC_SLASH)
+		.value("RSHIFT", KC_RSHIFT)
+		.value("MULTIPLY", KC_MULTIPLY)
+		.value("LMENU", KC_LMENU)
+		.value("SPACE", KC_SPACE)
+		.value("CAPITAL", KC_CAPITAL)
+		.value("F1", KC_F1)
+		.value("F2", KC_F2)
+		.value("F3", KC_F3)
+		.value("F4", KC_F4)
+		.value("F5", KC_F5)
+		.value("F6", KC_F6)
+		.value("F7", KC_F7)
+		.value("F8", KC_F8)
+		.value("F9", KC_F9)
+		.value("F10", KC_F10)
+		.value("NUMLOCK", KC_NUMLOCK)
+		.value("SCROLL", KC_SCROLL)
+		.value("NUMPAD7", KC_NUMPAD7)
+		.value("NUMPAD8", KC_NUMPAD8)
+		.value("NUMPAD9", KC_NUMPAD9)
+		.value("SUBTRACT", KC_SUBTRACT)
+		.value("NUMPAD4", KC_NUMPAD4)
+		.value("NUMPAD5", KC_NUMPAD5)
+		.value("NUMPAD6", KC_NUMPAD6)
+		.value("ADD", KC_ADD)
+		.value("NUMPAD1", KC_NUMPAD1)
+		.value("NUMPAD2", KC_NUMPAD2)
+		.value("NUMPAD3", KC_NUMPAD3)
+		.value("NUMPAD0", KC_NUMPAD0)
+		.value("DECIMAL", KC_DECIMAL)
+		.value("OEM_102", KC_OEM_102)
+		.value("F11", KC_F11)
+		.value("F12", KC_F12)
+		.value("F13", KC_F13)
+		.value("F14", KC_F14)
+		.value("F15", KC_F15)
+		.value("KANA", KC_KANA)
+		.value("ABNT_C1", KC_ABNT_C1)
+		.value("CONVERT", KC_CONVERT)
+		.value("NOCONVERT", KC_NOCONVERT)
+		.value("YEN", KC_YEN)
+		.value("ABNT_C2", KC_ABNT_C2)
+		.value("NUMPADEQUALS", KC_NUMPADEQUALS)
+		.value("PREVTRACK", KC_PREVTRACK)
+		.value("AT", KC_AT)
+		.value("COLON", KC_COLON)
+		.value("UNDERLINE", KC_UNDERLINE)
+		.value("KANJI", KC_KANJI)
+		.value("STOP", KC_STOP)
+		.value("AX", KC_AX)
+		.value("UNLABELED", KC_UNLABELED)
+		.value("NEXTTRACK", KC_NEXTTRACK)
+		.value("NUMPADENTER", KC_NUMPADENTER)
+		.value("RCONTROL", KC_RCONTROL)
+		.value("MUTE", KC_MUTE)
+		.value("CALCULATOR", KC_CALCULATOR)
+		.value("PLAYPAUSE", KC_PLAYPAUSE)
+		.value("MEDIASTOP", KC_MEDIASTOP)
+		.value("VOLUMEDOWN", KC_VOLUMEDOWN)
+		.value("VOLUMEUP", KC_VOLUMEUP)
+		.value("WEBHOME", KC_WEBHOME)
+		.value("NUMPADCOMMA", KC_NUMPADCOMMA)
+		.value("DIVIDE", KC_DIVIDE)
+		.value("SYSRQ", KC_SYSRQ)
+		.value("RMENU", KC_RMENU)
+		.value("PAUSE", KC_PAUSE)
+		.value("HOME", KC_HOME)
+		.value("UP", KC_UP)
+		.value("PGUP", KC_PGUP)
+		.value("LEFT", KC_LEFT)
+		.value("RIGHT", KC_RIGHT)
+		.value("END", KC_END)
+		.value("DOWN", KC_DOWN)
+		.value("PGDOWN", KC_PGDOWN)
+		.value("INSERT", KC_INSERT)
+		.value("DELETE", KC_DELETE)
+		.value("LWIN", KC_LWIN)
+		.value("RWIN", KC_RWIN)
+		.value("APPS", KC_APPS)
+		.value("POWER", KC_POWER)
+		.value("SLEEP", KC_SLEEP)
+		.value("WAKE", KC_WAKE)
+		.value("WEBSEARCH", KC_WEBSEARCH)
+		.value("WEBFAVORITES", KC_WEBFAVORITES)
+		.value("WEBREFRESH", KC_WEBREFRESH)
+		.value("WEBSTOP", KC_WEBSTOP)
+		.value("WEBFORWARD", KC_WEBFORWARD)
+		.value("WEBBACK", KC_WEBBACK)
+		.value("MYCOMPUTER", KC_MYCOMPUTER)
+		.value("MAIL", KC_MAIL)
+		.value("MEDIASELECT", KC_MEDIASELECT)
+		;
+
+	bp::class_<IInputKeyboard, boost::noncopyable>("IInputKeyboard", bp::no_init)
+		.def("isKeyDown", &IInputKeyboard::isKeyDown);
+
+	bp::class_<InputAxis>("InputAxis")
+		.def_readonly("abs", &InputAxis::abs)
+		.def_readonly("rel", &InputAxis::rel)
+		;
+
+	bp::class_<MouseState>("MouseState", bp::no_init)
+		.def_readonly("x", &MouseState::x)
+		.def_readonly("y", &MouseState::y)
+		.def_readonly("z", &MouseState::z)
+		;
+
+	bp::class_<IInputMouse, boost::noncopyable>("IInputMouse", bp::no_init)
+		.add_property("state", bp::make_function(&IInputMouse::getState, bp::return_value_policy<bp::copy_const_reference>()))
+		;
+
+	bp::class_<IInputSystem, boost::noncopyable>("IInputSystem", bp::no_init)
+		.add_property("mouse", bp::make_function(&IInputSystem::getMouse, bp::return_value_policy<bp::reference_existing_object>()))
+		.add_property("keyboard", bp::make_function(&IInputSystem::getKeyboard, bp::return_value_policy<bp::reference_existing_object>()));
+}
+
+#endif

File PolyPython/include/PolyPythonPhysicsBindings.h

 
 	bp::class_<PhysicsSystem, boost::noncopyable>("PhysicsSystem", bp::no_init)
 		.def("raycastSingle", (PhysicsRaycastHit(PhysicsSystem::*)(Level,const Ray&,float))&PhysicsSystem::raycastSingle)
+
+		.def("connectToVisualDebugger", &PhysicsSystem::connectToVisualDebugger)
 		;
 }
 

File PolyPython/include/PolyPythonRenderBindings.h

 		.def("pitch", &Ogre::Node::pitch)
 		.def("roll", &Ogre::Node::roll)
 
-		//.def("translate", (void(Ogre::Node::*)(const Vector3&))&Ogre::Node::translate)
 		.def("translate", (void(Ogre::Node::*)(const Vector3&, Ogre::Node::TransformSpace))&Ogre::Node::translate)
 		;
 
 		bp::scope s(node);
 
 		bp::enum_<Ogre::Node::TransformSpace>("TransformSpace")
-			.value("TS_LOCAL", Ogre::Node::TS_LOCAL)
-			.value("TS_PARENT", Ogre::Node::TS_PARENT)
-			.value("TS_WORLD", Ogre::Node::TS_WORLD)
+			.value("LOCAL", Ogre::Node::TS_LOCAL)
+			.value("PARENT", Ogre::Node::TS_PARENT)
+			.value("WORLD", Ogre::Node::TS_WORLD)
 			;
 	}
 
 	bp::class_<Ogre::SceneNode, bp::bases<Ogre::Node>, boost::noncopyable>("SceneNode", bp::no_init);
+
+	bp::class_<Ogre::SceneManager, boost::noncopyable>("SceneManager", bp::no_init)
+		.add_property("ambientLight",
+			bp::make_function(&Ogre::SceneManager::getAmbientLight, bp::return_value_policy<bp::copy_const_reference>()),
+			&Ogre::SceneManager::setAmbientLight);
 }
 
 #endif