aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar jonas <himself@jonasgunz.de> 2019-01-12 21:36:30 +0100
committerGravatar jonas <himself@jonasgunz.de> 2019-01-12 21:36:30 +0100
commit5d0b6dd79722707afb15642cc8523b36a6391e0d (patch)
treee7045bb0d5c2b25bbb4a2903ebb044c30b1b55d7
parent91e4ffec239c198c9c4652dc50812165813fe79f (diff)
downloadtermgl-5d0b6dd79722707afb15642cc8523b36a6391e0d.tar.gz
changed to cWiremesh, removed inherit, cWiremesh now directly writes to renderer
Things get funky when x > origin.x ?!?
-rw-r--r--Makefile2
-rw-r--r--cObject3D.cpp47
-rw-r--r--cObject3D.h50
-rw-r--r--cWiremesh.cpp68
-rw-r--r--cWiremesh.h66
-rw-r--r--main.cpp60
6 files changed, 170 insertions, 123 deletions
diff --git a/Makefile b/Makefile
index 879154c..3783295 100644
--- a/Makefile
+++ b/Makefile
@@ -7,7 +7,7 @@ BUILDDIR = build
VERSION = 0
PATCHLEVEL = 1
-OBJ = main.o cObject.o cObjectHandler.o cRender.o cInput.o cObject3D.o
+OBJ = main.o cObject.o cObjectHandler.o cRender.o cInput.o cWiremesh.o
debug: genversion $(OBJ)
mkdir -p $(BUILDDIR)
diff --git a/cObject3D.cpp b/cObject3D.cpp
deleted file mode 100644
index 7ba7132..0000000
--- a/cObject3D.cpp
+++ /dev/null
@@ -1,47 +0,0 @@
-#include "cObject3D.h"
-
-cObject3D::cObject3D(unsigned int _sx, unsigned int _sy)
-{
- setSize(_sx, _sy);
-}
-
-cObject3D::~cObject3D()
-{
- destruct();
-}
-
-void cObject3D::addVector(sCoord3d _origin, sCoord3d _vector, char _char, WORD _color)
-{
- vectors.push_back(sVector{_origin, _vector, _char, _color});
-}
-
-void cObject3D::rotate(sCoord3d _val)
-{
-
-}
-
-void cObject3D::reset()
-{
- vectors.clear();
-}
-
-void cObject3D::write()
-{
- for(long unsigned int i = 0; i < vectors.size(); i++)
- {
- drawLine(vectors[i].c,
- translate(vectors[i].origin),
- translate({vectors[i].origin.x + vectors[i].direction.x, vectors[i].origin.y + vectors[i].direction.y}),
- true, vectors[i].color);
- }
-}
-
-sPos cObject3D::translate(sCoord3d _coord)
-{
- sPos ret;
-
- ret.x = (int)((float)_coord.x - ((float)_coord.z / (float)_DEPTH * (float)_coord.x));
- ret.y = (int)((float)_coord.y - ((float)_coord.z / (float)_DEPTH * (float)_coord.y));
-
- return ret;
-}
diff --git a/cObject3D.h b/cObject3D.h
deleted file mode 100644
index 481b9a1..0000000
--- a/cObject3D.h
+++ /dev/null
@@ -1,50 +0,0 @@
-#pragma once
-
-#include <vector>
-
-#include "cObject.h"
-
-#define _DEPTH 50
-
-struct sCoord3d
-{
- int x;
- int y;
- int z;
-};
-
-struct sVector
-{
- sCoord3d origin;
- sCoord3d direction;
-
- char c;
- WORD color;
-};
-
-class cObject3D : cObject
-{
-public:
-
- cObject3D(unsigned int _sx, unsigned int _sy);
-
- virtual ~cObject3D();
-
- void addVector(sCoord3d _origin, sCoord3d _vector, char _char, WORD _color);
-
- void rotate(sCoord3d _val);
-
- void reset();
-
- void write();
-
-protected:
-
- cObject3D(){}
-
-private:
-
- sPos translate(sCoord3d _coord);
-
- std::vector<sVector> vectors;
-};
diff --git a/cWiremesh.cpp b/cWiremesh.cpp
new file mode 100644
index 0000000..f21b1d0
--- /dev/null
+++ b/cWiremesh.cpp
@@ -0,0 +1,68 @@
+#include "cWiremesh.h"
+
+cWiremesh::cWiremesh()
+{
+ position = {0,0,0};
+}
+
+cWiremesh::~cWiremesh()
+{
+
+}
+
+void cWiremesh::addVector(sCoord3d _origin, sCoord3d _vector, char _char, WORD _color)
+{
+ vectors.push_back(sVector{_origin, _vector, _char, _color});
+}
+
+void cWiremesh::rotate(sCoord3d _val)
+{
+
+}
+
+void cWiremesh::reset()
+{
+ vectors.clear();
+}
+
+void cWiremesh::write(cRender *_render)
+{
+ if(!_render)
+ return;
+
+ sPos porigin = _render->getSize();
+ sCoord3d origin = {porigin.x / 2, porigin.y / 2, 0};
+
+ for(long unsigned int i = 0; i < vectors.size(); i++)
+ {
+ _render->drawLine(vectors[i].c,
+ translate(vectors[i].origin + position, origin),
+ translate(vectors[i].origin + vectors[i].direction + position, origin),
+ true, vectors[i].color);
+ }
+}
+
+sPos cWiremesh::translate(sCoord3d _coord, sCoord3d _origin)
+{
+ sPos ret;
+
+ ret.x = (int)((float)_coord.x - ((float)_coord.z / (float)_DEPTH * (float)(_coord.x - _origin.x)));
+ ret.y = (int)((float)_coord.y - ((float)_coord.z / (float)_DEPTH * (float)(_coord.y - _origin.y)));
+
+ return ret;
+}
+
+sCoord3d cWiremesh::getPosition()
+{
+ return position;
+}
+
+void cWiremesh::setPosition(int _x, int _y, int _z)
+{
+ position = {_x, _y, _z};
+}
+
+void cWiremesh::setPosition(sCoord3d _pos)
+{
+ position = _pos;
+}
diff --git a/cWiremesh.h b/cWiremesh.h
new file mode 100644
index 0000000..49bf4b9
--- /dev/null
+++ b/cWiremesh.h
@@ -0,0 +1,66 @@
+#pragma once
+
+#include <vector>
+#include <cmath>
+
+#include "cRender.h"
+
+#define _DEPTH 100
+
+struct sCoord3d
+{
+ int x;
+ int y;
+ int z;
+
+ sCoord3d operator+(sCoord3d p)
+ {
+ sCoord3d ret;
+ ret.x = x + p.x;
+ ret.y = y + p.y;
+ ret.z = z + p.z;
+ return ret;
+ }
+};
+
+struct sVector
+{
+ sCoord3d origin;
+ sCoord3d direction;
+
+ char c;
+ WORD color;
+};
+
+class cWiremesh
+{
+public:
+
+ cWiremesh();
+
+ virtual ~cWiremesh();
+
+ void addVector(sCoord3d _origin, sCoord3d _vector, char _char, WORD _color);
+
+ void rotate(sCoord3d _val);
+
+ sCoord3d getPosition();
+
+ void setPosition(int _x, int _y, int _z);
+
+ void setPosition(sCoord3d _pos);
+
+ void reset();
+
+ void write(cRender *_render);
+
+protected:
+
+private:
+
+ sPos translate(sCoord3d _coord, sCoord3d _origin);
+
+ sCoord3d position;
+
+ std::vector<sVector> vectors;
+};
diff --git a/main.cpp b/main.cpp
index 9551bf3..e6bd74e 100644
--- a/main.cpp
+++ b/main.cpp
@@ -7,7 +7,7 @@
#include "cObject.h"
#include "cObjectHandler.h"
#include "cInput.h"
-#include "cObject3D.h"
+#include "cWiremesh.h"
#include "testobject.h"
@@ -16,14 +16,15 @@ int main()
cRender render(' ', _COL_DEFAULT, 30,30);
cObjectHandler handler(&render);
cObject ver(30,1);
- cObject3D obj(20,20);
+ cWiremesh obj;
cInput input;
+ render.render();
- int iobj = handler.createObject((cObject*)&obj);
- handler.moveObject(iobj, {40,10}, _MOVE_ABSOLUTE);
+ /*int iobj = handler.createObject((cObject*)&obj);
+ handler.moveObject(iobj, {40,10}, _MOVE_ABSOLUTE);*/
ver.drawPoint('v', {0,0}, true, _COL_WHITE);
ver.drawPoint(VERSION + 48, {1,0}, true, _COL_WHITE);
@@ -33,30 +34,34 @@ int main()
int iver = handler.createObject(&ver);
handler.moveObject(iver, {0,0}, _MOVE_ABSOLUTE);
- /*obj.addVector({0,0,0}, {5,0,0}, '#', _COL_RED);
- obj.addVector({5,0,0}, {0,5,0}, '#', _COL_RED);
- obj.addVector({0,0,0}, {0,5,0}, '#', _COL_RED);
- obj.addVector({0,5,0}, {5,0,0}, '#', _COL_RED);*/
+ int x = 25;
- obj.addVector({0,0,0}, {0,0,5}, '#', _COL_RED);
- obj.addVector({5,0,0}, {0,0,5}, '#', _COL_RED);
- obj.addVector({0,5,0}, {0,0,5}, '#', _COL_RED);
- obj.addVector({5,5,0}, {0,0,5}, '#', _COL_RED);
+ obj.addVector({0,0,x}, {x,0,0}, '+', _COL_RED);
+ obj.addVector({x,0,x}, {0,x,0}, '+', _COL_RED);
+ obj.addVector({0,0,x}, {0,x,0}, '+', _COL_RED);
+ obj.addVector({0,x,x}, {x,0,0}, '+', _COL_RED);
- /*obj.addVector({0,0,5}, {5,0,0}, '#', _COL_RED);
- obj.addVector({5,0,5}, {0,5,0}, '#', _COL_RED);
- obj.addVector({0,0,5}, {0,5,0}, '#', _COL_RED);
- obj.addVector({0,5,5}, {5,0,0}, '#', _COL_RED);*/
+ obj.addVector({0,0,0}, {0,0,x}, '.', _COL_RED);
+ obj.addVector({x,0,0}, {0,0,x}, '.', _COL_RED);
+ obj.addVector({0,x,0}, {0,0,x}, '.', _COL_RED);
+ obj.addVector({x,x,0}, {0,0,x}, '.', _COL_RED);
- obj.write();
+ obj.addVector({0,0,0}, {x,0,0}, '|', _COL_RED);
+ obj.addVector({x,0,0}, {0,x,0}, '|', _COL_RED);
+ obj.addVector({0,0,0}, {0,x,0}, '|', _COL_RED);
+ obj.addVector({0,x,0}, {x,0,0}, '|', _COL_RED);
handler.write();
- render.render();
+ obj.setPosition(0,0,0);
+ obj.write(&render);
- while(1);
- /*while(1)
+
+ render.render();
+ sCoord3d position = {0,0,0};
+ while(1)
{
sInputEvent ie = input.poll();
+
if(ie.type != _EVENT_NULL)
{
if(ie.type == _EVENT_KEY)
@@ -64,16 +69,20 @@ int main()
switch (ie.c)
{
case 'A'://up
- handler.moveObject(iobj, {0,-1}, _MOVE_RELATIVE);
+ position.y --;
+ obj.setPosition(position);
break;
case 'B'://down
- handler.moveObject(iobj, {0,1}, _MOVE_RELATIVE);
+ position.y ++;
+ obj.setPosition(position);
break;
case 'C'://right
- handler.moveObject(iobj, {1,0}, _MOVE_RELATIVE);
+ position.x ++;
+ obj.setPosition(position);
break;
case 'D'://left
- handler.moveObject(iobj, {-1,0}, _MOVE_RELATIVE);
+ position.x --;
+ obj.setPosition(position);
break;
};
}
@@ -92,12 +101,13 @@ int main()
}
handler.write();
+ obj.write(&render);
render.render();
usleep(10*1000);
}
}
- */
+
/*cRender a(' ', _COL_DEFAULT, 20,20);
cInput in;