Skip to content

Commit

Permalink
adds MapEditor tool
Browse files Browse the repository at this point in the history
  • Loading branch information
Jerboa-app committed Dec 11, 2023
1 parent d808a4f commit d89ce07
Show file tree
Hide file tree
Showing 12 changed files with 553 additions and 66 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ else()
target_link_libraries(Hop glew zlibstatic FreeType glm stduuid ${GLEW_LIBRARIES} ${OPENGL_LIBRARIES} glfw Lua)
endif()

add_subdirectory(tools/)

IF (BUILD_DEMOS)

Expand Down
87 changes: 29 additions & 58 deletions demo/desktop/softBodyTetris/tetris.lua
Original file line number Diff line number Diff line change
@@ -1,68 +1,39 @@
require("mesh")

Square =
{
{-0.5, -0.5},
{-0.5, 0.5},
{0.5, 0.5},
{0.5, -0.5}
}

Long =
{
{-0.5, -0.5},
{-0.5, 1.0},
{0.25, 1.0},
{0.25, -0.5},
{-0.5, -0.5}
L_mesh = {
{0, 0, 0.5},
{1, 0, 0.5},
{-1, 0, 0.5},
{-2, 0, 0.5},
{-2, 1, 0.5},
{-2, 2, 0.5},
{-2, 3, 0.5},
{-2, 4, 0.5},
{-2, 5, 0.5},
{-1, 5, 0.5},
{0, 5, 0.5},
{0, 4, 0.5},
{0, 3, 0.5},
{0, 2, 0.5},
{1, 2, 0.5},
{1, 1, 0.5}
}


--S_mesh = createMesh(Square, 0.05)
L_mesh = createMesh(Long, 0.05)

s = 6.8*hop.maxCollisionPrimitiveSize()
s = hop.maxCollisionPrimitiveSize()

math.randomseed(os.time())

xx = 0.89-s;
xx = 0.5;
x = xx
y = 0.47;

for i = 1, 1 do

if (x > 1.5) then
x = xx
y = y + s*1.5
end
y = 0.5;

-- x = x + s*2.0
o = {

-- o = {
["transform"] = {x,y,0.0,s},
["colour"] = {200/255,250/255,250/255,1.0},
["moveable"] = true,
["collisionMesh"] = L_mesh,
["meshParameters"] = {10000.0, 10.0, 0.1},
["name"] = ""

-- ["transform"] = {x,y,0.0,s},
-- ["colour"] = {200/255,250/255,250/255,1.0},
-- ["moveable"] = true,
-- ["collisionMesh"] = S_mesh,
-- ["meshParameters"] = {10000.0, 10.0, 0.1},
-- ["name"] = ""

-- }

-- hop.loadObject(o)

x = x + s*2.0

o = {

["transform"] = {x,y,0.0,s},
["colour"] = {200/255,250/255,250/255,1.0},
["moveable"] = true,
["collisionMesh"] = L_mesh,
["meshParameters"] = {10000.0, 10.0, 0.1},
["name"] = ""

}
}

hop.loadObject(o)
end
hop.loadObject(o)
57 changes: 51 additions & 6 deletions include/Collision/collisionMesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ namespace Hop::System::Physics
virtual ~MeshPoint() = default;

double x; double y; double r;

bool operator==(const MeshPoint & rhs)
{
return x == rhs.x && y == rhs.y && r == rhs.r;
}
};

struct MeshRectangle : public MeshPoint
Expand Down Expand Up @@ -66,6 +71,18 @@ namespace Hop::System::Physics
r = std::sqrt(dx*dx+dy*dy);
}

bool operator==(const MeshRectangle & rhs)
{
return llx == rhs.llx &&
lly == rhs.lly &&
ulx == rhs.ulx &&
uly == rhs.uly &&
urx == rhs.urx &&
ury == rhs.ury &&
lrx == rhs.lrx &&
lry == rhs.lry;
}

double llx, lly, ulx, uly, urx, ury, lrx, lry;
};

Expand Down Expand Up @@ -329,6 +346,21 @@ namespace Hop::System::Physics

void add(std::shared_ptr<CollisionPrimitive> c)
{

auto circ = std::make_shared<MeshPoint>
(
c->x, c->y, c->r
);

for (auto c : vertices)
{
if (*c.get() == *circ.get())
{
return;
}
}


Rectangle * l = dynamic_cast<Rectangle*>(c.get());

std::shared_ptr<CollisionPrimitive> p;
Expand Down Expand Up @@ -368,10 +400,7 @@ namespace Hop::System::Physics
(
std::move
(
std::make_shared<MeshPoint>
(
c->x, c->y, c->r
)
circ
)
);
p = std::make_shared<CollisionPrimitive>
Expand All @@ -392,6 +421,24 @@ namespace Hop::System::Physics
needsInit = true;
}

