summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Jonas Gunz <himself@jonasgunz.de> 2019-03-16 20:30:33 +0100
committerGravatar Jonas Gunz <himself@jonasgunz.de> 2019-03-16 20:30:33 +0100
commit4ed209d756c3cf719d8255c698d7988e85aa746a (patch)
tree0e596acc2904bcb76820ccc173283c3d716ba2b6
parented1837b54a35191a238703e73fd711a0995ff242 (diff)
downloadtermgl-4ed209d756c3cf719d8255c698d7988e85aa746a.tar.gz
Removed collision detection in Framebuffer #4
-rw-r--r--src/cObject.cpp2
-rw-r--r--src/cRender.cpp31
-rw-r--r--src/cRender.h7
-rw-r--r--src/cWiremesh.cpp2
4 files changed, 19 insertions, 23 deletions
diff --git a/src/cObject.cpp b/src/cObject.cpp
index 19f485f..a54d4e1 100644
--- a/src/cObject.cpp
+++ b/src/cObject.cpp
@@ -37,7 +37,7 @@ void cObject::write(cRender *_render, sPos _cameraPosition)
if (cScreen[p][o]) { //Dont overwrite empty pixels
sPos npos{ pos.x + (int)p - _cameraPosition.x,
pos.y + (int)o - _cameraPosition.y };
- _render->drawPoint(cScreen[p][o], npos, true, wColor[p][o]);
+ _render->drawPoint(cScreen[p][o], npos, wColor[p][o]);
}
}
}
diff --git a/src/cRender.cpp b/src/cRender.cpp
index 9d13b7c..cb3305d 100644
--- a/src/cRender.cpp
+++ b/src/cRender.cpp
@@ -74,14 +74,11 @@ cRender::~cRender()
#endif //__linux__
}
-int cRender::drawPoint(char _c, sPos _pos, bool _overrideCollision, WORD _color)
+int cRender::drawPoint(char _c, sPos _pos, WORD _color)
{
if (_pos.x >= (int)sizeX || _pos.y >= (int)sizeY || _pos.x < 0 || _pos.y < 0)
return _ERR_COORDINATES_INVALID_;
- if (_overrideCollision != true && cScreen[_pos.x][_pos.y] != cBackound) //detect Collsision
- return _COLLISION_;
-
cScreen[_pos.x][_pos.y] = _c;
if (_color == _COL_DEFAULT) //_COL_DEFAULT is NOT a proper colorcode!
wColor[_pos.x][_pos.y] = wDefColor;
@@ -94,24 +91,24 @@ int cRender::drawPoint(char _c, sPos _pos, bool _overrideCollision, WORD _color)
return 0;
}
-int cRender::drawLine(char _c, sPos _pos1, sPos _pos2, bool _overrideCollision, WORD _color)
+int cRender::drawLine(char _c, sPos _pos1, sPos _pos2, WORD _color)
{
if(_pos1.x > _pos2.x)
{
//Shit WILL go wrong
- return drawLine(_c, _pos2, _pos1, _overrideCollision, _color);
+ return drawLine(_c, _pos2, _pos1, _color);
}
if (_pos1.x == _pos2.x) { //Horizontal line
for (int i = _pos1.y; i <= _pos2.y; i++)
{
- drawPoint(_c, sPos{_pos1.x, i}, _overrideCollision, _color);
+ drawPoint(_c, sPos{_pos1.x, i}, _color);
}
}
else if (_pos1.y == _pos2.y) { //Vertical line
for (int i = _pos1.x; i <= _pos2.x; i++)
{
- drawPoint(_c, sPos{ i, _pos1.y }, _overrideCollision, _color);
+ drawPoint(_c, sPos{ i, _pos1.y }, _color);
}
}
else { //Diagonal Line
@@ -121,7 +118,7 @@ int cRender::drawLine(char _c, sPos _pos1, sPos _pos2, bool _overrideCollision,
for (int i = 0; i <= abs(dX); i++)
{
- drawPoint(_c, sPos{i + _pos1.x, (int)(i * fGradient + _pos1.y + 0.5)}, _overrideCollision, _color); //+0.5 for rounding error
+ drawPoint(_c, sPos{i + _pos1.x, (int)(i * fGradient + _pos1.y + 0.5)}, _color); //+0.5 for rounding error
if(std::abs(fGradient) > 1.0)
{
@@ -132,14 +129,14 @@ int cRender::drawLine(char _c, sPos _pos1, sPos _pos2, bool _overrideCollision,
drawLine(_c,
sPos{i + _pos1.x, (int)(i * fGradient + _pos1.y + 0.5)},
sPos{i + _pos1.x, (int)(i * fGradient + _pos1.y + 0.5) + dy },
- _overrideCollision, _color);
+ _color);
}//if
else if(dy < 0 && ((int)(i * fGradient + _pos1.y + 0.5) + dy) >= (_pos2.y) )
{
drawLine(_c,
sPos{i + _pos1.x, (int)(i * fGradient + _pos1.y + 0.5) + dy },
sPos{i + _pos1.x, (int)(i * fGradient + _pos1.y + 0.5)},
- _overrideCollision, _color);
+ _color);
}//else if
}//if
}//for
@@ -152,7 +149,7 @@ int cRender::drawText(string _s, sPos _pos, WORD _color)
{
for (unsigned int i = 0; i < _s.length(); i++)
{
- drawPoint(_s[i], sPos{ (int)i + _pos.x,_pos.y }, true, _color);
+ drawPoint(_s[i], sPos{ (int)i + _pos.x,_pos.y }, _color);
}
return 0;
}
@@ -160,16 +157,16 @@ int cRender::drawText(string _s, sPos _pos, WORD _color)
int cRender::drawRectangle(char _border, char _fill, sPos _pos1, sPos _pos2, WORD _borderColor, WORD _fillColor)
{
//Draw the four outside lines
- drawLine(_border, _pos1, sPos{ _pos1.x, _pos2.y }, true, _borderColor);
- drawLine(_border, _pos1, sPos{ _pos2.x, _pos1.y }, true, _borderColor);
- drawLine(_border, sPos{ _pos1.x, _pos2.y }, _pos2, true, _borderColor);
- drawLine(_border, sPos{ _pos2.x, _pos1.y }, _pos2, true, _borderColor);
+ drawLine(_border, _pos1, sPos{ _pos1.x, _pos2.y }, _borderColor);
+ drawLine(_border, _pos1, sPos{ _pos2.x, _pos1.y }, _borderColor);
+ drawLine(_border, sPos{ _pos1.x, _pos2.y }, _pos2, _borderColor);
+ drawLine(_border, sPos{ _pos2.x, _pos1.y }, _pos2, _borderColor);
//Fill rectangle if _fill isn't NULL
if (_fill) {
for (int i = _pos1.y + 1; i < _pos2.y; i++) {
for (int o = _pos1.x + 1; o < _pos2.x; o++) {
- drawPoint(_fill, sPos{ o,i }, true, _fillColor);
+ drawPoint(_fill, sPos{ o,i }, _fillColor);
}
}
}
diff --git a/src/cRender.h b/src/cRender.h
index d262791..6dd75fb 100644
--- a/src/cRender.h
+++ b/src/cRender.h
@@ -24,7 +24,6 @@
#define _ERR_RENDER_BLOCKED_BY_CHILD_ 3
#define _ERR_SCREEN_TOO_SMALL_ 4
-#define _COLLISION_ 255
//Colors
#ifdef _WIN32
@@ -79,14 +78,14 @@ public:
virtual ~cRender();
/** Draws _c @ _pos in screenbuffer
- * Returns _COLLOSION_ if _pos is already set to !cBackround && _overrideCollision isnt set
+ * Returns _COLLOSION_ if _pos is already set to !cBackround
*/
- int drawPoint(char _c, sPos _pos, bool _overrideCollision, WORD _color);
+ int drawPoint(char _c, sPos _pos, WORD _color);
/** draws Line from _pos1 to _pos2 in screenbuffer
* x Value of pos1 MUSTNT exceed the x value of pos2!
*/
- int drawLine(char _c, sPos _pos1, sPos _pos2, bool _overrideCollision, WORD _color);
+ int drawLine(char _c, sPos _pos1, sPos _pos2, WORD _color);
/** Draws Text _s @ _pos in screenbuffer
* First char is @ _pos
diff --git a/src/cWiremesh.cpp b/src/cWiremesh.cpp
index 62fee0d..537f98a 100644
--- a/src/cWiremesh.cpp
+++ b/src/cWiremesh.cpp
@@ -35,7 +35,7 @@ void cWiremesh::write(cRender *_render)
_render->drawLine(vectors[i].c,
translate(vorigin + position, origin),
translate(vorigin + vdirection + position, origin),
- true, vectors[i].color);
+ vectors[i].color);
}
}