Merge branch 'master' into MusicalProgrammer

This commit is contained in:
MusicalProgrammer
2018-10-29 14:33:27 -04:00
25 changed files with 1417 additions and 161 deletions

View File

@@ -1,7 +1,7 @@
#include "CameraController.h"
#include "win32Defines.h"
#include <iostream>
#include "PhysicalInstance.h"
#include "PartInstance.h"
#include "Demo.h"
#include "AudioPlayer.h"
@@ -138,13 +138,18 @@ void CameraController::centerCamera(Instance* selection)
lookAt(Vector3(0,0,0));
focusPosition=Vector3(0,0,0);
}
else
else if(PartInstance* part = dynamic_cast<PartInstance*>(selection))
{
Vector3 partPos = ((PhysicalInstance*)selection)->getPosition()/2;
Vector3 partPos = (part)->getPosition()/2;
lookAt(partPos);
focusPosition=partPos;
zoom=((partPos-frame.translation).magnitude());
}
else
{
lookAt(Vector3(0,0,0));
focusPosition=Vector3(0,0,0);
}
}
void CameraController::update(Demo* demo)
@@ -208,10 +213,10 @@ void CameraController::update(Demo* demo)
}
if(GetHoldKeyState(VK_RSHIFT) || GetHoldKeyState(VK_LSHIFT)) {
moveRate = 2.f;
moveRate = 2;
}
else {
moveRate = 1.f;
moveRate = 1;
}
if(GetHoldKeyState(VK_RBUTTON))

View File