int clicked(float x, float y)
{

for (int j = 0; j < int(worldVertices.size()); j++)
{
double rx = worldVertices[j]->x - x;
double ry = worldVertices[j]->y - y;
double d2 = rx*rx+ry*ry;

if (d2 < worldVertices[j]->r*worldVertices[j]->r)
{
return j;
}
}

return -1;
}

size_t size(){return vertices.size();}

std::shared_ptr<MeshPoint> getModelVertex(size_t i)
Expand All @@ -417,8 +464,6 @@ namespace Hop::System::Physics
{
return updateWorldMeshSoft(transform, dt);
}

needsInit = false;
}

void updateWorldMeshRigid(
Expand Down
11 changes: 10 additions & 1 deletion include/Component/cCollideable.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,16 @@ namespace Hop::Object::Component
mesh.updateWorldMesh(transform, dt);
}

void add(std::shared_ptr<CollisionPrimitive> c) { mesh.add(c); }
void add
(
std::shared_ptr<CollisionPrimitive> c,
cTransform & transform
)
{
mesh.add(c);
mesh.updateWorldMesh(transform, 0.0);
}

void remove(size_t i) { mesh.remove(i); }

};
Expand Down
8 changes: 8 additions & 0 deletions include/Display/display.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@ namespace Hop

void mousePosition(double & x, double & y){ if (glfwWindow != NULL){ glfwGetCursorPos(glfwWindow,&x,&y); } }

void setMousePosition(double x, double y)
{
if (glfwWindow != NULL)
{
glfwSetCursorPos(glfwWindow, x, y);
}
}

int getKeyLastState(int key) { return glfwGetKey(glfwWindow, key); }

void loop()
Expand Down
6 changes: 6 additions & 0 deletions include/orthoCam.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ namespace Hop::System::Rendering
return invProjection*ndc;
}

glm::vec2 worldToScreen(float x, float y)
{
glm::vec4 pos = vp*glm::vec4(x, y, 0.0, 1.0);
return glm::vec2( (pos.x+1.0)*resolution.x*0.5, -1.0*((pos.y+1.0)*resolution.y*0.5-resolution.y) );
}

glm::mat4 & getVP(){return vp;}

glm::mat4 getProjection() const {return projection;}
Expand Down
3 changes: 2 additions & 1 deletion src/Collision/collisionMesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ namespace Hop::System::Physics
}

computeRadius();
needsInit = false;
}

void CollisionMesh::centerOfMassWorld(double & cx, double & cy)
Expand Down Expand Up @@ -118,7 +119,6 @@ namespace Hop::System::Physics
double dt
)
{

if (needsInit)
{
modelToCenterOfMassFrame();
Expand Down Expand Up @@ -206,6 +206,7 @@ namespace Hop::System::Physics
}

computeRadius();
needsInit = false;

}

Expand Down
1 change: 1 addition & 0 deletions tools/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add_subdirectory(meshEditor)
26 changes: 26 additions & 0 deletions tools/meshEditor/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
set(OUTPUT_NAME MeshEditor)

include_directories(.)

if (WINDOWS)
add_compile_definitions(WINDOWS)

if (RELEASE)
# launch as windows, not console app - so cmd does not open as well
add_link_options(-mwindows)
endif ()
else ()
add_link_options(-no-pie)
endif()

add_executable(${OUTPUT_NAME} "main.cpp")

target_link_libraries(${OUTPUT_NAME} Hop)

set_target_properties(${OUTPUT_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${OUTPUT_NAME}")

file(GLOB LUA "*.lua")
file(GLOB MAP "*.hmap")

file(COPY ${LUA} DESTINATION "${CMAKE_BINARY_DIR}/${OUTPUT_NAME}/")
file(COPY ${MAP} DESTINATION "${CMAKE_BINARY_DIR}/${OUTPUT_NAME}/")
8 changes: 8 additions & 0 deletions tools/meshEditor/config.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
config =
{
["timeStep"] = 1.0/1800.0,
["subSample"] = 2,
["cofr"] = 0.75
}

hop.configure(config);
Loading

0 comments on commit d89ce07

Please sign in to comment.