diff options
author | Jonas Gunz <himself@jonasgunz.de> | 2019-01-12 01:00:56 +0100 |
---|---|---|
committer | Jonas Gunz <himself@jonasgunz.de> | 2019-01-12 01:00:56 +0100 |
commit | 91e4ffec239c198c9c4652dc50812165813fe79f (patch) | |
tree | 0f85ceedb3c2edac68ab34b8b5baaf903ce28935 | |
parent | bdce9a52170f1a3535c290a379e4cb9f509614ec (diff) | |
download | termgl-91e4ffec239c198c9c4652dc50812165813fe79f.tar.gz |
cObject3D should displaya wiremesh of Object composed of vectors
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | cObject3D.cpp | 47 | ||||
-rw-r--r-- | cObject3D.h | 50 | ||||
-rw-r--r-- | main.cpp | 31 |
4 files changed, 125 insertions, 5 deletions
@@ -7,7 +7,7 @@ BUILDDIR = build VERSION = 0 PATCHLEVEL = 1 -OBJ = main.o cObject.o cObjectHandler.o cRender.o cInput.o +OBJ = main.o cObject.o cObjectHandler.o cRender.o cInput.o cObject3D.o debug: genversion $(OBJ) mkdir -p $(BUILDDIR) diff --git a/cObject3D.cpp b/cObject3D.cpp new file mode 100644 index 0000000..7ba7132 --- /dev/null +++ b/cObject3D.cpp @@ -0,0 +1,47 @@ +#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 new file mode 100644 index 0000000..481b9a1 --- /dev/null +++ b/cObject3D.h @@ -0,0 +1,50 @@ +#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; +}; @@ -7,6 +7,7 @@ #include "cObject.h" #include "cObjectHandler.h" #include "cInput.h" +#include "cObject3D.h" #include "testobject.h" @@ -15,14 +16,14 @@ int main() cRender render(' ', _COL_DEFAULT, 30,30); cObjectHandler handler(&render); cObject ver(30,1); - testobject obj; + cObject3D obj(20,20); cInput input; - render.render(); + int iobj = handler.createObject((cObject*)&obj); - handler.moveObject(iobj, {10,10}, _MOVE_ABSOLUTE); + handler.moveObject(iobj, {40,10}, _MOVE_ABSOLUTE); ver.drawPoint('v', {0,0}, true, _COL_WHITE); ver.drawPoint(VERSION + 48, {1,0}, true, _COL_WHITE); @@ -32,7 +33,28 @@ int main() int iver = handler.createObject(&ver); handler.moveObject(iver, {0,0}, _MOVE_ABSOLUTE); - while(1) + /*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);*/ + + 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,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.write(); + + handler.write(); + render.render(); + + while(1); + /*while(1) { sInputEvent ie = input.poll(); if(ie.type != _EVENT_NULL) @@ -75,6 +97,7 @@ int main() usleep(10*1000); } } + */ /*cRender a(' ', _COL_DEFAULT, 20,20); cInput in; |