From ca8fc412287ec8508012ab964de8df00ea8dbc07 Mon Sep 17 00:00:00 2001 From: Vulpovile Date: Sun, 14 Mar 2021 18:34:31 -0700 Subject: [PATCH] Finished surfaces --- Blocks3D.vcproj | 4 + src/include/DataModelV2/PartInstance.h | 1 + src/include/Faces.h | 9 + src/include/Renderer.h | 2 +- src/source/DataModelV2/PartInstance.cpp | 34 ++-- src/source/Renderer.cpp | 250 +++++++++++++++++++++++- 6 files changed, 280 insertions(+), 20 deletions(-) create mode 100644 src/include/Faces.h diff --git a/Blocks3D.vcproj b/Blocks3D.vcproj index 0b8ba5d..3727dad 100644 --- a/Blocks3D.vcproj +++ b/Blocks3D.vcproj @@ -669,6 +669,10 @@ RelativePath=".\src\include\ErrorFunctions.h" > + + diff --git a/src/include/DataModelV2/PartInstance.h b/src/include/DataModelV2/PartInstance.h index b61d66e..321b2c2 100644 --- a/src/include/DataModelV2/PartInstance.h +++ b/src/include/DataModelV2/PartInstance.h @@ -49,6 +49,7 @@ public: void setCFrame(CoordinateFrame); void setSize(Vector3); void setShape(Enum::Shape::Value shape); + void setChanged(); //Collision bool collides(PartInstance * part); diff --git a/src/include/Faces.h b/src/include/Faces.h new file mode 100644 index 0000000..9b5413d --- /dev/null +++ b/src/include/Faces.h @@ -0,0 +1,9 @@ +#ifndef FACES_H +#define FACES_H +#define TOP 0 +#define BOTTOM 1 +#define LEFT 2 +#define RIGHT 3 +#define FRONT 4 +#define BACK 5 +#endif \ No newline at end of file diff --git a/src/include/Renderer.h b/src/include/Renderer.h index cfa8735..37cc5d5 100644 --- a/src/include/Renderer.h +++ b/src/include/Renderer.h @@ -3,5 +3,5 @@ #include "Enum.h" #include "DataModelV2/Instance.h" void renderShape(const Enum::Shape::Value& shape, const Vector3& size, const Color3& ncolor); -void renderSurface(const char face, const Vector3& size, const Enum::SurfaceType::Value& surface, const Enum::Controller::Value& controller); +void renderSurface(const char face, const Enum::SurfaceType::Value& surface, const Vector3& size, const Enum::Controller::Value& controller, const Color3& color); #endif diff --git a/src/source/DataModelV2/PartInstance.cpp b/src/source/DataModelV2/PartInstance.cpp index edecc88..55c2ace 100644 --- a/src/source/DataModelV2/PartInstance.cpp +++ b/src/source/DataModelV2/PartInstance.cpp @@ -1,9 +1,9 @@ #include "DataModelV2/PartInstance.h" #include "Globals.h" -#include "../../Renderer.h" +#include "Renderer.h" #include #include - +#include "Faces.h" PartInstance::PartInstance(void) { @@ -18,12 +18,12 @@ PartInstance::PartInstance(void) color = Color3::gray(); velocity = Vector3(0,0,0); rotVelocity = Vector3(0,0,0); - top = Enum::SurfaceType::Smooth; - front = Enum::SurfaceType::Smooth; - right = Enum::SurfaceType::Smooth; - back = Enum::SurfaceType::Smooth; - left = Enum::SurfaceType::Smooth; - bottom = Enum::SurfaceType::Smooth; + top = Enum::SurfaceType::Bumps; + front = Enum::SurfaceType::Bumps; + right = Enum::SurfaceType::Bumps; + back = Enum::SurfaceType::Bumps; + left = Enum::SurfaceType::Bumps; + bottom = Enum::SurfaceType::Bumps; shape = Enum::Shape::Block; } @@ -77,6 +77,11 @@ void PartInstance::postRender(RenderDevice *rd) } } +void PartInstance::setChanged() +{ + changed = true; +} + void PartInstance::setParent(Instance* prnt) { Instance * cparent = getParent(); @@ -249,6 +254,12 @@ void PartInstance::render(RenderDevice* rd) { Vector3 renderSize = size/2; glNewList(glList, GL_COMPILE); renderShape(this->shape, renderSize, color); + renderSurface(TOP, this->top, renderSize, this->controller, color); + renderSurface(FRONT, this->front, renderSize, this->controller, color); + renderSurface(RIGHT, this->right, renderSize, this->controller, color); + renderSurface(BACK, this->back, renderSize, this->controller, color); + renderSurface(LEFT, this->left, renderSize, this->controller, color); + renderSurface(BOTTOM, this->bottom, renderSize, this->controller, color); glEndList(); } rd->setObjectToWorldMatrix(cFrame); @@ -289,15 +300,14 @@ static TCHAR* enumStr(int shape) void PartInstance::PropUpdate(LPPROPGRIDITEM &item) { + setChanged(); if(strcmp(item->lpszPropName, "Color3") == 0) { color = Color3(GetRValue(item->lpCurValue)/255.0F,GetGValue(item->lpCurValue)/255.0F,GetBValue(item->lpCurValue)/255.0F); - changed=true; } - if(strcmp(item->lpszPropName, "Anchored") == 0) + else if(strcmp(item->lpszPropName, "Anchored") == 0) { anchored= item->lpCurValue == TRUE; - changed=true; } else if(strcmp(item->lpszPropName, "Offset") == 0) { @@ -356,7 +366,7 @@ void PartInstance::PropUpdate(LPPROPGRIDITEM &item) setSize(size); } } - if(strcmp(item->lpszPropName, "Shape") == 0) + else if(strcmp(item->lpszPropName, "Shape") == 0) { printf("%s", enumStr(strEnum((TCHAR*)item->lpCurValue))); setShape(strEnum((TCHAR*)item->lpCurValue)); diff --git a/src/source/Renderer.cpp b/src/source/Renderer.cpp index bfacdba..85b20e1 100644 --- a/src/source/Renderer.cpp +++ b/src/source/Renderer.cpp @@ -1,5 +1,6 @@ #include "Renderer.h" #include +#include "Faces.h" float _bevelSize = 0.07F; std::vector _debugUniqueVertices; @@ -199,20 +200,23 @@ void renderShape(const Enum::Shape::Value& shape, const Vector3& size, const Col break; case Enum::Shape::Ball: glColor(ncolor); + glPushMatrix(); glScalef(size.x, size.y, size.z); gluSphere(gluNewQuadric(), 1, 20, 20); + glPopMatrix(); break; default: + GLUquadric * q = gluNewQuadric(); glColor(ncolor); glPushMatrix(); glScalef(size.x, size.y, size.z); glRotatef(90, 0, 1, 0); glTranslatef(0,0,1); - gluDisk(gluNewQuadric(), 0, 1, 12, 12); + gluDisk(q, 0, 1, 12, 12); glTranslatef(0,0,-2); - gluCylinder(gluNewQuadric(), 1, 1, 2, 12, 1); + gluCylinder(q, 1, 1, 2, 12, 1); glRotatef(180, 1, 0, 0); - gluDisk(gluNewQuadric(), 0, 1, 12, 12); + gluDisk(q, 0, 1, 12, 12); glPopMatrix(); /*Plusses, can possibly integrate into cylinder code later on*/ glVertexPointer(2, GL_FLOAT,0, square_arr); @@ -240,21 +244,253 @@ void renderShape(const Enum::Shape::Value& shape, const Vector3& size, const Col } } -void renderSurface(const char face, const Vector3& size, const Enum::SurfaceType::Value& surface, const Enum::Controller::Value& controller) +static G3D::Color3 getControllerColor(int controller) + { + switch(controller) + { + case Enum::Controller::KeyboardLeft: + return Color3::red(); + case Enum::Controller::KeyboardRight: + return Color3::blue(); + case Enum::Controller::Chase: + return Color3::black(); + case Enum::Controller::Flee: + return Color3::yellow(); + } + return Color3::gray(); + } + +void translateFace(const char face, const Vector3& size) { + //glTranslatef(0,0,size.z); + switch(face) + { + case TOP: + { + glTranslatef(0,size.y,0); + glRotatef(90,1,0,0); + } + break; + case BOTTOM: + { + glTranslatef(0,-size.y,0); + glRotatef(-90,1,0,0); + } + break; + case LEFT: + { + glTranslatef(size.x,0,0); + glRotatef(-90,0,1,0); + } + break; + case RIGHT: + { + glTranslatef(-size.x,0,0); + glRotatef(90,0,1,0); + } + break; + case FRONT: + { + glTranslatef(0,0,size.z); + glRotatef(-180,0,1,0); + } + break; + default: + { + glTranslatef(0,0,-size.z); + } + break; + } +} + +/*static const GLfloat bump[] = { + 0.5f, 0.25F, 0.5f, // Front-top-left + -0.5f, 0.25F, 0.5f, // Front-top-right + 0.5f, -0.25F, 0.5f, // Front-bottom-left + -0.5f, -0.25F, 0.5f, // Front-bottom-right + -0.5f, -0.25F, -0.5f, // Back-bottom-right + -0.5f, 0.25F, 0.5f, // Front-top-right + -0.5f, 0.25F, -0.5f, // Back-top-right + 0.5f, 0.25F, 0.5f, // Front-top-left + 0.5f, 0.25F, -0.5f, // Back-top-left + 0.5f, -0.25F, 0.5f, // Front-bottom-left + 0.5f, -0.25F, -0.5f, // Back-bottom-left + -0.5f, -0.25F, -0.5f, // Back-bottom-right + 0.5f, 0.25F, -0.5f, // Back-top-left + -0.5f, 0.25F, -0.5f // Back-top-right +};*/ + +static const int BMP_FACES = 5*2; +static const GLfloat bumpTriangles[] = { + //Top + -0.3F, 0.1F, -0.3F, + -0.3F, 0.1F, 0.3F, + 0.3F, 0.1F, -0.3F, + + 0.3F, 0.1F, -0.3F, + -0.3F, 0.1F, 0.3F, + 0.3F, 0.1F, 0.3F, + + + //Front + -0.3F, 0.1F, 0.3F, + -0.3F, -0.1F, 0.3F, + 0.3F, 0.1F, 0.3F, + + 0.3F, 0.1F, 0.3F, + -0.3F, -0.1F, 0.3F, + 0.3F, -0.1F, 0.3F, + + + //Back + -0.3F, -0.1F, -0.3F, + -0.3F, 0.1F, -0.3F, + 0.3F, -0.1F, -0.3F, + + 0.3F, -0.1F, -0.3F, + -0.3F, 0.1F, -0.3F, + 0.3F, 0.1F, -0.3F, + + + //Right + 0.3F, -0.1F, -0.3F, + 0.3F, 0.1F, -0.3F, + 0.3F, -0.1F, 0.3F, + + 0.3F, -0.1F, 0.3F, + 0.3F, 0.1F, -0.3F, + 0.3F, 0.1F, 0.3F, + + + //Left + -0.3F, 0.1F, -0.3F, + -0.3F, -0.1F, -0.3F, + -0.3F, 0.1F, 0.3F, + + -0.3F, 0.1F, 0.3F, + -0.3F, -0.1F, -0.3F, + -0.3F, -0.1F, 0.3F, +}; + +static const GLfloat bumpTriangleNormals[] = { + 0.000000F, 1.000000F, 0.000000F, + 0.000000F, 1.000000F, 0.000000F, + 0.000000F, 1.000000F, 0.000000F, + 0.000000F, 1.000000F, -0.000000F, + -0.000000F, 1.000000F, 0.000000F, + 0.000000F, 1.000000F, 0.000000F, + -0.000000F, 0.000000F, 1.000000F, + 0.000000F, 0.000000F, 1.000000F, + 0.000000F, 0.000000F, 1.000000F, + 0.000000F, 0.000000F, 1.000000F, + 0.000000F, 0.000000F, 1.000000F, + 0.000000F, -0.000000F, 1.000000F, + 0.000000F, 0.000000F, -1.000000F, + 0.000000F, 0.000000F, -1.000000F, + 0.000000F, 0.000000F, -1.000000F, + 0.000000F, 0.000000F, -1.000000F, + 0.000000F, 0.000000F, -1.000000F, + -0.000000F, -0.000000F, -1.000000F, + 1.000000F, 0.000000F, 0.000000F, + 1.000000F, 0.000000F, 0.000000F, + 1.000000F, 0.000000F, 0.000000F, + 1.000000F, -0.000000F, 0.000000F, + 1.000000F, 0.000000F, -0.000000F, + 1.000000F, 0.000000F, 0.000000F, + -1.000000F, 0.000000F, 0.000000F, + -1.000000F, 0.000000F, 0.000000F, + -1.000000F, 0.000000F, -0.000000F, + -1.000000F, -0.000000F, 0.000000F, + -1.000000F, 0.000000F, 0.000000F, + -1.000000F, 0.000000F, 0.000000F, +}; + + +void renderSurface(const char face, const Enum::SurfaceType::Value& surface, const Vector3& size, const Enum::Controller::Value& controller, const Color3& nColor) +{ + glPushMatrix(); + translateFace(face, size); switch(surface) { + case Enum::SurfaceType::Motor: + { + printf("MOTOR\n"); + glDisable(GL_LIGHTING); + glColor(getControllerColor(controller)); + GLUquadric * q = gluNewQuadric(); + gluQuadricNormals(q, GLU_NONE); + glPushMatrix(); + glTranslatef(0,0,-0.2F); + gluCylinder(q, 0.4F, 0.4F, 0.4F, 6, 1); + glTranslatef(0,0,0.4F); + gluDisk(q, 0, 0.4F, 6, 1); + glTranslatef(0,0,-0.4F); + glRotatef(180, 1, 0, 0); + gluDisk(q, 0, 0.4F, 6, 1); + glPopMatrix(); + } case Enum::SurfaceType::Hinge: { - + glDisable(GL_LIGHTING); + glColor3f(1,1,0); + GLUquadric * q = gluNewQuadric(); + gluQuadricNormals(q, GLU_NONE); + glPushMatrix(); + glTranslatef(0,0,-0.5F); + gluCylinder(q, 0.2F, 0.2F, 1, 6, 1); + glTranslatef(0,0,1); + gluDisk(q, 0, 0.2F, 6, 1); + glTranslatef(0,0,-1); + glRotatef(180, 1, 0, 0); + gluDisk(q, 0, 0.2F, 6, 1); + glPopMatrix(); + glEnable(GL_LIGHTING); } break; case Enum::SurfaceType::Bumps: { - + glRotatef(-90,1,0,0); + float x; + float y; + switch(face) + { + case TOP: + case BOTTOM: + x = size.x * 2; + y = size.z * 2; + break; + case LEFT: + case RIGHT: + y = size.y * 2; + x = size.z * 2; + break; + case FRONT: + case BACK: + x = size.x * 2; + y = size.y * 2; + break; + } + glTranslatef(-x/2+0.5F,0,-y/2+0.5F); + glColor(color); + glDisableClientState(GL_COLOR_ARRAY); + glVertexPointer(3, GL_FLOAT, 0, bumpTriangles); + glNormalPointer(GL_FLOAT, 0, bumpTriangleNormals); + for(float i = 0; i < y; i++) + { + glPushMatrix(); + for(float j = 0; j < x; j++) + { + glDrawArrays(GL_TRIANGLES, 0, 30); + glTranslatef(1,0,0); + } + glPopMatrix(); + glTranslatef(0,0,1); + } + glEnableClientState(GL_COLOR_ARRAY); } - break; + break; default: break; } + glPopMatrix(); } \ No newline at end of file