@@ -7,9 +7,34 @@
using namespace std;
using namespace rapidxml;
PhysicalInstance* DataModelInstance::makePart()
DataModelInstance::DataModelInstance(void)
{
PhysicalInstance* part = new PhysicalInstance();
Instance::Instance();
workspace = new WorkspaceInstance();
guiRoot = new Instance();
level = new LevelInstance();
//children.push_back(workspace);
//children.push_back(level);
className = "dataModel";
mousex = 0;
mousey = 0;
mouseButton1Down = false;
showMessage = false;
canDelete = false;
workspace->setParent(this);
level->setParent(this);
}
DataModelInstance::~DataModelInstance(void)
{
}
PartInstance* DataModelInstance::makePart()
{
PartInstance* part = new PartInstance();
return part;
}
@@ -50,6 +75,7 @@ bool DataModelInstance::scanXMLObject(xml_node<> * scanNode)
for (xml_node<> *node = scanNode->first_node();node; node = node->next_sibling())
{
if (strncmp(node->name(),"Item",4)==0)
{
xml_attribute<> *classAttr = node->first_attribute("class");
@@ -135,11 +161,15 @@ bool DataModelInstance::scanXMLObject(xml_node<> * scanNode)
float sizeZ = getFloatValue(sizeNode,"Z");
if (_successfulLoad) {
PhysicalInstance* test = makePart();
PartInstance* test = makePart();
test->setParent(getWorkspace());
test->color = Color3(R,G,B);
test->setSize(Vector3(sizeX,sizeY,sizeZ));
test->setCFrame(Matrix3(R00,R01,R02,R10,R11,R12,R20,R21,R22)*Vector3(X,Y,Z));
CoordinateFrame what;
what.translation = Vector3(X,Y,Z);
what.rotation = Matrix3(R00,R01,R02,R10,R11,R12,R20,R21,R22);
test->setCFrame(what);
}
else
{
@@ -163,7 +193,7 @@ bool DataModelInstance::scanXMLObject(xml_node<> * scanNode)
bool DataModelInstance::load()
{
ifstream levelFile("skooter.rbxm");
ifstream levelFile("..//skooterFix.rbxm",ios::binary);
if (levelFile) {
levelFile.seekg(0,levelFile.end);
int length = levelFile.tellg();
@@ -184,37 +214,53 @@ bool DataModelInstance::load()
return true;
}
DataModelInstance::DataModelInstance(void)
{
Instance::Instance();
workspace = new WorkspaceInstance();
guiRoot = new Instance();
children.push_back(workspace);
className = "dataModel";
mousex = 0;
mousey = 0;
mouseButton1Down = false;
showMessage = false;
}
DataModelInstance::~DataModelInstance(void)
{
}
void DataModelInstance::setMessage(std::string msg)
{
message = msg;
isBrickCount = false;
showMessage = true;
}
void DataModelInstance::clearMessage()
{
showMessage = false;
isBrickCount = false;
message = "";
}
void DataModelInstance::setMessageBrickCount()
{
isBrickCount = true;
showMessage = true;
}
void DataModelInstance::drawMessage(RenderDevice* rd)
{
if(isBrickCount)
{
int brickCount = 0;
int instCount = 0;
std::vector<Instance*> inst = getAllChildren();
for(size_t i = 0; i < inst.size(); i++)
{
if(PartInstance* moveTo = dynamic_cast<PartInstance*>(inst.at(i)))
{
brickCount++;
}
else
{
instCount++;
}
}
char brkc[12];
sprintf(brkc, "%d", brickCount);
char instc[12];
sprintf(instc, "%d", instCount);
message = "Bricks: ";
message += brkc;
message += " Snaps: ";
message += instc;
}
if(showMessage && !font.isNull())
{
int x = rd->getWidth()/2;
@@ -248,3 +294,9 @@ Instance* DataModelInstance::getGuiRoot()
{
return guiRoot;
}
LevelInstance* DataModelInstance::getLevel()
{
return level;
}

View File

@@ -1,8 +1,8 @@
#pragma once
#include "rapidxml/rapidxml.hpp"
#include "instance.h"
#include "WorkspaceInstance.h"
#include "PhysicalInstance.h"
#include "LevelInstance.h"
#include "PartInstance.h"
#include "rapidxml/rapidxml.hpp"
class DataModelInstance :
public Instance
@@ -10,29 +10,33 @@ class DataModelInstance :
public:
DataModelInstance(void);
~DataModelInstance(void);
void setMessage(std::string);
void clearMessage();
bool load();
bool printIfLoadError(const char* errorMsg);
void drawMessage(RenderDevice*);
WorkspaceInstance* getWorkspace();
WorkspaceInstance* workspace;
Instance* guiRoot;
std::string message;
bool showMessage;
G3D::GFontRef font;
Instance* getGuiRoot();
float mousex;
float mousey;
Vector2 getMousePos();
void setMousePos(int x,int y);
void setMousePos(Vector2 pos);
bool mouseButton1Down;
PhysicalInstance* makePart();
void setMessage(std::string);
void setMessageBrickCount();
void clearMessage();
bool load();
void drawMessage(RenderDevice*);
WorkspaceInstance* getWorkspace();
WorkspaceInstance* workspace;
LevelInstance * level;
LevelInstance * getLevel();
Instance* guiRoot;
std::string message;
bool showMessage;
G3D::GFontRef font;
Instance* getGuiRoot();
float mousex;
float mousey;
Vector2 getMousePos();
void setMousePos(int x,int y);
void setMousePos(Vector2 pos);
bool mouseButton1Down;
PartInstance* makePart();
private:
bool isBrickCount;
bool scanXMLObject(rapidxml::xml_node<>* node);
rapidxml::xml_node<>* getNode(rapidxml::xml_node<> * node,const char* name );
float getFloatValue(rapidxml::xml_node<> * node,const char* name);
bool _successfulLoad;
std::string _errMsg;
};

4
Demo.h
View File

@@ -35,6 +35,7 @@ class Demo { // : public GApp {
RenderDevice* renderDevice;
UserInput* userInput;
PropertyWindow* _propWindow;
void generateShadowMap(const CoordinateFrame& lightViewMatrix) const;
private:
void initGUI();
HWND _hWndMain;
@@ -47,7 +48,8 @@ class Demo { // : public GApp {
HWND _hwndToolbox;
HWND _buttonTest;
HWND _hwndRenderer;
G3D::TextureRef shadowMap;
double lightProjX, lightProjY, lightProjNear, lightProjFar;
protected:
Stopwatch m_graphicsWatch;
Stopwatch m_logicWatch;

8
Enum.h
View File

@@ -1,3 +1,5 @@
#pragma once
namespace Enum
{
namespace SurfaceType
@@ -6,4 +8,10 @@ namespace Enum
Smooth, Bumps, Welds, Glue
};
}
namespace Shape
{
enum Value {
Block, Sphere, Cylinder
};
}
}

View File

@@ -8,9 +8,10 @@ int const Globals::patch = 2;
int Globals::surfaceId = 2;
bool Globals::showMouse = true;
bool Globals::useMousePoint = false;
std::vector<Instance*> postRenderStack = std::vector<Instance*>();
const std::string Globals::PlaceholderName = "Dynamica";
std::vector<Instance*> g_selectedInstances = std::vector<Instance*>();
bool running = false;
G3D::TextureRef Globals::surface;
POINT Globals::mousepoint;
Globals::Globals(void){}

View File

@@ -20,4 +20,6 @@ public:
static const std::string PlaceholderName;
};
extern std::vector<Instance*> g_selectedInstances;
extern std::vector<Instance*> postRenderStack;
extern std::vector<Instance*> g_selectedInstances;
extern bool running;

26
GroupInstance.cpp Normal file
View File

@@ -0,0 +1,26 @@
#include "GroupInstance.h"
GroupInstance::GroupInstance(void)
{
PVInstance::PVInstance();
className = "GroupInstance";
}
GroupInstance::GroupInstance(const GroupInstance &oinst)
{
PVInstance::PVInstance(oinst);
}
GroupInstance::~GroupInstance(void)
{
}
std::vector<PROPGRIDITEM> GroupInstance::getProperties()
{
std::vector<PROPGRIDITEM> properties = PVInstance::getProperties();
return properties;
}
void GroupInstance::PropUpdate(LPPROPGRIDITEM &pItem)
{
PVInstance::PropUpdate(pItem);
}

13
GroupInstance.h Normal file
View File

@@ -0,0 +1,13 @@
#pragma once
#include "PVInstance.h"
class GroupInstance :
public PVInstance
{
public:
GroupInstance(void);
~GroupInstance(void);
GroupInstance(const GroupInstance &oinst);
virtual std::vector<PROPGRIDITEM> getProperties();
virtual void PropUpdate(LPPROPGRIDITEM &pItem);
};

View File

@@ -9,6 +9,7 @@ Instance::Instance(void)
name = "Default Game Instance";
className = "BaseInstance";
listicon = 0;
canDelete = true;
}
Instance::Instance(const Instance &oinst)
@@ -16,13 +17,14 @@ Instance::Instance(const Instance &oinst)
name = oinst.name;
className = oinst.className;
canDelete = oinst.canDelete;
//setParent(oinst.parent);
}
void Instance::render(RenderDevice* rd)
{
{
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);
@@ -31,7 +33,6 @@ void Instance::render(RenderDevice* rd)
{
children.at(i)->render(rd);
}
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_COLOR_ARRAY);
glDisableClientState(GL_NORMAL_ARRAY);

View File

@@ -5,6 +5,7 @@
class Instance
{
public:
bool canDelete;
Instance(void);
Instance(const Instance&);
virtual ~Instance(void);
@@ -12,7 +13,7 @@ public:
virtual void render(RenderDevice*);
std::vector<Instance*> children; // All children.
std::string getClassName();
virtual Instance* findFirstChild(std::string);
Instance* findFirstChild(std::string);
std::vector<Instance* > getChildren();
std::vector<Instance* > getAllChildren();
void setParent(Instance*);

73
LevelInstance.cpp Normal file
View File

@@ -0,0 +1,73 @@
#include "LevelInstance.h"
LevelInstance::LevelInstance(void)
{
Instance::Instance();
name = "Level";
winMessage = "You Won!";
loseMessage = "You Lost. Try Again";
timer = 60.0F;
score = 0;
canDelete = false;
}
LevelInstance::~LevelInstance(void)
{
}
char timerTxt[12];
char scoreTxt[12];
std::vector<PROPGRIDITEM> LevelInstance::getProperties()
{
std::vector<PROPGRIDITEM> properties = Instance::getProperties();
properties.push_back(createPGI("Messages",
"WinMessage",
"The message that shows when the player wins.",
(LPARAM)winMessage.c_str(),
PIT_EDIT));
properties.push_back(createPGI("Messages",
"LoseMessage",
"The message that shows when the player loses.",
(LPARAM)loseMessage.c_str(),
PIT_EDIT));
sprintf(timerTxt, "%g", timer);
sprintf(scoreTxt, "%d", score);
properties.push_back(createPGI("Gameplay",
"InitialTimerValue",
"The ammount of time in seconds the player has to complete this level.\r\n\r\nPut 0 if time is limitless.",
(LPARAM)timerTxt,
PIT_EDIT));
properties.push_back(createPGI("Gameplay",
"InitialScoreValue",
"The ammount of points the player starts with.",
(LPARAM)scoreTxt,
PIT_EDIT));
return properties;
}
void LevelInstance::PropUpdate(LPPROPGRIDITEM &pItem)
{
if(strcmp(pItem->lpszPropName, "InitialTimerValue") == 0)
{
timer = atoi((LPSTR)pItem->lpCurValue);
}
if(strcmp(pItem->lpszPropName, "InitialScoreValue") == 0)
{
score = atof((LPSTR)pItem->lpCurValue);
}
if(strcmp(pItem->lpszPropName, "LoseMessage") == 0)
{
loseMessage = (LPSTR)pItem->lpCurValue;
}
if(strcmp(pItem->lpszPropName, "WinMessage") == 0)
{
winMessage = (LPSTR)pItem->lpCurValue;
}
else
Instance::PropUpdate(pItem);
}

16
LevelInstance.h Normal file
View File

@@ -0,0 +1,16 @@
#pragma once
#include "instance.h"
class LevelInstance :
public Instance
{
public:
LevelInstance(void);
~LevelInstance(void);
float timer;
int score;
virtual std::vector<PROPGRIDITEM> getProperties();
std::string winMessage;
std::string loseMessage;
virtual void PropUpdate(LPPROPGRIDITEM &pItem);
};

41
PVInstance.cpp Normal file
View File

@@ -0,0 +1,41 @@
#include "PVInstance.h"
PVInstance::PVInstance(void)
{
Instance::Instance();
nameShown = false;
className = "PVInstance";
}
PVInstance::PVInstance(const PVInstance &oinst)
{
Instance::Instance(oinst);
}
PVInstance::~PVInstance(void)
{
}
void PVInstance::postRender(RenderDevice* rd)
{
}
std::vector<PROPGRIDITEM> PVInstance::getProperties()
{
std::vector<PROPGRIDITEM> properties = Instance::getProperties();
properties.push_back(createPGI(
"Item",
"NameShown",
"This chooses whether the item name is shown",
nameShown,
PIT_CHECK));
return properties;
}
void PVInstance::PropUpdate(LPPROPGRIDITEM &pItem)
{
if(strcmp(pItem->lpszPropName, "NameShown") == 0)
{
nameShown = (bool)pItem->lpCurValue;
}
else Instance::PropUpdate(pItem);
}

15
PVInstance.h Normal file
View File

@@ -0,0 +1,15 @@
#pragma once
#include "instance.h"
class PVInstance :
public Instance
{
public:
PVInstance(void);
~PVInstance(void);
PVInstance(const PVInstance &oinst);
virtual void postRender(RenderDevice* rd);
virtual std::vector<PROPGRIDITEM> getProperties();
virtual void PropUpdate(LPPROPGRIDITEM &pItem);
bool nameShown;
};

576
PartInstance.cpp Normal file
View File

@@ -0,0 +1,576 @@
#include "PartInstance.h"
#include "Globals.h"
#include <sstream>
#include <iomanip>
PartInstance::PartInstance(void) : _bevelSize(0.07f), _parseVert(0), _debugTimer(0)
{
PVInstance::PVInstance();
name = "Unnamed PVItem";
className = "Part";
canCollide = true;
anchored = true;
size = Vector3(2,1,4);
setCFrame(CoordinateFrame(Vector3(0,0,0)));
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;
shape = Enum::Shape::Block;
}
void PartInstance::postRender(RenderDevice *rd)
{
if(!nameShown)
return;
G3D::GFontRef fnt = NULL;
Instance* dm = parent;
while(dm != NULL)
{
if(DataModelInstance* mod = dynamic_cast<DataModelInstance*>(dm))
{
fnt = mod->font;
break;
}
dm = dm->getParent();
}
if(!fnt.isNull())
{
Vector3 gamepoint = position + Vector3(0,1.5,0);
Vector3 camerapoint = rd->getCameraToWorldMatrix().translation;
float distance = pow(pow((double)gamepoint.x - (double)camerapoint.x, 2) + pow((double)gamepoint.y - (double)camerapoint.y, 2) + pow((double)gamepoint.z - (double)camerapoint.z, 2), 0.5);
if(distance < 100 && distance > -100)
{
if(distance < 0)
distance = distance*-1;
glDisable(GL_DEPTH_TEST);
fnt->draw3D(rd, name, CoordinateFrame(rd->getCameraToWorldMatrix().rotation, gamepoint), 0.03*distance, Color3::yellow(), Color3::black(), G3D::GFont::XALIGN_CENTER, G3D::GFont::YALIGN_CENTER);
glEnable(GL_DEPTH_TEST);
}
}
}
PartInstance::PartInstance(const PartInstance &oinst) : _bevelSize(0.07f), _parseVert(0), _debugTimer(0)
{
PVInstance::PVInstance(oinst);
//name = oinst.name;
//className = "Part";
name = oinst.name;
canCollide = oinst.canCollide;
setParent(oinst.parent);
anchored = oinst.anchored;
size = oinst.size;
setCFrame(oinst.cFrame);
color = oinst.color;
velocity = oinst.velocity;
rotVelocity = oinst.rotVelocity;
top = oinst.top;
front = oinst.front;
right = oinst.right;
back = oinst.back;
left = oinst.left;
bottom = oinst.bottom;
shape = oinst.shape;
changed = true;
}
void PartInstance::setSize(Vector3 newSize)
{
int minsize = 1;
int maxsize = 512;
changed = true;
int sizex = (int)newSize.x;
if(sizex <= 0)
sizex = 1;
if(sizex > 512)
sizex = 512;
int sizey = (int)newSize.y;
if(sizey <= 0)
sizey = 1;
if(sizey > 512)
sizey = 512;
int sizez = (int)newSize.z;
if(sizez <= 0)
sizez = 1;
if(sizez > 512)
sizez = 512;
if(shape != Enum::Shape::Block)
{
int max = sizex;
if(sizey > max)
max = sizey;
if(sizez > max)
max = sizez;
sizex = sizey = sizez = max;
}
size = Vector3(sizex, sizey, sizez);
}
Vector3 PartInstance::getSize()
{
return size;
}
Vector3 PartInstance::getPosition()
{
return position;
}
void PartInstance::setPosition(Vector3 pos)
{
position = pos;
cFrame = CoordinateFrame(pos);
changed = true;
}
CoordinateFrame PartInstance::getCFrame()
{
return cFrame;
}
void PartInstance::setCFrame(CoordinateFrame coordinateFrame)
{
cFrame = coordinateFrame;
position = coordinateFrame.translation;
changed = true;
}
// Can probably be deleted
CoordinateFrame PartInstance::getCFrameRenderBased()
{
return cFrame;//CoordinateFrame(getCFrame().rotation,Vector3(getCFrame().translation.x, getCFrame().translation.y, getCFrame().translation.z));
}
#ifdef NEW_BOX_RENDER
Box PartInstance::getBox()
{
Box box = Box(Vector3(size.x/2, size.y/2, size.z/2) ,Vector3(-size.x/2,-size.y/2,-size.z/2));
CoordinateFrame c = getCFrameRenderBased();
itemBox = c.toWorldSpace(box);
return itemBox;
}
#else
Box PartInstance::getBox()
{
if(changed)
{
Box box = Box(Vector3(0+size.x/4, 0+size.y/4, 0+size.z/4) ,Vector3(0-size.x/4,0-size.y/4,0-size.z/4));
CoordinateFrame c = getCFrameRenderBased();
itemBox = c.toWorldSpace(box);
Vector3 v0,v1,v2,v3;
for (int f = 0; f < 6; f++) {
itemBox.getFaceCorners(f, v0,v1,v2,v3);
_vertices[f*16] = v0.x;
_vertices[(f*16)+1] = v0.y;
_vertices[(f*16)+2] = v0.z;
_vertices[(f*16)+3] = v1.x;
_vertices[(f*16)+4] = v1.y;
_vertices[(f*16)+5] = v1.z;
_vertices[(f*16)+6] = v2.x;
_vertices[(f*16)+7] = v2.y;
_vertices[(f*16)+8] = v2.z;
_vertices[(f*16)+9] = v3.x;
_vertices[(f*16)+10] = v3.y;
_vertices[(f*16)+11] = v3.z;
_vertices[(f*16)+12] = color.r;
_vertices[(f*16)+13] = color.g;
_vertices[(f*16)+14] = color.b;
_vertices[(f*16)+15] = 1;
}
}
return itemBox;
}
#endif
bool PartInstance::collides(Box box)
{
return CollisionDetection::fixedSolidBoxIntersectsFixedSolidBox(getBox(), box);
}
void PartInstance::addVertex(Vector3 vertexPos,Color3 color)
{
_vertices.push_back(vertexPos.x);
_vertices.push_back(vertexPos.y);
_vertices.push_back(vertexPos.z);
_vertices.push_back(color.r);
_vertices.push_back(color.g);
_vertices.push_back(color.b);
}
void PartInstance::addNormals(Vector3 normal)
{
for (unsigned int i=0;i<3;i+=1) {
_normals.push_back(normal.x);
_normals.push_back(normal.y);
_normals.push_back(normal.z);
}
}
void PartInstance::addTriangle(Vector3 v1,Vector3 v2,Vector3 v3)
{
addVertex(v1,color);
addVertex(v2,color);
addVertex(v3,color);
addNormals(cross(v2-v1,v3-v1).direction());
}
void PartInstance::debugPrintVertexIDs(RenderDevice* rd,GFontRef font,Matrix3 rot)
{
_debugUniqueVertices.clear();
glDisable(GL_DEPTH_TEST);
for (unsigned int i=0;i<_vertices.size();i+=6)
{
std::stringstream stream;
stream << std::fixed << std::setprecision(1) << i;
Vector3 testVector = Vector3(_vertices[i],_vertices[i+1],_vertices[i+2]);
if (isUniqueVertex(testVector))
{
font->draw3D(rd, stream.str(), CoordinateFrame(testVector) * -rot, 0.05, Color3::fromARGB(0xFF4F0000), Color4::clear());
_debugUniqueVertices.push_back(testVector);
}
}
glEnable(GL_DEPTH_TEST);
}
void PartInstance::makeFace(int vertex1,int vertex2, int vertex3)
{
addTriangle(Vector3(_vertices[vertex1],_vertices[vertex1+1],_vertices[vertex1+2]),
Vector3(_vertices[vertex2],_vertices[vertex2+1],_vertices[vertex2+2]),
Vector3(_vertices[vertex3],_vertices[vertex3+1],_vertices[vertex3+2]));
}
bool PartInstance::isUniqueVertex(Vector3 pos)
{
for (unsigned int i=0;i<_debugUniqueVertices.size();i+=1)
{
if (pos==_debugUniqueVertices[i])
{
return false;
}
}
return true;
}
#ifdef NEW_BOX_RENDER
void PartInstance::render(RenderDevice* rd) {
if(nameShown)
postRenderStack.push_back(this);
if (changed)
{
getBox();
_vertices.clear();
Vector3 renderSize = size/2;
// Front
addTriangle(Vector3(renderSize.x-_bevelSize,renderSize.y-_bevelSize,renderSize.z),
Vector3(-renderSize.x+_bevelSize,-renderSize.y+_bevelSize,renderSize.z),
Vector3(renderSize.x-_bevelSize,-renderSize.y+_bevelSize,renderSize.z)
);
addTriangle(Vector3(-renderSize.x+_bevelSize,renderSize.y-_bevelSize,renderSize.z),
Vector3(-renderSize.x+_bevelSize,-renderSize.y+_bevelSize,renderSize.z),
Vector3(renderSize.x-_bevelSize,renderSize.y-_bevelSize,renderSize.z)
);
// Top
addTriangle(Vector3(renderSize.x-_bevelSize,renderSize.y,renderSize.z-_bevelSize),
Vector3(renderSize.x-_bevelSize,renderSize.y,-renderSize.z+_bevelSize),
Vector3(-renderSize.x+_bevelSize,renderSize.y,renderSize.z-_bevelSize)
);
addTriangle(Vector3(-renderSize.x+_bevelSize,renderSize.y,renderSize.z-_bevelSize),
Vector3(renderSize.x-_bevelSize,renderSize.y,-renderSize.z+_bevelSize),
Vector3(-renderSize.x+_bevelSize,renderSize.y,-renderSize.z+_bevelSize)
);
// Back
addTriangle(Vector3(renderSize.x-_bevelSize,renderSize.y-_bevelSize,-renderSize.z),
Vector3(renderSize.x-_bevelSize,-renderSize.y+_bevelSize,-renderSize.z),
Vector3(-renderSize.x+_bevelSize,-renderSize.y+_bevelSize,-renderSize.z)
);
addTriangle(Vector3(renderSize.x-_bevelSize,renderSize.y-_bevelSize,-renderSize.z),
Vector3(-renderSize.x+_bevelSize,-renderSize.y+_bevelSize,-renderSize.z),
Vector3(-renderSize.x+_bevelSize,renderSize.y-_bevelSize,-renderSize.z)
);
// Bottom
addTriangle(Vector3(renderSize.x-_bevelSize,-renderSize.y,-renderSize.z+_bevelSize),
Vector3(renderSize.x-_bevelSize,-renderSize.y,renderSize.z-_bevelSize),
Vector3(-renderSize.x+_bevelSize,-renderSize.y,renderSize.z-_bevelSize)
);
addTriangle(Vector3(-renderSize.x+_bevelSize,-renderSize.y,renderSize.z-_bevelSize),
Vector3(-renderSize.x+_bevelSize,-renderSize.y,-renderSize.z+_bevelSize),
Vector3(renderSize.x-_bevelSize,-renderSize.y,-renderSize.z+_bevelSize)
);
// Left
addTriangle(Vector3(-renderSize.x,renderSize.y-_bevelSize,-renderSize.z+_bevelSize),
Vector3(-renderSize.x,-renderSize.y+_bevelSize,renderSize.z-_bevelSize),
Vector3(-renderSize.x,renderSize.y-_bevelSize,renderSize.z-_bevelSize)
);
addTriangle(Vector3(-renderSize.x,-renderSize.y+_bevelSize,renderSize.z-_bevelSize),
Vector3(-renderSize.x,renderSize.y-_bevelSize,-renderSize.z+_bevelSize),
Vector3(-renderSize.x,-renderSize.y+_bevelSize,-renderSize.z+_bevelSize)
);
// Right
addTriangle(Vector3(renderSize.x,renderSize.y-_bevelSize,renderSize.z-_bevelSize),
Vector3(renderSize.x,-renderSize.y+_bevelSize,renderSize.z-_bevelSize),
Vector3(renderSize.x,renderSize.y-_bevelSize,-renderSize.z+_bevelSize)
);
addTriangle(Vector3(renderSize.x,-renderSize.y+_bevelSize,-renderSize.z+_bevelSize),
Vector3(renderSize.x,renderSize.y-_bevelSize,-renderSize.z+_bevelSize),
Vector3(renderSize.x,-renderSize.y+_bevelSize,renderSize.z-_bevelSize)
);
// Bevel Top Front
makeFace(0,36,48);
makeFace(48,18,0);
// Bevel Left Front Corner
makeFace(18,156,162);
makeFace(24,18,162);
// Bevel Left Front Top Corner
makeFace(48,156,18);
// Bevel Left Front Bottom Corner
makeFace(120,6,150);
// Bevel Left Top
makeFace(48,66,156);
makeFace(144,156,66);
// Bevel Bottom
makeFace(6,120,114);
makeFace(114,12,6);
// Left Bottom
makeFace(120,150,174);
makeFace(174,132,120);
// Right Front Top Corner
makeFace(36,0,180);
// Right Front Corner
makeFace(180,0,12);
makeFace(186,180,12);
// Right Front Bottom Corner
makeFace(186,12,114);
// Right Bottom
makeFace(186,114,108);
makeFace(108,198,186);
// Right Top Corner
makeFace(180,192,36);
makeFace(192,42,36);
// Right Back Top Corner
makeFace(72,42,192);
// Right Back Bottom Corner
makeFace(78,198,108);
// Right Back Corner
makeFace(72,192,198);
makeFace(198,78,72);
// Back Bottom Corner
makeFace(78,108,132);
makeFace(132,84,78);
// Back Top
makeFace(42,72,102);
makeFace(102,66,42);
// Back Left Top Corner
makeFace(144,66,102);
// Back Left Corner
makeFace(144,102,84);
makeFace(84,174,144);
// Back Left Bottom Corner
makeFace(174,84,132);
for (unsigned short i=0;i<_vertices.size()/6;i++) {
_indices.push_back(i);
}
changed=false;
}
//rd->setObjectToWorldMatrix(cFrame);
CoordinateFrame forDraw = rd->getObjectToWorldMatrix();
rd->setObjectToWorldMatrix(cFrame);
glVertexPointer(3, GL_FLOAT,6 * sizeof(GLfloat), &_vertices[0]);
glColorPointer(3, GL_FLOAT,6 * sizeof(GLfloat), &_vertices[3]);
glNormalPointer(GL_FLOAT,3 * sizeof(GLfloat), &_normals[0]);
glPushMatrix();
//glTranslatef(2,7,0);
glDrawElements(GL_TRIANGLES, _indices.size(), GL_UNSIGNED_SHORT, &_indices[0]);
glPopMatrix();
rd->setObjectToWorldMatrix(forDraw);
}
#else
void PartInstance::render(RenderDevice* rd)
{
if(changed)
Box box = getBox();
glColor(color);
/*glEnable( GL_TEXTURE_2D );
glEnable(GL_BLEND);// you enable blending function
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glBindTexture( GL_TEXTURE_2D, Globals::surfaceId);
glBegin(GL_QUADS);*/
for(int i = 0; i < 96; i+=16)
{
double add = 0.8;
Enum::SurfaceType::Value face;
if(i == 0)//Back
face = back;
else if(i == 16)//Right
face = right;
else if(i == 32)//Front
face = front;
else if(i == 48)//Top
face = top;
else if(i == 64)//Left
face = left;
else if(i == 80)//Bottom
face = bottom;
/*if(face == Snaps)
add = 0.0;
else if(face == Inlets)
add = 0.2;*/
Vector3 v0 = Vector3(_vertices[i], _vertices[i+1], _vertices[i+2]), v1 = Vector3(_vertices[i+3], _vertices[i+4], _vertices[i+5]), v3 = Vector3(_vertices[i+9], _vertices[i+10], _vertices[i+11]);
/*glNormal3fv((v1 - v0).cross(v3 - v0).direction());
glTexCoord2f(0.0F,0.0F);
glVertex3fv(v0);
glTexCoord2f(1.0F,0.0F);
glVertex3fv(v1);
glTexCoord2f(1.0F,0.25F);
glVertex3f(_vertices[i+6], _vertices[i+7], _vertices[i+8]);
glTexCoord2f(0.0F,0.25F);
glVertex3fv(v3);*/
glEnable( GL_TEXTURE_2D );
glEnable(GL_BLEND);// you enable blending function
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glBindTexture( GL_TEXTURE_2D, Globals::surfaceId);
glBegin( GL_QUADS );
glNormal3fv((v1 - v0).cross(v3 - v0).direction());
glTexCoord2d(0.0,0.0+add);
glVertex3fv(v0);
glTexCoord2d( 1.0,0.0+add);
glVertex3fv(v1);
glTexCoord2d(1.0,0.2+add);
glVertex3f(_vertices[i+6], _vertices[i+7], _vertices[i+8]);
glTexCoord2d( 0.0,0.2+add);
glVertex3fv(v3);
glEnd();
glDisable( GL_TEXTURE_2D );
}
/*glEnd();
glDisable(GL_TEXTURE_2D);*/
glColor(Color3::white());
if(!children.empty())
{
for(size_t i = 0; i < children.size(); i++)
{
children.at(i)->render(rd);
}
}
}
#endif
PartInstance::~PartInstance(void)
{
}
char pto[512];
char pto2[512];
#include <sstream>
void PartInstance::PropUpdate(LPPROPGRIDITEM &item)
{
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;
}
else if(strcmp(item->lpszPropName, "Offset") == 0)
{
std::string str = (LPTSTR)item->lpCurValue;
std::vector<float> vect;
std::stringstream ss(str);
float i;
while (ss >> i)
{
vect.push_back(i);
if (ss.peek() == ',')
ss.ignore();
}
if(vect.size() != 3)
{
sprintf(pto, "%g, %g, %g", cFrame.translation.x, cFrame.translation.y, cFrame.translation.z, "what");
LPCSTR str = LPCSTR(pto);
item->lpCurValue = (LPARAM)str;
}
else
{
Vector3 pos(vect.at(0),vect.at(1),vect.at(2));
setPosition(pos);
}
}
else if(strcmp(item->lpszPropName, "Size") == 0)
{
std::string str = (LPTSTR)item->lpCurValue;
std::vector<float> vect;
std::stringstream ss(str);
float i;
while (ss >> i)
{
vect.push_back(i);
if (ss.peek() == ',')
ss.ignore();
}
if(vect.size() != 3)
{
sprintf(pto, "%g, %g, %g", cFrame.translation.x, cFrame.translation.y, cFrame.translation.z, "what");
LPCSTR str = LPCSTR(pto);
item->lpCurValue = (LPARAM)str;
}
else
{
Vector3 size(vect.at(0),vect.at(1),vect.at(2));
setSize(size);
}
}
else PVInstance::PropUpdate(item);
}
std::vector<PROPGRIDITEM> PartInstance::getProperties()
{
std::vector<PROPGRIDITEM> properties = PVInstance::getProperties();
properties.push_back(createPGI(
"Properties",
"Color3",
"The color of the selected part",
RGB((color.r*255),(color.g*255),(color.b*255)),
PIT_COLOR
));
sprintf(pto, "%g, %g, %g", cFrame.translation.x, cFrame.translation.y, cFrame.translation.z);
properties.push_back(createPGI(
"Item",
"Offset",
"The position of the object in the workspace",
(LPARAM)pto,
PIT_EDIT
));
sprintf(pto2, "%g, %g, %g", size.x, size.y, size.z);
properties.push_back(createPGI(
"Item",
"Size",
"The position of the object in the workspace",
(LPARAM)pto2,
PIT_EDIT
));
return properties;
}

63
PartInstance.h Normal file
View File

@@ -0,0 +1,63 @@
#pragma once
#include "PVInstance.h"
#include "Enum.h"
#define NEW_BOX_RENDER
class PartInstance : public PVInstance
{
public:
PartInstance(void);
PartInstance(const PartInstance &oinst);
Instance* clone() const { return new PartInstance(*this); }
virtual void PartInstance::postRender(RenderDevice* rd);
~PartInstance(void);
virtual void render(RenderDevice*);
Vector3 velocity;
Enum::SurfaceType::Value top;
Enum::SurfaceType::Value front;
Enum::SurfaceType::Value right;
Enum::SurfaceType::Value back;
Enum::SurfaceType::Value left;
Enum::SurfaceType::Value bottom;
Enum::Shape::Value shape;
CoordinateFrame cFrame;
Color3 color;
Vector3 getPosition();
void setPosition(Vector3);
CoordinateFrame getCFrame();
void setCFrame(CoordinateFrame);
Box getBox();
Box getScaledBox();
CoordinateFrame getCFrameRenderBased();
Vector3 getSize();
void setSize(Vector3);
bool canCollide;
bool anchored;
Vector3 rotVelocity;
bool collides(Box);
virtual std::vector<PROPGRIDITEM> getProperties();
virtual void PropUpdate(LPPROPGRIDITEM &pItem);
void addVertex(Vector3 vertexPos,Color3 color);
void addNormals(Vector3 normal);
void addTriangle(Vector3 vertexPos,Vector3 vertexPos2, Vector3 vertexPos3);
void debugPrintVertexIDs(RenderDevice* rd, GFontRef font, Matrix3 camRot);
void makeFace(int vertex1, int vertex2, int vertex3);
bool isUniqueVertex(Vector3 pos);
private:
Vector3 position;
Vector3 size;
float _bevelSize;
int _parseVert;
int _debugTimer;
std::vector<Vector3> _debugUniqueVertices;
#ifdef NEW_BOX_RENDER
std::vector<GLfloat> _vertices;
std::vector<GLfloat> _normals;
#else
GLfloat _vertices[96];
#endif
std::vector<GLushort> _indices;
bool changed;
Box itemBox;
};

View File

@@ -4,6 +4,7 @@
#include "resource.h"
#include "PropertyWindow.h"
#include "Globals.h"
#include "strsafe.h"
/*typedef struct typPRGP {
Instance* instance; // Declare member types
Property &prop;
@@ -11,11 +12,14 @@
std::vector<PROPGRIDITEM> prop;
std::vector<Instance*> children;
Instance* selectedInstance;
Instance * selectedInstance;
Instance * parent = NULL;
const int CX_BITMAP = 16;
const int CY_BITMAP = 16;
LRESULT CALLBACK PropProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
TCHAR achTemp[256];
PropertyWindow *propWind = (PropertyWindow *)GetWindowLongPtr(hwnd, GWL_USERDATA);
if (propWind==NULL)
{
@@ -28,6 +32,78 @@ LRESULT CALLBACK PropProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
ShowWindow(hwnd, SW_HIDE);
}
break;
case WM_DRAWITEM:
{
std::cout << "Drawing?" << "\r\n";
COLORREF clrBackground;
COLORREF clrForeground;
TEXTMETRIC tm;
int x;
int y;
HRESULT hr;
size_t cch;
LPDRAWITEMSTRUCT lpdis = (LPDRAWITEMSTRUCT) lParam;
if (lpdis->itemID == -1) // Empty item)
break;
// Get the food icon from the item data.
HBITMAP hbmIcon = LoadBitmap(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_BITMAP1));
HBITMAP hbmMask = LoadBitmap(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_BITMAP1));
// The colors depend on whether the item is selected.
clrForeground = SetTextColor(lpdis->hDC,
GetSysColor(lpdis->itemState & ODS_SELECTED ?
COLOR_HIGHLIGHTTEXT : COLOR_WINDOWTEXT));
clrBackground = SetBkColor(lpdis->hDC,
GetSysColor(lpdis->itemState & ODS_SELECTED ?
COLOR_HIGHLIGHT : COLOR_WINDOW));
// Calculate the vertical and horizontal position.
GetTextMetrics(lpdis->hDC, &tm);
y = (lpdis->rcItem.bottom + lpdis->rcItem.top - tm.tmHeight) / 2;
x = LOWORD(GetDialogBaseUnits()) / 4;
// Get and display the text for the list item.
SendMessage(lpdis->hwndItem, CB_GETLBTEXT, lpdis->itemID, (LPARAM) achTemp);
hr = StringCchLength(achTemp, 256, &cch);
if (FAILED(hr))
{
// TODO: Write error handler.
}
ExtTextOut(lpdis->hDC, CX_BITMAP + 2 * x, y,
ETO_CLIPPED | ETO_OPAQUE, &lpdis->rcItem,
achTemp, (UINT)cch, NULL);
// Restore the previous colors.
SetTextColor(lpdis->hDC, clrForeground);
SetBkColor(lpdis->hDC, clrBackground);
// Draw the food icon for the item.
HDC hdc = CreateCompatibleDC(lpdis->hDC);
if (hdc == NULL)
break;
SelectObject(hdc, hbmMask);
BitBlt(lpdis->hDC, x, lpdis->rcItem.top + 1,
CX_BITMAP, CY_BITMAP, hdc, 0, 0, SRCAND);
SelectObject(hdc, hbmIcon);
BitBlt(lpdis->hDC, x, lpdis->rcItem.top + 1,
CX_BITMAP, CY_BITMAP, hdc, 0, 0, SRCPAINT);
DeleteDC(hdc);
// If the item has the focus, draw the focus rectangle.
if (lpdis->itemState & ODS_FOCUS)
DrawFocusRect(lpdis->hDC, &lpdis->rcItem);
}
break;
case WM_MEASUREITEM:
{
LPMEASUREITEMSTRUCT lpmis = (LPMEASUREITEMSTRUCT) lParam;
@@ -52,12 +128,31 @@ LRESULT CALLBACK PropProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
propWind->ClearProperties();
while(g_selectedInstances.size() != 0)
g_selectedInstances.erase(g_selectedInstances.begin());
g_selectedInstances.push_back(children.at(ItemIndex-1));
propWind->SetProperties(children.at(ItemIndex-1));
if(parent != NULL)
{
std::cout << ItemIndex << std::endl;
if(ItemIndex == 1)
{
g_selectedInstances.push_back(parent);
propWind->SetProperties(parent);
}
else
{
g_selectedInstances.push_back(children.at(ItemIndex+2));
propWind->SetProperties(children.at(ItemIndex+2));
}
}
else
{
g_selectedInstances.push_back(children.at(ItemIndex-1));
propWind->SetProperties(children.at(ItemIndex-1));
}
}
}
}
break;
case WM_NOTIFY:
{
switch(((LPNMHDR)lParam)->code)
@@ -69,6 +164,7 @@ LRESULT CALLBACK PropProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
LPNMPROPGRID lpnmp = (LPNMPROPGRID)pnm;
LPPROPGRIDITEM item = PropGrid_GetItemData(pnm->hwndFrom,lpnmp->iIndex);
selectedInstance->PropUpdate(item);
//propWind->SetProperties(selectedInstance);
}
}
break;
@@ -85,14 +181,24 @@ LRESULT CALLBACK PropProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
void PropertyWindow::refreshExplorer()
{
SendMessage(_explorerComboBox,CB_RESETCONTENT,0,0);
parent = NULL;
for (unsigned int i=0;i<g_selectedInstances.size();i++) {
SendMessage(_explorerComboBox,CB_ADDSTRING, 0,(LPARAM)g_selectedInstances[i]->name.c_str());
if(g_selectedInstances[i]->getParent() != NULL)
{
std::string title = ".. (";
title += g_selectedInstances[i]->getParent()->name;
title += ")";
SendMessage(_explorerComboBox,CB_ADDSTRING, 0,(LPARAM)title.c_str());
parent = g_selectedInstances[i]->getParent();
}
children = g_selectedInstances[i]->getChildren();
for(size_t z = 0; z < children.size(); z++)
{
SendMessage(_explorerComboBox,CB_ADDSTRING, 0,(LPARAM)children.at(z)->name.c_str());
}
SendMessage(_explorerComboBox,CB_SETCURSEL,0,(LPARAM)0);
SendMessage(_explorerComboBox,CB_SETCURSEL,0,(LPARAM)0);
}
}

View File

@@ -21,6 +21,7 @@ TextButtonInstance::TextButtonInstance(void)
visible = true;
className = "TextButton";
disabled = false;
selected = false;
}
bool TextButtonInstance::mouseInButton(float mousex, float mousey, RenderDevice* rd)
@@ -58,6 +59,10 @@ void TextButtonInstance::setAllColorsSame()
textOutlineColorDn = textOutlineColor;
boxColorDn = boxColor;
boxOutlineColorDn = boxOutlineColor;
textColorDis = textColor;
textOutlineColorDis = textOutlineColor;
boxColorDis = boxColor;
boxOutlineColorDis = boxOutlineColor;
}
TextButtonInstance::~TextButtonInstance(void)
@@ -68,9 +73,9 @@ void TextButtonInstance::drawObj(RenderDevice* rd, Vector2 mousePos, bool mouseD
{
Vector3 point1;
Vector3 point2;
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glDisableClientState(GL_COLOR_ARRAY);
if(floatBottom)
{
point1 = Vector3(boxBegin.x, rd->getHeight() + boxBegin.y,0);
@@ -83,7 +88,12 @@ void TextButtonInstance::drawObj(RenderDevice* rd, Vector2 mousePos, bool mouseD
point2 = Vector3(boxEnd.x, boxEnd.y,0);
}
Vector2 RelativeTo = Vector2(point1.x + fontLocationRelativeTo.x, point1.y + fontLocationRelativeTo.y);
if(mouseInArea(point1.x, point1.y, point2.x, point2.y, mousePos.x, mousePos.y) && mouseDown)
if(disabled)
{
Draw::box(Box(point1, point2), rd, boxColorDis, boxOutlineColorDis);
font->draw2D(rd, title, RelativeTo, textSize, textColorDis, textOutlineColorDis);
}
else if(mouseInArea(point1.x, point1.y, point2.x, point2.y, mousePos.x, mousePos.y) && mouseDown)
{
Draw::box(Box(point1, point2), rd, boxColorDn, boxOutlineColorDn);
font->draw2D(rd, title, RelativeTo, textSize, textColorDn, textOutlineColorDn);
@@ -93,6 +103,11 @@ void TextButtonInstance::drawObj(RenderDevice* rd, Vector2 mousePos, bool mouseD
Draw::box(Box(point1, point2), rd, boxColorOvr, boxOutlineColorOvr);
font->draw2D(rd, title, RelativeTo, textSize, textColorOvr, textOutlineColorOvr);
}
else if(selected)
{
Draw::box(Box(point1, point2), rd, boxColorOvr, boxOutlineColorOvr);
font->draw2D(rd, title, RelativeTo, textSize, textColorOvr, textOutlineColorOvr);
}
else
{
Draw::box(Box(point1, point2), rd, boxColor, boxOutlineColor);

View File

@@ -21,6 +21,10 @@ public:
Color4 textOutlineColorDn;
Color4 boxColorDn;
Color4 boxOutlineColorDn;
Color4 textColorDis;
Color4 textOutlineColorDis;
Color4 boxColorDis;
Color4 boxOutlineColorDis;
bool centeredWithinBox;
std::string title;
G3D::GFontRef font;

View File

@@ -3,11 +3,10 @@
WorkspaceInstance::WorkspaceInstance(void)
{
Instance::Instance();
name = "Instance";
className = "Level";
timer = 60.0F;
score = 0;
GroupInstance::GroupInstance();
name = "Workspace";
className = "Workspace";
canDelete = false;
}
WorkspaceInstance::~WorkspaceInstance(void)

View File

@@ -1,13 +1,10 @@
#pragma once
#include "instance.h"
#include "GroupInstance.h"
class WorkspaceInstance :
public Instance
public GroupInstance
{
public:
float timer;
int score;
WorkspaceInstance(void);
~WorkspaceInstance(void);
};

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

414
main.cpp
View File

@@ -14,13 +14,14 @@
// TODO: Move toolbar buttons with resized window.
#define _WIN32_WINNT 0x0400
//#define LEGACY_LOAD_G3DFUN_LEVEL
#include <G3DAll.h>
#include <initguid.h>
#include <iomanip>
#include "Instance.h"
#include "resource.h"
#include "PhysicalInstance.h"
#include "PartInstance.h"
#include "TextButtonInstance.h"
#include "ImageButtonInstance.h"
#include "DataModelInstance.h"
@@ -41,11 +42,13 @@
#include "PropertyWindow.h"
#include <commctrl.h>
#if G3D_VER < 61000
#error Requires G3D 6.10
#endif
HWND hwnd;
DEFINE_GUID(CLSID_G3d, 0xB323F8E0L, 0x2E68, 0x11D0, 0x90, 0xEA, 0x00, 0xAA, 0x00, 0x60, 0xF8, 0x6F);
HRESULT hresult;
OLECHAR dat = ((OLECHAR)"SayHello");
@@ -67,8 +70,10 @@ static std::string cameraSound = "";
static std::string clickSound = "";
static std::string dingSound = "";
static int cursorid = 0;
static int cursorOvrid = 0;
static int currentcursorid = 0;
static G3D::TextureRef cursor = NULL;
static bool running = true;
static G3D::TextureRef cursorOvr = NULL;
static bool mouseMovedBeginMotion = false;
static const int CURSOR = 0;
static const int ARROWS = 1;
@@ -76,13 +81,15 @@ static const int RESIZE = 2;
static POINT oldGlobalMouse;
static int mode = CURSOR;
bool dragging = false;
Vector2 oldMouse = Vector2(0,0);
#include <math.h>
Vector2 mouseDownOn = Vector2(nan(), 0);
float moveRate = 0.5;
static const std::string PlaceholderName = "HyperCube";
Demo *usableApp = NULL;
Demo::Demo(const GAppSettings& settings,HWND parentWindow) { //: GApp(settings,window) {
lightProjX = 17; lightProjY = 17; lightProjNear = 1; lightProjFar = 40;
_hWndMain = parentWindow;
HMODULE hThisInstance = GetModuleHandle(NULL);
@@ -191,9 +198,9 @@ std::string Convert (float number){
}
PhysicalInstance* makePart()
PartInstance* makePart()
{
PhysicalInstance* part = new PhysicalInstance();
PartInstance* part = new PartInstance();
return part;
}
@@ -245,7 +252,14 @@ public:
void GUDButtonListener::onButton1MouseClick(BaseButtonInstance* button)
{
if(g_selectedInstances.size() > 0)
bool cont = false;
for(size_t i = 0; i < g_selectedInstances.size(); i++)
if(g_selectedInstances.at(i)->canDelete)
{
cont = true;
break;
}
if(cont)
{
AudioPlayer::playSound(dingSound);
if(button->name == "Duplicate")
@@ -253,7 +267,7 @@ void GUDButtonListener::onButton1MouseClick(BaseButtonInstance* button)
std::vector<Instance*> newinst;
for(size_t i = 0; i < g_selectedInstances.size(); i++)
{
if(g_selectedInstances.at(i) != dataModel->getWorkspace())
if(g_selectedInstances.at(i)->canDelete)
{
Instance* tempinst = g_selectedInstances.at(i);
@@ -282,7 +296,7 @@ void RotateButtonListener::onButton1MouseClick(BaseButtonInstance* button)
{
Instance* selectedInstance = g_selectedInstances.at(0);
AudioPlayer::playSound(clickSound);
if(PhysicalInstance* part = dynamic_cast<PhysicalInstance*>(selectedInstance))
if(PartInstance* part = dynamic_cast<PartInstance*>(selectedInstance))
{
if(button->name == "Tilt")
part->setCFrame(part->getCFrame()*Matrix3::fromEulerAnglesXYZ(0,0,toRadians(90)));
@@ -301,7 +315,7 @@ void deleteInstance()
size_t undeletable = 0;
while(g_selectedInstances.size() > undeletable)
{
if(g_selectedInstances.at(0) != dataModel && g_selectedInstances.at(0) != dataModel->getWorkspace())
if(g_selectedInstances.at(0)->canDelete)
{
AudioPlayer::playSound(GetFileInPath("/content/sounds/pageturn.wav"));
Instance* selectedInstance = g_selectedInstances.at(0);
@@ -378,6 +392,7 @@ void Demo::initGUI()
button->title = "Hopper";
button->fontLocationRelativeTo = Vector2(10, 3);
button->setAllColorsSame();
button->boxOutlineColorOvr = Color3(0,255,255);
button = makeTextButton();
button->boxBegin = Vector2(0, -48);
@@ -390,6 +405,7 @@ void Demo::initGUI()
button->title = "Controller";
button->fontLocationRelativeTo = Vector2(10, 3);
button->setAllColorsSame();
button->boxOutlineColorOvr = Color3(0,255,255);
button = makeTextButton();
button->boxBegin = Vector2(0, -72);
@@ -402,6 +418,7 @@ void Demo::initGUI()
button->title = "Color";
button->fontLocationRelativeTo = Vector2(10, 3);
button->setAllColorsSame();
button->boxOutlineColorOvr = Color3(0,255,255);
button = makeTextButton();
button->boxBegin = Vector2(0, -96);
@@ -414,6 +431,7 @@ void Demo::initGUI()
button->title = "Surface";
button->fontLocationRelativeTo = Vector2(10, 3);
button->setAllColorsSame();
button->boxOutlineColorOvr = Color3(0,255,255);
button = makeTextButton();
button->boxBegin = Vector2(0, -120);
@@ -422,10 +440,10 @@ void Demo::initGUI()
button->setParent(dataModel->getGuiRoot());
button->font = fntlighttrek;
button->textColor = Color3(0,255,255);
button->boxOutlineColor = Color3(0,255,255);
button->title = "Model";
button->fontLocationRelativeTo = Vector2(10, 3);
button->setAllColorsSame();
button->boxOutlineColorOvr = Color3(0,255,255);
button = makeTextButton();
button->boxBegin = Vector2(0, 0);
@@ -439,6 +457,7 @@ void Demo::initGUI()
button->textSize = 16;
button->fontLocationRelativeTo = Vector2(10, 0);
button->setAllColorsSame();
button->boxColorOvr = Color4(0.6F,0.6F,0.6F,0.4F);
button = makeTextButton();
button->boxBegin = Vector2(125, 0);
@@ -452,6 +471,7 @@ void Demo::initGUI()
button->textSize = 16;
button->fontLocationRelativeTo = Vector2(10, 0);
button->setAllColorsSame();
button->boxColorOvr = Color4(0.6F,0.6F,0.6F,0.4F);
button = makeTextButton();
button->boxBegin = Vector2(250, 0);
@@ -465,6 +485,7 @@ void Demo::initGUI()
button->textSize = 16;
button->fontLocationRelativeTo = Vector2(10, 0);
button->setAllColorsSame();
button->boxColorOvr = Color4(0.6F,0.6F,0.6F,0.4F);
button = makeTextButton();
button->boxBegin = Vector2(375, 0);
@@ -478,6 +499,7 @@ void Demo::initGUI()
button->textSize = 16;
button->fontLocationRelativeTo = Vector2(10, 0);
button->setAllColorsSame();
button->boxColorOvr = Color4(0.6F,0.6F,0.6F,0.4F);
button = makeTextButton();
button->boxBegin = Vector2(500, 0);
@@ -491,6 +513,7 @@ void Demo::initGUI()
button->textSize = 16;
button->fontLocationRelativeTo = Vector2(10, 0);
button->setAllColorsSame();
button->boxColorOvr = Color4(0.6F,0.6F,0.6F,0.4F);
@@ -502,7 +525,9 @@ void Demo::initGUI()
button->boxColor = Color4::clear();
button->textSize = 12;
button->title = "Group";
button->setAllColorsSame();
button->name = "Group";
button->setAllColorsSame();
button->textColorDis = Color3(0.8F,0.8F,0.8F);
button->font = fntlighttrek;
button->fontLocationRelativeTo = Vector2(10, 0);
button->setParent(dataModel->getGuiRoot());
@@ -516,7 +541,9 @@ void Demo::initGUI()
button->boxColor = Color4::clear();
button->textSize = 12;
button->title = "UnGroup";
button->name = "UnGroup";
button->setAllColorsSame();
button->textColorDis = Color3(0.8F,0.8F,0.8F);
button->font = fntlighttrek;
button->fontLocationRelativeTo = Vector2(10, 0);
button->setParent(dataModel->getGuiRoot());
@@ -530,6 +557,7 @@ void Demo::initGUI()
button->textSize = 12;
button->title = "Duplicate";
button->setAllColorsSame();
button->textColorDis = Color3(0.8F,0.8F,0.8F);
button->font = fntlighttrek;
button->fontLocationRelativeTo = Vector2(10, 0);
button->setParent(dataModel->getGuiRoot());
@@ -708,17 +736,16 @@ void Demo::onInit() {
initGUI();
dataModel->load();
// Say bye bye to this soon...
/*
PhysicalInstance* test = makePart();
#ifdef LEGACY_LOAD_G3DFUN_LEVEL
PartInstance* test = makePart();
test->setParent(dataModel->getWorkspace());
test->color = Color3(0.2F,0.3F,1);
test->setSize(Vector3(24,1,24));
test->setPosition(Vector3(0,0,0));
test->setCFrame(test->getCFrame() * Matrix3::fromEulerAnglesXYZ(0,toRadians(0),toRadians(0)));
test->setCFrame(test->getCFrame() * Matrix3::fromEulerAnglesXYZ(0,toRadians(54),toRadians(0)));
test = makePart();
test->setParent(dataModel->getWorkspace());
test->color = Color3(.5F,1,.5F);
@@ -730,7 +757,6 @@ void Demo::onInit() {
test->setSize(Vector3(4,1,2));
test->setPosition(Vector3(10,1,0));
test = makePart();
test->setParent(dataModel->getWorkspace());
test->color = Color3::gray();
@@ -773,7 +799,7 @@ void Demo::onInit() {
test->setSize(Vector3(4,1,2));
test->setPosition(Vector3(-2,5,0));
//dataModel->setMessageBrickCount();
test = makePart();
@@ -787,7 +813,9 @@ void Demo::onInit() {
test->color = Color3::gray();
test->setSize(Vector3(4,1,2));
test->setPosition(Vector3(2,7,0));
*/
#else
dataModel->load();
#endif
@@ -838,15 +866,55 @@ std::vector<Instance*> Demo::getSelection()
return g_selectedInstances;
}
void Demo::onSimulation(RealTime rdt, SimTime sdt, SimTime idt) {
Instance* obj = dataModel->getGuiRoot()->findFirstChild("Delete");
if(obj != NULL)
if(running)
{
std::vector <Instance* > objects = dataModel->getWorkspace()->getAllChildren();
for(size_t i = 0; i < objects.size(); i++)
{
ImageButtonInstance* button = (ImageButtonInstance*)obj;
if(g_selectedInstances.size() <= 0 || g_selectedInstances.at(0) == dataModel->getWorkspace())
button->disabled = true;
else
button->disabled = false;
if(PartInstance* moveTo = dynamic_cast<PartInstance*>(objects.at(i)))
{
moveTo->velocity.y -= (196.2F/30);
moveTo->setPosition(Vector3(moveTo->getPosition().x, moveTo->getPosition().y+(moveTo->velocity.y)/30, moveTo->getPosition().z));
if(moveTo->getPosition().y < -128)
{
moveTo->setParent(NULL);
delete moveTo;
}
}
}
}
Instance * obj6 = dataModel->getGuiRoot()->findFirstChild("Delete");
Instance * obj = dataModel->getGuiRoot()->findFirstChild("Duplicate");
Instance * obj2 = dataModel->getGuiRoot()->findFirstChild("Group");
Instance * obj3 = dataModel->getGuiRoot()->findFirstChild("UnGroup");
Instance * obj4 = dataModel->getGuiRoot()->findFirstChild("Rotate");
Instance * obj5 = dataModel->getGuiRoot()->findFirstChild("Tilt");
if(obj != NULL && obj2 != NULL && obj3 != NULL && obj4 !=NULL && obj5 != NULL && obj6 != NULL)
{
BaseButtonInstance* button = (BaseButtonInstance*)obj;
BaseButtonInstance* button2 = (BaseButtonInstance*)obj2;
BaseButtonInstance* button3 = (BaseButtonInstance*)obj3;
BaseButtonInstance* button4 = (BaseButtonInstance*)obj4;
BaseButtonInstance* button5 = (BaseButtonInstance*)obj5;
BaseButtonInstance* button6 = (BaseButtonInstance*)obj6;
button->disabled = true;
button2->disabled = true;
button3->disabled = true;
button4->disabled = true;
button5->disabled = true;
button6->disabled = true;
for(size_t i = 0; i < g_selectedInstances.size(); i++)
if(g_selectedInstances.at(i)->canDelete)
{
button->disabled = false;
button2->disabled = false;
button3->disabled = false;
button4->disabled = false;
button5->disabled = false;
button6->disabled = false;
break;
}
}
@@ -878,6 +946,8 @@ bool IsHolding(int button)
return (GetKeyState(button) >> 1)>0;
}
BOOL GetKPBool(int VK) {
return (GetKeyState(VK) & 0x8000);
}
@@ -911,32 +981,61 @@ void Demo::onUserInput(UserInput* ui) {
dataModel->mouseButton1Down = (GetKeyState(VK_LBUTTON) & 0x100) != 0;
if (GetHoldKeyState(VK_LBUTTON)) {
if(!G3D::isNaN(mouseDownOn.x))
{
if(abs(mouseDownOn.x - dataModel->mousex) > 4 || abs(mouseDownOn.y - dataModel->mousey) > 4)
{
dragging = true;
}
}
else
{
mouseDownOn = Vector2(dataModel->mousex, dataModel->mousey);
}
if (dragging) {
PhysicalInstance* part = NULL;
PartInstance* part = NULL;
if(g_selectedInstances.size() > 0)
part = (PhysicalInstance*) g_selectedInstances.at(0);
part = (PartInstance*) g_selectedInstances.at(0);
Ray dragRay = cameraController.getCamera()->worldRay(dataModel->mousex, dataModel->mousey, renderDevice->getViewport());
std::vector<Instance*> instances = dataModel->getWorkspace()->getAllChildren();
for(size_t i = 0; i < instances.size(); i++)
{
if(PhysicalInstance* moveTo = dynamic_cast<PhysicalInstance*>(instances.at(i)))
if(PartInstance* moveTo = dynamic_cast<PartInstance*>(instances.at(i)))
{
Vector3 outLocation=Vector3(0,0,0);
Vector3 outNormal=Vector3(0,0,0);
if (moveTo!=part) {
if (CollisionDetection::collisionTimeForMovingPointFixedBox(dragRay.origin,dragRay.direction*100,moveTo->getBox(),outLocation,outNormal)!=inf())
{
part->setPosition(Vector3(floor(outLocation.x),floor(outLocation.y+1),floor(outLocation.z)));
break;
}
}
/*
float __time = testRay.intersectionTime(moveTo->getBox());
float __nearest=std::numeric_limits<float>::infinity();
if (__time != inf())
if (__time != inf() && moveTo != part)
{
if (__nearest>__time)
{
Vector3 closest = (dragRay.closestPoint(moveTo->getPosition()) * 2);
part->setPosition(closest);
//part->setPosition(Vector3(floor(closest.x),part->getPosition().y,floor(closest.z)));
Vector3 closest = (dragRay.closestPoint(moveTo->getPosition()));
//part->setPosition(closest);
part->setPosition(Vector3(floor(closest.x),floor(closest.y),floor(closest.z)));
}
}
*/
}
}
Sleep(10);
}
}
else
{
dragging = false;
mouseDownOn = Vector2(nan(), 0);
}
// Camera KB Handling {
if (GetKPBool(VK_OEM_COMMA)) //Left
usableApp->cameraController.panLeft();
@@ -981,7 +1080,7 @@ void makeFlag(Vector3 &vec, RenderDevice* &rd)
bool mouseInArea(float point1x, float point1y, float point2x, float point2y)
/*bool mouseInArea(float point1x, float point1y, float point2x, float point2y)
{
@@ -993,7 +1092,7 @@ bool mouseInArea(float point1x, float point1y, float point2x, float point2y)
}
}
return false;
}
}*/
void drawButtons(RenderDevice* rd)
@@ -1020,7 +1119,7 @@ void drawOutline(Vector3 from, Vector3 to, RenderDevice* rd, LightingParameters
Draw::box(c.toWorldSpace(Box(Vector3(to.x + offsetSize, from.y - offsetSize + 0.2, from.z + offsetSize), Vector3(to.x - offsetSize, to.y + offsetSize - 0.2, from.z - offsetSize))), rd, outline, Color4::clear());
Draw::box(c.toWorldSpace(Box(Vector3(to.x + offsetSize, from.y - offsetSize + 0.2, to.z + offsetSize), Vector3(to.x - offsetSize, to.y + offsetSize-0.2, to.z - offsetSize))), rd, outline, Color4::clear());
Draw::box(c.toWorldSpace(Box(Vector3(from.x + offsetSize, from.y - offsetSize + 0.2, to.z + offsetSize), Vector3(from.x - offsetSize, to.y + offsetSize - 0.2, to.z - offsetSize))), rd, outline, Color4::clear());
//Z
Draw::box(c.toWorldSpace(Box(Vector3(from.x + offsetSize, from.y + offsetSize, from.z - offsetSize), Vector3(from.x - offsetSize, from.y - offsetSize, to.z + offsetSize))), rd, outline, Color4::clear());
Draw::box(c.toWorldSpace(Box(Vector3(from.x + offsetSize, to.y + offsetSize, from.z - offsetSize), Vector3(from.x - offsetSize, to.y - offsetSize, to.z + offsetSize))), rd, outline, Color4::clear());
@@ -1029,6 +1128,7 @@ void drawOutline(Vector3 from, Vector3 to, RenderDevice* rd, LightingParameters
if(mode == ARROWS)
{
glScalef(2,2,2);
rd->setLight(0, NULL);
rd->setAmbientLightColor(Color3(1,1,1));
@@ -1036,23 +1136,24 @@ void drawOutline(Vector3 from, Vector3 to, RenderDevice* rd, LightingParameters
c.toWorldSpace(Box(from, to)).getBounds(box);
float max = box.high().y - pos.y;
Draw::arrow(pos, Vector3(0, 1.5+max, 0), rd);
Draw::arrow(pos, Vector3(0, (-1.5)-max, 0), rd);
Draw::arrow(pos/2, Vector3(0, 1.5+max, 0), rd);
Draw::arrow(pos/2, Vector3(0, (-1.5)-max, 0), rd);
max = box.high().x - pos.x;
Draw::arrow(pos, Vector3(1.5+max, 0, 0), rd);
Draw::arrow(pos, Vector3((-1.5)-max, 0, 0), rd);
Draw::arrow(pos/2, Vector3(1.5+max, 0, 0), rd);
Draw::arrow(pos/2, Vector3((-1.5)-max, 0, 0), rd);
max = box.high().z - pos.z;
Draw::arrow(pos, Vector3(0, 0, 1.5+max), rd);
Draw::arrow(pos, Vector3(0, 0, (-1.5)-max), rd);
Draw::arrow(pos/2, Vector3(0, 0, 1.5+max), rd);
Draw::arrow(pos/2, Vector3(0, 0, (-1.5)-max), rd);
rd->setAmbientLightColor(lighting.ambient);
rd->setLight(0, GLight::directional(lighting.lightDirection, lighting.lightColor));
glScalef(1,1,1);
}
else if(mode == RESIZE)
{
@@ -1064,24 +1165,23 @@ void drawOutline(Vector3 from, Vector3 to, RenderDevice* rd, LightingParameters
float distance = pow(pow((double)gamepoint.x - (double)camerapoint.x, 2) + pow((double)gamepoint.y - (double)camerapoint.y, 2) + pow((double)gamepoint.z - (double)camerapoint.z, 2), 0.5);
if(distance < 200)
{
float multiplier = distance * 0.025F/2;
if(multiplier < 0.25F)
multiplier = 0.25F;
Vector3 position = pos + (c.lookVector()*((size.z/2)+1));
Draw::sphere(Sphere(position, multiplier), rd, sphereColor, Color4::clear());
position = pos - (c.lookVector()*((size.z/2)+1));
Draw::sphere(Sphere(position, multiplier), rd, sphereColor, Color4::clear());
Vector3 position = pos + (c.lookVector()*((size.z)+2));
Draw::sphere(Sphere(position, multiplier*2), rd, sphereColor, Color4::clear());
position = pos - (c.lookVector()*((size.z)+2));
Draw::sphere(Sphere(position, multiplier*2), rd, sphereColor, Color4::clear());
position = pos + (c.rightVector()*((size.x/2)+1));
Draw::sphere(Sphere(position, multiplier), rd, sphereColor, Color4::clear());
position = pos - (c.rightVector()*((size.x/2)+1));
Draw::sphere(Sphere(position, multiplier), rd, sphereColor, Color4::clear());
position = pos + (c.rightVector()*((size.x)+2));
Draw::sphere(Sphere(position, multiplier*2), rd, sphereColor, Color4::clear());
position = pos - (c.rightVector()*((size.x)+2));
Draw::sphere(Sphere(position, multiplier*2), rd, sphereColor, Color4::clear());
position = pos + (c.upVector()*((size.y/2)+1));
Draw::sphere(Sphere(position, multiplier), rd, sphereColor, Color4::clear());
position = pos - (c.upVector()*((size.y/2)+1));
Draw::sphere(Sphere(position, multiplier), rd, sphereColor, Color4::clear());
position = pos + (c.upVector()*((size.y)+2));
Draw::sphere(Sphere(position, multiplier*2), rd, sphereColor, Color4::clear());
position = pos - (c.upVector()*((size.y)+2));
Draw::sphere(Sphere(position, multiplier*2), rd, sphereColor, Color4::clear());
}
rd->setAmbientLightColor(lighting.ambient);
rd->setLight(0, GLight::directional(lighting.lightDirection, lighting.lightColor));
@@ -1098,16 +1198,20 @@ void Demo::exitApplication()
void Demo::onGraphics(RenderDevice* rd) {
G3D::uint8 num = 0;
POINT mousepos;
mouseOnScreen = true;
if (GetCursorPos(&mousepos))
{
POINT pointm = mousepos;
if (ScreenToClient(_hWndMain, &mousepos))
{
//mouseOnScreen = true;
if(mousepos.x < 1 || mousepos.y < 1 || mousepos.x >= rd->getViewport().width()-1 || mousepos.y >= rd->getViewport().height()-1)
//POINT pointm;
///GetCursorPos(&pointm);
if(_hwndRenderer != WindowFromPoint(pointm)) //OLD: mousepos.x < 1 || mousepos.y < 1 || mousepos.x >= rd->getViewport().width()-1 || mousepos.y >= rd->getViewport().height()-1
{
mouseOnScreen = false;
//ShowCursor(true);
@@ -1125,6 +1229,8 @@ void Demo::onGraphics(RenderDevice* rd) {
}
}
if(Globals::useMousePoint)
{
mousepos = Globals::mousepoint;
@@ -1132,6 +1238,20 @@ void Demo::onGraphics(RenderDevice* rd) {
}
LightingParameters lighting(G3D::toSeconds(11, 00, 00, AM));
Matrix4 lightProjectionMatrix(Matrix4::orthogonalProjection(-lightProjX, lightProjX, -lightProjY, lightProjY, lightProjNear, lightProjFar));
CoordinateFrame lightCFrame;
lightCFrame.lookAt(-lighting.lightDirection, Vector3::unitY());
lightCFrame.translation = lighting.lightDirection * 20;
Matrix4 lightMVP = lightProjectionMatrix * lightCFrame.inverse();
if (GLCaps::supports_GL_ARB_shadow()) {
generateShadowMap(lightCFrame);
}
renderDevice->setProjectionAndCameraMatrix(*cameraController.getCamera());
// Cyan background
@@ -1150,20 +1270,38 @@ void Demo::onGraphics(RenderDevice* rd) {
renderDevice->setLight(0, GLight::directional(lighting.lightDirection, lighting.lightColor));
renderDevice->setAmbientLightColor(lighting.ambient);
/*
Vector3 gamepoint = Vector3(0, 5, 0);
Vector3 camerapoint = rd->getCameraToWorldMatrix().translation;
float distance = pow(pow((double)gamepoint.x - (double)camerapoint.x, 2) + pow((double)gamepoint.y - (double)camerapoint.y, 2) + pow((double)gamepoint.z - (double)camerapoint.z, 2), 0.5);
if(distance < 50 && distance > -50)
{
if(distance < 0)
distance = distance*-1;
fntdominant->draw3D(rd, "Testing", CoordinateFrame(rd->getCameraToWorldMatrix().rotation, gamepoint), 0.04*distance, Color3::yellow(), Color3::black(), G3D::GFont::XALIGN_CENTER, G3D::GFont::YALIGN_CENTER);
}
*/
rd->pushState();
if (GLCaps::supports_GL_ARB_shadow()) {
rd->configureShadowMap(1, lightMVP, shadowMap);
}
rd->beforePrimitive();
dataModel->getWorkspace()->render(rd);
//if (dataModel->children[0]->children.size()>0)
//((PhysicalInstance*)dataModel->children[0]->children[0])->debugPrintVertexIDs(rd,fntdominant,-cameraController.getCoordinateFrame().rotation);
//((PartInstance*)dataModel->children[0]->children[0])->debugPrintVertexIDs(rd,fntdominant,-cameraController.getCoordinateFrame().rotation);
rd->afterPrimitive();
rd->popState();
if(g_selectedInstances.size() > 0)
{
for(size_t i = 0; i < g_selectedInstances.size(); i++)
{
if(PhysicalInstance* part = dynamic_cast<PhysicalInstance*>(g_selectedInstances.at(i)))
if(PartInstance* part = dynamic_cast<PartInstance*>(g_selectedInstances.at(i)))
{
Vector3 size = part->getSize();
Vector3 pos = part->getPosition();
@@ -1173,16 +1311,18 @@ void Demo::onGraphics(RenderDevice* rd) {
}
//Vector3 gamepoint = Vector3(0, 5, 0);
//Vector3 camerapoint = rd->getCameraToWorldMatrix().translation;
//float distance = pow(pow((double)gamepoint.x - (double)camerapoint.x, 2) + pow((double)gamepoint.y - (double)camerapoint.y, 2) + pow((double)gamepoint.z - (double)camerapoint.z, 2), 0.5);
//if(distance < 50 && distance > -50)
//{
// if(distance < 0)
// distance = distance*-1;
// fntdominant->draw3D(rd, "Testing", CoordinateFrame(rd->getCameraToWorldMatrix().rotation, gamepoint), 0.04*distance, Color3::yellow(), Color3::black(), G3D::GFont::XALIGN_CENTER, G3D::GFont::YALIGN_CENTER);
//}
while(!postRenderStack.empty())
{
Instance* inst = postRenderStack.at(0);
postRenderStack.erase(postRenderStack.begin());
if(PVInstance* pinst = dynamic_cast<PVInstance*>(inst))
{
pinst->postRender(rd);
}
}
renderDevice->disableLighting();
@@ -1202,9 +1342,9 @@ void Demo::onGraphics(RenderDevice* rd) {
fntdominant->draw2D(rd, "FPS: " + stream.str(), Vector2(120, 25), 10, Color3::fromARGB(0xFFFF00), Color3::black());
stream.str("");
stream.clear();
stream << std::fixed << std::setprecision(1) << dataModel->getWorkspace()->timer;
stream << std::fixed << std::setprecision(1) << dataModel->getLevel()->timer;
fntdominant->draw2D(rd, "Timer: " + stream.str(), Vector2(rd->getWidth() - 120, 25), 20, Color3::fromARGB(0x81C518), Color3::black());
fntdominant->draw2D(rd, "Score: " + Convert(dataModel->getWorkspace()->score), Vector2(rd->getWidth() - 120, 50), 20, Color3::fromARGB(0x81C518), Color3::black());
fntdominant->draw2D(rd, "Score: " + Convert(dataModel->getLevel()->score), Vector2(rd->getWidth() - 120, 50), 20, Color3::fromARGB(0x81C518), Color3::black());
//GUI Boxes
Draw::box(G3D::Box(Vector3(0,25,0),Vector3(80,355,0)),rd,Color4(0.6F,0.6F,0.6F,0.4F), Color4(0,0,0,0));
@@ -1230,19 +1370,49 @@ void Demo::onGraphics(RenderDevice* rd) {
glEnable(GL_BLEND);// you enable blending function
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
std::vector<Instance*> instances = dataModel->getWorkspace()->getAllChildren();
currentcursorid = cursorid;
bool onGUI = false;
std::vector<Instance*> guis = dataModel->getGuiRoot()->getAllChildren();
for(size_t i = 0; i < guis.size(); i++)
{
if(BaseButtonInstance* button = dynamic_cast<BaseButtonInstance*>(guis.at(i)))
{
if(button->mouseInButton(dataModel->mousex,dataModel->mousey, renderDevice))
{
onGUI = true;
break;
}
}
}
if(!onGUI)
for(size_t i = 0; i < instances.size(); i++)
{
if(PartInstance* test = dynamic_cast<PartInstance*>(instances.at(i)))
{
float time = cameraController.getCamera()->worldRay(dataModel->mousex, dataModel->mousey, renderDevice->getViewport()).intersectionTime(test->getBox());
//float time = testRay.intersectionTime(test->getBox());
if (time != inf())
{
currentcursorid = cursorOvrid;
break;
}
}
}
glBindTexture( GL_TEXTURE_2D, cursorid);
glBindTexture( GL_TEXTURE_2D, currentcursorid);
glBegin( GL_QUADS );
glTexCoord2d(0.0,0.0);
glVertex2f(mousepos.x-40, mousepos.y-40);
glVertex2f(mousepos.x-64, mousepos.y-64);
glTexCoord2d( 1.0,0.0 );
glVertex2f(mousepos.x+40, mousepos.y-40);
glVertex2f(mousepos.x+64, mousepos.y-64);
glTexCoord2d(1.0,1.0 );
glVertex2f(mousepos.x+40, mousepos.y+40 );
glVertex2f(mousepos.x+64, mousepos.y+64 );
glTexCoord2d( 0.0,1.0 );
glVertex2f( mousepos.x-40, mousepos.y+40 );
glVertex2f( mousepos.x-64, mousepos.y+64 );
glEnd();
glDisable( GL_TEXTURE_2D );
@@ -1251,6 +1421,7 @@ void Demo::onGraphics(RenderDevice* rd) {
rd->afterPrimitive();
rd->popState();
renderDevice->pop2D();
debugAssertGLOk();
}
void Demo::onKeyPressed(int key)
@@ -1267,7 +1438,10 @@ void Demo::onKeyUp(int key)
void Demo::onMouseLeftPressed(HWND hwnd,int x,int y)
{
SetFocus(hwnd);
//Removed set focus
std::cout << "Click: " << x << "," << y << std::endl;
@@ -1293,7 +1467,7 @@ void Demo::onMouseLeftPressed(HWND hwnd,int x,int y)
bool objFound = false;
for(size_t i = 0; i < instances.size(); i++)
{
if(PhysicalInstance* test = dynamic_cast<PhysicalInstance*>(instances.at(i)))
if(PartInstance* test = dynamic_cast<PartInstance*>(instances.at(i)))
{
float time = testRay.intersectionTime(test->getBox());
@@ -1332,8 +1506,8 @@ void Demo::onMouseLeftPressed(HWND hwnd,int x,int y)
{
while(g_selectedInstances.size() > 0)
g_selectedInstances.erase(g_selectedInstances.begin());
g_selectedInstances.push_back(dataModel->getWorkspace());
_propWindow->SetProperties(dataModel->getWorkspace());
g_selectedInstances.push_back(dataModel);
_propWindow->SetProperties(dataModel);
}
}
@@ -1346,7 +1520,7 @@ void Demo::onMouseLeftUp(int x,int y)
//message = "Dragging = false.";
//messageTime = System::time();
std::vector<Instance*> instances_2D = dataModel->getGuiRoot()->getAllChildren();
std::vector<Instance*> instances = dataModel->getWorkspace()->getAllChildren();
//std::vector<Instance*> instances = dataModel->getWorkspace()->getAllChildren();
for(size_t i = 0; i < instances_2D.size(); i++)
{
if(BaseButtonInstance* button = dynamic_cast<BaseButtonInstance*>(instances_2D[i]))
@@ -1366,7 +1540,7 @@ void Demo::onMouseRightUp(int x,int y)
}
void Demo::onMouseMoved(int x,int y)
{
oldMouse = dataModel->getMousePos();
//oldMouse = dataModel->getMousePos();
dataModel->mousex = x;
dataModel->mousey = y;
@@ -1492,6 +1666,27 @@ LRESULT CALLBACK G3DProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
case WM_MOUSEMOVE:
app->onMouseMoved(LOWORD(lParam),HIWORD(lParam));
break;
case WM_KEYDOWN:
if ((HIWORD(lParam)&0x4000)==0) // single key press
{
app->onKeyPressed(wParam);
}
break;
case WM_KEYUP:
{
app->onKeyUp(wParam);
}
break;
case WM_SYSKEYDOWN:
if ((HIWORD(lParam)&0x4000)==0) // single key press
{
app->onKeyPressed(wParam);
}
break;
case WM_SYSKEYUP:
{
app->onKeyUp(wParam);
}
case WM_SIZE:
{
app->onGraphics(app->renderDevice);
@@ -1505,6 +1700,37 @@ LRESULT CALLBACK G3DProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
return 0;
}
void Demo::generateShadowMap(const CoordinateFrame& lightViewMatrix) const {
//debugAssert(shadowMapSize < app->renderDevice->getHeight());
//debugAssert(shadowMapSize < app->renderDevice->getWidth());
//app->renderDevice->clear(debugLightMap, true, false);
Rect2D rect = Rect2D::xywh(0, 0, 512, 512);
renderDevice->pushState();
renderDevice->setViewport(rect);
// Draw from the light's point of view
renderDevice->setProjectionMatrix(Matrix4::orthogonalProjection(-lightProjX, lightProjX, -lightProjY, lightProjY, lightProjNear, lightProjFar));
renderDevice->setCameraToWorldMatrix(lightViewMatrix);
renderDevice->disableColorWrite();
// We can choose to use a large bias or render from
// the backfaces in order to avoid front-face self
// shadowing. Here, we use a large offset.
renderDevice->setPolygonOffset(8);
dataModel->render(renderDevice);
renderDevice->popState();
shadowMap->copyFromScreen(rect);
}
void Demo::run() {
usableApp = this;
//setDebugMode(false);
@@ -1526,7 +1752,8 @@ void Demo::run() {
UpdateWindow(_hWndMain);
// Load objects here=
cursor = Texture::fromFile(GetFileInPath("/content/cursor2.png"));
cursor = Texture::fromFile(GetFileInPath("/content/images/ArrowCursor.png"));
cursorOvr = Texture::fromFile(GetFileInPath("/content/images/DragCursor.png"));
Globals::surface = Texture::fromFile(GetFileInPath("/content/images/surfacebr.png"));
Globals::surfaceId = Globals::surface->getOpenGLID();
fntdominant = GFont::fromFile(GetFileInPath("/content/font/dominant.fnt"));
@@ -1535,8 +1762,17 @@ void Demo::run() {
clickSound = GetFileInPath("/content/sounds/switch.wav");
dingSound = GetFileInPath("/content/sounds/electronicpingshort.wav");
sky = Sky::create(NULL, ExePath() + "/content/sky/");
cursorid = cursor->openGLID();
if (GLCaps::supports_GL_ARB_shadow()) {
shadowMap = Texture::createEmpty(512, 512, "Shadow map", TextureFormat::depth(),
Texture::CLAMP, Texture::BILINEAR_NO_MIPMAP, Texture::DIM_2D, Texture::DEPTH_LEQUAL);
}
cursorid = cursor->openGLID();
currentcursorid = cursorid;
cursorOvrid = cursorOvr->openGLID();
RealTime now=0, lastTime=0;
double simTimeRate = 1.0f;
float fps=30.0f;