Finished surfaces
This commit is contained in:
@@ -669,6 +669,10 @@
|
|||||||
RelativePath=".\src\include\ErrorFunctions.h"
|
RelativePath=".\src\include\ErrorFunctions.h"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\src\include\Faces.h"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath=".\src\include\Globals.h"
|
RelativePath=".\src\include\Globals.h"
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -49,6 +49,7 @@ public:
|
|||||||
void setCFrame(CoordinateFrame);
|
void setCFrame(CoordinateFrame);
|
||||||
void setSize(Vector3);
|
void setSize(Vector3);
|
||||||
void setShape(Enum::Shape::Value shape);
|
void setShape(Enum::Shape::Value shape);
|
||||||
|
void setChanged();
|
||||||
|
|
||||||
//Collision
|
//Collision
|
||||||
bool collides(PartInstance * part);
|
bool collides(PartInstance * part);
|
||||||
|
|||||||
9
src/include/Faces.h
Normal file
9
src/include/Faces.h
Normal file
@@ -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
|
||||||
@@ -3,5 +3,5 @@
|
|||||||
#include "Enum.h"
|
#include "Enum.h"
|
||||||
#include "DataModelV2/Instance.h"
|
#include "DataModelV2/Instance.h"
|
||||||
void renderShape(const Enum::Shape::Value& shape, const Vector3& size, const Color3& ncolor);
|
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
|
#endif
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
#include "DataModelV2/PartInstance.h"
|
#include "DataModelV2/PartInstance.h"
|
||||||
#include "Globals.h"
|
#include "Globals.h"
|
||||||
#include "../../Renderer.h"
|
#include "Renderer.h"
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
|
#include "Faces.h"
|
||||||
|
|
||||||
PartInstance::PartInstance(void)
|
PartInstance::PartInstance(void)
|
||||||
{
|
{
|
||||||
@@ -18,12 +18,12 @@ PartInstance::PartInstance(void)
|
|||||||
color = Color3::gray();
|
color = Color3::gray();
|
||||||
velocity = Vector3(0,0,0);
|
velocity = Vector3(0,0,0);
|
||||||
rotVelocity = Vector3(0,0,0);
|
rotVelocity = Vector3(0,0,0);
|
||||||
top = Enum::SurfaceType::Smooth;
|
top = Enum::SurfaceType::Bumps;
|
||||||
front = Enum::SurfaceType::Smooth;
|
front = Enum::SurfaceType::Bumps;
|
||||||
right = Enum::SurfaceType::Smooth;
|
right = Enum::SurfaceType::Bumps;
|
||||||
back = Enum::SurfaceType::Smooth;
|
back = Enum::SurfaceType::Bumps;
|
||||||
left = Enum::SurfaceType::Smooth;
|
left = Enum::SurfaceType::Bumps;
|
||||||
bottom = Enum::SurfaceType::Smooth;
|
bottom = Enum::SurfaceType::Bumps;
|
||||||
shape = Enum::Shape::Block;
|
shape = Enum::Shape::Block;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -77,6 +77,11 @@ void PartInstance::postRender(RenderDevice *rd)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PartInstance::setChanged()
|
||||||
|
{
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
|
||||||
void PartInstance::setParent(Instance* prnt)
|
void PartInstance::setParent(Instance* prnt)
|
||||||
{
|
{
|
||||||
Instance * cparent = getParent();
|
Instance * cparent = getParent();
|
||||||
@@ -249,6 +254,12 @@ void PartInstance::render(RenderDevice* rd) {
|
|||||||
Vector3 renderSize = size/2;
|
Vector3 renderSize = size/2;
|
||||||
glNewList(glList, GL_COMPILE);
|
glNewList(glList, GL_COMPILE);
|
||||||
renderShape(this->shape, renderSize, color);
|
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();
|
glEndList();
|
||||||
}
|
}
|
||||||
rd->setObjectToWorldMatrix(cFrame);
|
rd->setObjectToWorldMatrix(cFrame);
|
||||||
@@ -289,15 +300,14 @@ static TCHAR* enumStr(int shape)
|
|||||||
|
|
||||||
void PartInstance::PropUpdate(LPPROPGRIDITEM &item)
|
void PartInstance::PropUpdate(LPPROPGRIDITEM &item)
|
||||||
{
|
{
|
||||||
|
setChanged();
|
||||||
if(strcmp(item->lpszPropName, "Color3") == 0)
|
if(strcmp(item->lpszPropName, "Color3") == 0)
|
||||||
{
|
{
|
||||||
color = Color3(GetRValue(item->lpCurValue)/255.0F,GetGValue(item->lpCurValue)/255.0F,GetBValue(item->lpCurValue)/255.0F);
|
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;
|
anchored= item->lpCurValue == TRUE;
|
||||||
changed=true;
|
|
||||||
}
|
}
|
||||||
else if(strcmp(item->lpszPropName, "Offset") == 0)
|
else if(strcmp(item->lpszPropName, "Offset") == 0)
|
||||||
{
|
{
|
||||||
@@ -356,7 +366,7 @@ void PartInstance::PropUpdate(LPPROPGRIDITEM &item)
|
|||||||
setSize(size);
|
setSize(size);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(strcmp(item->lpszPropName, "Shape") == 0)
|
else if(strcmp(item->lpszPropName, "Shape") == 0)
|
||||||
{
|
{
|
||||||
printf("%s", enumStr(strEnum((TCHAR*)item->lpCurValue)));
|
printf("%s", enumStr(strEnum((TCHAR*)item->lpCurValue)));
|
||||||
setShape(strEnum((TCHAR*)item->lpCurValue));
|
setShape(strEnum((TCHAR*)item->lpCurValue));
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
#include "Renderer.h"
|
#include "Renderer.h"
|
||||||
#include <G3DAll.h>
|
#include <G3DAll.h>
|
||||||
|
#include "Faces.h"
|
||||||
|
|
||||||
float _bevelSize = 0.07F;
|
float _bevelSize = 0.07F;
|
||||||
std::vector<Vector3> _debugUniqueVertices;
|
std::vector<Vector3> _debugUniqueVertices;
|
||||||
@@ -199,20 +200,23 @@ void renderShape(const Enum::Shape::Value& shape, const Vector3& size, const Col
|
|||||||
break;
|
break;
|
||||||
case Enum::Shape::Ball:
|
case Enum::Shape::Ball:
|
||||||
glColor(ncolor);
|
glColor(ncolor);
|
||||||
|
glPushMatrix();
|
||||||
glScalef(size.x, size.y, size.z);
|
glScalef(size.x, size.y, size.z);
|
||||||
gluSphere(gluNewQuadric(), 1, 20, 20);
|
gluSphere(gluNewQuadric(), 1, 20, 20);
|
||||||
|
glPopMatrix();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
GLUquadric * q = gluNewQuadric();
|
||||||
glColor(ncolor);
|
glColor(ncolor);
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
glScalef(size.x, size.y, size.z);
|
glScalef(size.x, size.y, size.z);
|
||||||
glRotatef(90, 0, 1, 0);
|
glRotatef(90, 0, 1, 0);
|
||||||
glTranslatef(0,0,1);
|
glTranslatef(0,0,1);
|
||||||
gluDisk(gluNewQuadric(), 0, 1, 12, 12);
|
gluDisk(q, 0, 1, 12, 12);
|
||||||
glTranslatef(0,0,-2);
|
glTranslatef(0,0,-2);
|
||||||
gluCylinder(gluNewQuadric(), 1, 1, 2, 12, 1);
|
gluCylinder(q, 1, 1, 2, 12, 1);
|
||||||
glRotatef(180, 1, 0, 0);
|
glRotatef(180, 1, 0, 0);
|
||||||
gluDisk(gluNewQuadric(), 0, 1, 12, 12);
|
gluDisk(q, 0, 1, 12, 12);
|
||||||
glPopMatrix();
|
glPopMatrix();
|
||||||
/*Plusses, can possibly integrate into cylinder code later on*/
|
/*Plusses, can possibly integrate into cylinder code later on*/
|
||||||
glVertexPointer(2, GL_FLOAT,0, square_arr);
|
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)
|
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:
|
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;
|
break;
|
||||||
case Enum::SurfaceType::Bumps:
|
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:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
glPopMatrix();
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user