Skip to content

Commit

Permalink
Added in hub and gave it a collision mesh shape
Browse files Browse the repository at this point in the history
Raycasting doesn't work with collision mesh.
  • Loading branch information
adam4813 committed Jun 1, 2016
1 parent 160301c commit fb2b69d
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 3 deletions.
2 changes: 1 addition & 1 deletion assets
4 changes: 2 additions & 2 deletions client/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<float>(os.GetWindowWidth()), static_cast<float>(os.GetWindowHeight()));
/*tec::active_entity = ps.RayCastMousePick(connection.GetClientID(), mouse_x, mouse_y,
static_cast<float>(os.GetWindowWidth()), static_cast<float>(os.GetWindowHeight()));*/
//ps.DebugDraw();
if (camera_controller != nullptr) {
if (camera_controller->mouse_look) {
Expand Down
51 changes: 51 additions & 0 deletions client/test_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -34,6 +35,7 @@
#include <map>
#include <set>
#include <memory>
#include <BulletCollision/Gimpact/btGImpactShape.h>

#include "../proto/components.pb.h"

Expand Down Expand Up @@ -123,6 +125,8 @@ namespace tec {
AddFileFactory<ScriptFile>();
}

std::unique_ptr<btTriangleMesh> btmesh;

void BuildTestEntities() {
auto debug_shader_files = std::list < std::pair<Shader::ShaderType, FilePath> > {
std::make_pair(Shader::VERTEX, FilePath::GetAssetPath("shaders/debug.vert")),
Expand Down Expand Up @@ -172,6 +176,53 @@ namespace tec {
bob.Add<LuaScript>(script1);
}

{
Entity hub(105);
std::shared_ptr<OBJ> hub_mesh = OBJ::Create(FilePath::GetAssetPath("hub/hub.obj"));
Renderable* renderable = new Renderable();
renderable->mesh = hub_mesh;
renderable->shader = deferred_shader;
hub.Add<Renderable>(renderable);
Position* position = new Position(glm::vec3(0.0, -1.0, 0.0));
hub.Add<Position>(position);

CollisionBody* body = new CollisionBody();
btmesh = std::unique_ptr<btTriangleMesh>(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<btGImpactMeshShape>(btmesh.get());
shape->updateBound();
body->shape = shape;
body->shape->setLocalScaling(btVector3(1.0f, 1.0f, 1.0f));
body->entity_id = 105;
Multiton<eid, CollisionBody*>::Set(105, body);


proto::Entity e;
e.set_id(105);
hub.Out<Position>(e);

std::shared_ptr<EntityCreated> data = std::make_shared<EntityCreated>();
data->entity = e;
data->entity_id = 105;
EventSystem<EntityCreated>::Get()->Emit(data);
}

{
Entity vidstand(101);
std::shared_ptr<ComputerKeyboard> keybaord = std::make_shared<ComputerKeyboard>();
Expand Down

0 comments on commit fb2b69d

Please sign in to comment.