From fb2b69d5c9ea14a9bc69fa87d804af96b84ac2ea Mon Sep 17 00:00:00 2001 From: Adam Martin Date: Wed, 1 Jun 2016 17:22:38 -0500 Subject: [PATCH] Added in hub and gave it a collision mesh shape Raycasting doesn't work with collision mesh. --- assets | 2 +- client/main.cpp | 4 ++-- client/test_data.cpp | 51 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+), 3 deletions(-) diff --git a/assets b/assets index 787bce36..1159b40a 160000 --- a/assets +++ b/assets @@ -1 +1 @@ -Subproject commit 787bce36c4d4cd606d19b49f21b05aaf2022640f +Subproject commit 1159b40a77ec65910c0d22094f938e062622057a diff --git a/client/main.cpp b/client/main.cpp index b415b184..33ec5e95 100644 --- a/client/main.cpp +++ b/client/main.cpp @@ -303,8 +303,8 @@ int main(int argc, char* argv[]) { lua_sys.Update(delta); os.GetMousePosition(&mouse_x, &mouse_y); - tec::active_entity = ps.RayCastMousePick(connection.GetClientID(), mouse_x, mouse_y, - static_cast(os.GetWindowWidth()), static_cast(os.GetWindowHeight())); + /*tec::active_entity = ps.RayCastMousePick(connection.GetClientID(), mouse_x, mouse_y, + static_cast(os.GetWindowWidth()), static_cast(os.GetWindowHeight()));*/ //ps.DebugDraw(); if (camera_controller != nullptr) { if (camera_controller->mouse_look) { diff --git a/client/test_data.cpp b/client/test_data.cpp index 18a026ba..d7d1b60e 100644 --- a/client/test_data.cpp +++ b/client/test_data.cpp @@ -14,6 +14,7 @@ #include "graphics/shader.hpp" #include "graphics/material.hpp" #include "graphics/texture-object.hpp" +#include "graphics/vertex-buffer-object.hpp" #include "graphics/animation.hpp" #include "graphics/lights.hpp" #include "graphics/view.hpp" @@ -34,6 +35,7 @@ #include #include #include +#include #include "../proto/components.pb.h" @@ -123,6 +125,8 @@ namespace tec { AddFileFactory(); } + std::unique_ptr btmesh; + void BuildTestEntities() { auto debug_shader_files = std::list < std::pair > { std::make_pair(Shader::VERTEX, FilePath::GetAssetPath("shaders/debug.vert")), @@ -172,6 +176,53 @@ namespace tec { bob.Add(script1); } + { + Entity hub(105); + std::shared_ptr hub_mesh = OBJ::Create(FilePath::GetAssetPath("hub/hub.obj")); + Renderable* renderable = new Renderable(); + renderable->mesh = hub_mesh; + renderable->shader = deferred_shader; + hub.Add(renderable); + Position* position = new Position(glm::vec3(0.0, -1.0, 0.0)); + hub.Add(position); + + CollisionBody* body = new CollisionBody(); + btmesh = std::unique_ptr(new btTriangleMesh()); + for (size_t mesh_i = 0; mesh_i < hub_mesh->GetMeshCount(); ++mesh_i) { + Mesh* mesh = hub_mesh->GetMesh(mesh_i); + for (ObjectGroup* objgroup : mesh->object_groups) { + btmesh->preallocateVertices(mesh->verts.size()); + btmesh->preallocateIndices(objgroup->indices.size()); + for (size_t face_i = 0; face_i < objgroup->indices.size(); ++face_i) { + const VertexData& v1 = mesh->verts[objgroup->indices[face_i]]; + const VertexData& v2 = mesh->verts[objgroup->indices[++face_i]]; + const VertexData& v3 = mesh->verts[objgroup->indices[++face_i]]; + btmesh->addTriangle( + btVector3(v1.position.x, v1.position.y, v1.position.z), + btVector3(v2.position.x, v2.position.y, v2.position.z), + btVector3(v3.position.x, v3.position.y, v3.position.z), false); + } + } + } + body->mass = 0.0f; + auto shape = std::make_shared(btmesh.get()); + shape->updateBound(); + body->shape = shape; + body->shape->setLocalScaling(btVector3(1.0f, 1.0f, 1.0f)); + body->entity_id = 105; + Multiton::Set(105, body); + + + proto::Entity e; + e.set_id(105); + hub.Out(e); + + std::shared_ptr data = std::make_shared(); + data->entity = e; + data->entity_id = 105; + EventSystem::Get()->Emit(data); + } + { Entity vidstand(101); std::shared_ptr keybaord = std::make_shared();