mikymod 12 yıl önce
ebeveyn
işleme
a68495a6cf

+ 13 - 15
engine/os/linux/OsWindow.cpp

@@ -42,12 +42,14 @@ void oswindow_set_window(Display* dpy, Window win)
 
 //-----------------------------------------------------------------------------
 OsWindow::OsWindow()
-	: m_resizable(true)
+	: m_x(0)
+	, m_y(0)
+	, m_width(0)
+	, m_height(0)
+	, m_resizable(true)
 	, m_x11_detectable_autorepeat(false)
 {
 	set_title("");
-
-	XGetWindowAttributes(m_x11_display, m_x11_window, &m_win_attr);
 }
 
 //-----------------------------------------------------------------------------
@@ -70,19 +72,15 @@ void OsWindow::hide()
 //-----------------------------------------------------------------------------
 void OsWindow::get_size(uint32_t& width, uint32_t& height)
 {
-	XGetWindowAttributes(m_x11_display, m_x11_window, &m_win_attr);
-
-	width = m_win_attr.width;
-	height = m_win_attr.height;
+	width = m_width;
+	height = m_height;
 }
 
 //-----------------------------------------------------------------------------
 void OsWindow::get_position(uint32_t& x, uint32_t& y)
 {
-	XGetWindowAttributes(m_x11_display, m_x11_window, &m_win_attr);
-
-	x = m_win_attr.x;
-	y = m_win_attr.y;
+	x = m_x;
+	y = m_y;
 }
 
 //-----------------------------------------------------------------------------
