From a94557f5119ca5cac0ecf970b02180152af83f5d Mon Sep 17 00:00:00 2001 From: jonas Date: Mon, 4 Mar 2019 00:47:23 +0100 Subject: Started collision detection, working progress Move now triggers CheckCollision for every move action Hit direction detection still missing --- test.cpp | 48 +++++++++++------------------------------------- 1 file changed, 11 insertions(+), 37 deletions(-) (limited to 'test.cpp') diff --git a/test.cpp b/test.cpp index 313b632..7d0c9b9 100644 --- a/test.cpp +++ b/test.cpp @@ -32,6 +32,11 @@ public: drawPoint('Q', _pos, true, _COL_YELLOW); } + virtual bool onCollisionActive(unsigned int _hit, int _passiveObject){ + drawPoint('K', {0,0}, true, _COL_RED); + return true; + } + virtual void onChar(unsigned char _c) { drawPoint(_c, {1,1},true, _COL_BLUE); } private: int cc; @@ -42,7 +47,6 @@ int main(int argc, char* argv[]) cRender render(' ', _COL_DEFAULT, 30,30); cObjectHandler handler(&render); cObject ver(45,1); - cWiremesh obj; testobject obj2; cInput input; @@ -60,37 +64,15 @@ int main(int argc, char* argv[]) ver.drawText(DATE, {20,0}, _COL_WHITE); ver.drawText(VERSTRING, {0,0}, _COL_WHITE); int iver = handler.createObject(&ver); - handler.moveObject(iver, {0,0}, _MOVE_ABSOLUTE); - - int x = 15; - int y = 15; - int z = 30; - - obj.addVector({-x,-y,z}, {2*x,0,0}, '+', _COL_RED); - obj.addVector({-x,-y,z}, {0,2*y,0}, '+', _COL_RED); - obj.addVector({-x,y,z}, {2*x,0,0}, '+', _COL_RED); - obj.addVector({x,-y,z}, {0,2*y,0}, '+', _COL_RED); - - obj.addVector({-x,-y,0}, {0,0,z}, ':', _COL_RED); - obj.addVector({x,-y,0}, {0,0,z}, ':', _COL_RED); - obj.addVector({-x,y,0}, {0,0,z}, ':', _COL_RED); - obj.addVector({x,y,0}, {0,0,z}, ':', _COL_RED); - - obj.addVector({-x,-y,0}, {2*x,0,0}, ',', _COL_RED); - obj.addVector({-x,-y,0}, {0,2*y,0}, ',', _COL_RED); - obj.addVector({-x,y,0}, {2*x,0,0}, ',', _COL_RED); - obj.addVector({x,-x,0}, {0,2*y,0}, ',', _COL_RED); - int imesh = handler.createWiremesh(&obj); + handler.moveObject(iver, {0,0}, _MOVE_FORCE_ABSOLUTE); int iobj2 = handler.createObject((cObject*)&obj2); - handler.moveObject(iobj2, {3,3}, _MOVE_ABSOLUTE); + handler.moveObject(iobj2, {3,3}, _MOVE_FORCE_ABSOLUTE); sPos middle = render.getSize(); middle.x /= 2; middle.y /= 2; - handler.moveWiremesh(imesh,{middle.x,middle.y,0}, _MOVE_ABSOLUTE); - while( loop ) { sInputEvent ie = input.poll(); @@ -126,22 +108,16 @@ int main(int argc, char* argv[]) switch(ie.c) { case 'w': - handler.rotateWiremesh(imesh,{-10,0,0}); + handler.moveObject(iobj2, {0,-1}, _MOVE_RELATIVE); break; case 's': - handler.rotateWiremesh(imesh,{10,0,0}); + handler.moveObject(iobj2, {0,1}, _MOVE_RELATIVE); break; case 'a': - handler.rotateWiremesh(imesh,{0,-10,0}); + handler.moveObject(iobj2, {-1,0}, _MOVE_RELATIVE); break; case 'd': - handler.rotateWiremesh(imesh,{0,10,0}); - break; - case 'q': - handler.rotateWiremesh(imesh,{0,0,-10}); - break; - case 'e': - handler.rotateWiremesh(imesh,{0,0,10}); + handler.moveObject(iobj2, {1,0}, _MOVE_RELATIVE); break; }; } @@ -151,8 +127,6 @@ int main(int argc, char* argv[]) } } - handler.rotateWiremesh(imesh,{1,1,1}); - handler.write(); render.render(); framecounter++; -- cgit v1.2.3