@@ -120,10 +118,10 @@ void OsWindow::set_resizable(bool resizable)
 {
 	XSizeHints hints;
 	hints.flags = PMinSize | PMaxSize;
-	hints.min_width = resizable ? 1 : m_win_attr.width;
-	hints.min_height = resizable ? 1 : m_win_attr.height;
-	hints.max_width = resizable ? 65535 : m_win_attr.width;
-	hints.max_height = resizable ? 65535 : m_win_attr.height;
+	hints.min_width = resizable ? 1 : m_width;
+	hints.min_height = resizable ? 1 : m_height;
+	hints.max_width = resizable ? 65535 : m_width;
+	hints.max_height = resizable ? 65535 : m_height;
 
 	XSetWMNormalHints(m_x11_display, m_x11_window, &hints);
 

+ 4 - 2
engine/os/linux/OsWindow.h

@@ -70,8 +70,10 @@ public:
 
 public:
 
-	XWindowAttributes m_win_attr;
-
+	uint32_t		m_x;
+	uint32_t		m_y;
+	uint32_t		m_width;
+	uint32_t		m_height;
 	bool			m_resizable;
 
 	bool			m_x11_detectable_autorepeat;

+ 4 - 4
engine/os/linux/main.cpp

@@ -325,10 +325,10 @@ public:
 				{
 					const OsMetricsEvent& ev = event.metrics;
 					m_mouse->set_metrics(ev.width, ev.height);
-					m_window->m_win_attr.x = ev.x;
-					m_window->m_win_attr.y = ev.y;
-					m_window->m_win_attr.width = ev.width;
-					m_window->m_win_attr.height = ev.height;
+					m_window->m_x = ev.x;
+					m_window->m_y = ev.y;
+					m_window->m_width = ev.width;
+					m_window->m_height = ev.height;
 					break;
 				}
 				case OsEvent::EXIT:

+ 22 - 8
engine/physics/Actor.cpp

@@ -43,6 +43,7 @@ using physx::PxVec3;
 using physx::PxReal;
 using physx::PxRigidBody;
 using physx::PxRigidDynamic;
+using physx::PxRigidStatic;
 using physx::PxPlaneGeometry;
 using physx::PxSphereGeometry;
 using physx::PxBoxGeometry;
@@ -64,6 +65,7 @@ Actor::Actor(PxScene* scene, SceneGraph& sg, int32_t node, ActorType::Enum type,
 	, m_type(type)
 {
 	Matrix4x4 m = sg.world_pose(node);
+
 	PxMat44 pose((PxReal*)(m.to_float_ptr()));
 
 	switch (type)
@@ -96,14 +98,17 @@ Actor::Actor(PxScene* scene, SceneGraph& sg, int32_t node, ActorType::Enum type,
 	
 	create_box(Vector3(0, 0, 0), .5, .5, .5);
 
-	PxRigidBodyExt::setMassAndUpdateInertia(*static_cast<PxRigidDynamic*>(m_actor), 500.0f);
-
-	PxD6Joint* joint = PxD6JointCreate(*device()->physx(), m_actor, PxTransform(pose), NULL, PxTransform(pose));
-	joint->setMotion(PxD6Axis::eX, PxD6Motion::eFREE);
-	joint->setMotion(PxD6Axis::eY, PxD6Motion::eFREE);
-	//joint->setMotion(PxD6Axis::eZ, PxD6Motion::eFREE);
-	//joint->setMotion(PxD6Axis::eSWING1, PxD6Motion::eFREE);
-	joint->setMotion(PxD6Axis::eSWING2, PxD6Motion::eFREE);
+	if (type == ActorType::DYNAMIC_PHYSICAL || type == ActorType::DYNAMIC_KINEMATIC)
+	{
+		PxRigidBodyExt::setMassAndUpdateInertia(*static_cast<PxRigidDynamic*>(m_actor), 500.0f);
+
+		PxD6Joint* joint = PxD6JointCreate(*device()->physx(), m_actor, PxTransform(pose), NULL, PxTransform(pose));
+		joint->setMotion(PxD6Axis::eX, PxD6Motion::eFREE);
+		joint->setMotion(PxD6Axis::eY, PxD6Motion::eFREE);
+		//joint->setMotion(PxD6Axis::eZ, PxD6Motion::eFREE);
+		//joint->setMotion(PxD6Axis::eSWING1, PxD6Motion::eFREE);
+		joint->setMotion(PxD6Axis::eSWING2, PxD6Motion::eFREE);
+	}
 
 	m_scene->addActor(*m_actor);
 }
@@ -248,6 +253,14 @@ void Actor::update_pose()
 
 	switch (m_type)
 	{
+		case ActorType::STATIC:
+		{
+			// m_actor->setGlobalPose(world_transform);
+		}
+		case ActorType::DYNAMIC_PHYSICAL:
+		{
+			break;
+		}
 		case ActorType::DYNAMIC_KINEMATIC:
 		{
 			static_cast<PxRigidDynamic*>(m_actor)->setKinematicTarget(world_transform);
@@ -260,6 +273,7 @@ void Actor::update_pose()
 //-----------------------------------------------------------------------------
 void Actor::update(const Matrix4x4& pose)
 {
+
 	if (m_type == ActorType::DYNAMIC_PHYSICAL)
 	{
 		m_scene_graph.set_world_pose(m_node, pose);

+ 13 - 0
engine/resource/PhysicsResource.cpp

@@ -37,6 +37,15 @@ namespace crown
 namespace physics_resource
 {
 
+static uint32_t actor_type_to_enum(const char* type)
+{
+	if (string::strcmp("static", type) == 0) return PhysicsActorType::STATIC;
+	else if (string::strcmp("dynamic_physical", type) == 0) return PhysicsActorType::DYNAMIC_PHYSICAL;
+	else if (string::strcmp("dynamic_kinematic", type) == 0) return PhysicsActorType::DYNAMIC_KINEMATIC;
+
+	CE_FATAL("Bad actor type");
+}
+
 static uint32_t shape_type_to_enum(const char* type)
 {
 	const StringId32 th = hash::murmur2_32(type, string::strlen(type));
@@ -89,15 +98,19 @@ void parse_actor(JSONElement e, PhysicsActor& actor, List<PhysicsShape>& actor_s
 {
 	JSONElement name = e.key("name");
 	JSONElement node = e.key("node");
+	JSONElement type = e.key("type");
 	JSONElement shapes = e.key("shapes");
 
 	DynamicString actor_name;
 	DynamicString actor_node;
+	DynamicString actor_type;
 	name.string_value(actor_name);
 	node.string_value(actor_node);
+	type.string_value(actor_type);
 
 	actor.name = hash::murmur2_32(actor_name.c_str(), actor_name.length());
 	actor.node = hash::murmur2_32(actor_node.c_str(), actor_node.length());
+	actor.type = actor_type_to_enum(actor_type.c_str());
 	actor.num_shapes = shapes.size();
 
 	for (uint32_t i = 0; i < actor.num_shapes; i++)

+ 11 - 0
engine/resource/PhysicsResource.h

@@ -54,10 +54,21 @@ struct PhysicsController
 	float contact_offset;	// Skin around the object within which contacts will be generated. Use it to avoid numerical precision issues.
 };
 
+struct PhysicsActorType
+{
+	enum Enum
+	{
+		STATIC,
+		DYNAMIC_PHYSICAL,
+		DYNAMIC_KINEMATIC
+	};
+};
+
 struct PhysicsActor
 {
 	StringId32 name;
 	StringId32 node;
+	uint32_t type;
 	uint32_t num_shapes;
 };
 

+ 2 - 1
engine/world/Unit.cpp

@@ -207,7 +207,8 @@ void Unit::create_physics_objects()
 		for (uint32_t i = 0; i < pr->num_actors(); i++)
 		{
 			const PhysicsActor actor = pr->actor(i);
-			add_actor(actor.name, m_world.physics_world()->create_actor(m_scene_graph, m_scene_graph.node(actor.node), ActorType::DYNAMIC_PHYSICAL));
+			Log::i("node: %d", m_scene_graph.node(actor.node));
+			add_actor(actor.name, m_world.physics_world()->create_actor(m_scene_graph, m_scene_graph.node(actor.node), (ActorType::Enum)actor.type));
 		}
 	}
 }

+ 6 - 0
engine/world/World.cpp

@@ -288,6 +288,12 @@ GuiId World::create_window_gui(const char* name)
 	return m_render_world.create_gui(gr);
 }
 
+//-----------------------------------------------------------------------------
+GuiId World::create_world_gui(const Matrix4x4 pose, const uint32_t width, const uint32_t height)
+{
+	// Must be implemented
+}
+
 //-----------------------------------------------------------------------------
 void World::destroy_gui(GuiId id)
 {

+ 1 - 0
engine/world/World.h

@@ -114,6 +114,7 @@ public:
 	void								set_sound_volume(SoundId sound, const float vol);
 
 	GuiId								create_window_gui(const char* name);
+	GuiId								create_world_gui(const Matrix4x4 pose, const uint32_t width, const uint32_t height);
 	void								destroy_gui(GuiId id);
 	Gui*								lookup_gui(GuiId id);