2010-03-13 10:39:22 +00:00
|
|
|
#include "main.h"
|
|
|
|
|
|
|
|
#include <stdexcept>
|
|
|
|
|
2010-03-13 22:00:01 +00:00
|
|
|
#include "model_gl.h"
|
2010-03-13 10:39:22 +00:00
|
|
|
#include "graphics_interface.h"
|
|
|
|
#include "util.h"
|
|
|
|
#include "conversion.h"
|
2010-05-25 18:06:42 +00:00
|
|
|
#include "platform_common.h"
|
|
|
|
#include "xml_parser.h"
|
2010-05-25 18:51:35 +00:00
|
|
|
#include <iostream>
|
2010-03-13 10:39:22 +00:00
|
|
|
|
|
|
|
using namespace Shared::Platform;
|
2010-05-25 18:06:42 +00:00
|
|
|
using namespace Shared::PlatformCommon;
|
2010-03-13 10:39:22 +00:00
|
|
|
using namespace Shared::Graphics;
|
|
|
|
using namespace Shared::Graphics::Gl;
|
|
|
|
using namespace Shared::Util;
|
2010-05-25 18:06:42 +00:00
|
|
|
using namespace Shared::Xml;
|
2010-03-13 10:39:22 +00:00
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
2010-06-24 13:18:11 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
const char *folderDelimiter = "\\";
|
|
|
|
#else
|
|
|
|
const char *folderDelimiter = "/";
|
|
|
|
#endif
|
|
|
|
|
2010-03-13 10:39:22 +00:00
|
|
|
namespace Shared{ namespace G3dViewer{
|
|
|
|
|
|
|
|
// ===============================================
|
|
|
|
// class Global functions
|
|
|
|
// ===============================================
|
|
|
|
|
|
|
|
wxString ToUnicode(const char* str) {
|
|
|
|
return wxString(str, wxConvUTF8);
|
|
|
|
}
|
|
|
|
|
|
|
|
wxString ToUnicode(const string& str) {
|
|
|
|
return wxString(str.c_str(), wxConvUTF8);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ===============================================
|
|
|
|
// class MainWindow
|
|
|
|
// ===============================================
|
|
|
|
|
|
|
|
const string MainWindow::versionString= "v1.3.5-beta1";
|
|
|
|
const string MainWindow::winHeader= "G3D viewer " + versionString + " - Built: " + __DATE__;
|
|
|
|
|
|
|
|
MainWindow::MainWindow(const string &modelPath)
|
|
|
|
: wxFrame(NULL, -1, ToUnicode(winHeader),wxPoint(Renderer::windowX, Renderer::windowY),
|
|
|
|
wxSize(Renderer::windowW, Renderer::windowH))
|
|
|
|
{
|
|
|
|
//getGlPlatformExtensions();
|
|
|
|
renderer= Renderer::getInstance();
|
2010-05-25 18:06:42 +00:00
|
|
|
if(modelPath != "") {
|
|
|
|
this->modelPathList.push_back(modelPath);
|
|
|
|
}
|
2010-03-13 10:39:22 +00:00
|
|
|
model= NULL;
|
|
|
|
playerColor= Renderer::pcRed;
|
|
|
|
|
|
|
|
speed= 0.025f;
|
|
|
|
|
|
|
|
glCanvas = new GlCanvas(this);
|
|
|
|
|
|
|
|
//getGlPlatformExtensions();
|
|
|
|
|
|
|
|
//glCanvas->SetCurrent();
|
|
|
|
//renderer->init();
|
|
|
|
|
|
|
|
menu= new wxMenuBar();
|
|
|
|
|
|
|
|
//menu
|
|
|
|
menuFile= new wxMenu();
|
|
|
|
menuFile->Append(miFileLoad, wxT("Load"));
|
2010-05-25 18:06:42 +00:00
|
|
|
menuFile->Append(miFileLoadParticleXML, wxT("Load Particle XML"));
|
2010-06-24 10:52:58 +00:00
|
|
|
menuFile->Append(miFileLoadProjectileParticleXML, wxT("Load Projectile Particle XML"));
|
2010-03-13 10:39:22 +00:00
|
|
|
menu->Append(menuFile, wxT("File"));
|
|
|
|
|
|
|
|
//mode
|
|
|
|
menuMode= new wxMenu();
|
|
|
|
menuMode->AppendCheckItem(miModeNormals, wxT("Normals"));
|
|
|
|
menuMode->AppendCheckItem(miModeWireframe, wxT("Wireframe"));
|
|
|
|
menuMode->AppendCheckItem(miModeGrid, wxT("Grid"));
|
|
|
|
menu->Append(menuMode, wxT("Mode"));
|
|
|
|
|
|
|
|
//mode
|
|
|
|
menuSpeed= new wxMenu();
|
|
|
|
menuSpeed->Append(miSpeedSlower, wxT("Slower"));
|
|
|
|
menuSpeed->Append(miSpeedFaster, wxT("Faster"));
|
|
|
|
menu->Append(menuSpeed, wxT("Speed"));
|
|
|
|
|
|
|
|
//custom color
|
|
|
|
menuCustomColor= new wxMenu();
|
|
|
|
menuCustomColor->AppendCheckItem(miColorRed, wxT("Red"));
|
|
|
|
menuCustomColor->AppendCheckItem(miColorBlue, wxT("Blue"));
|
|
|
|
menuCustomColor->AppendCheckItem(miColorYellow, wxT("Yellow"));
|
|
|
|
menuCustomColor->AppendCheckItem(miColorGreen, wxT("Green"));
|
|
|
|
menu->Append(menuCustomColor, wxT("Custom Color"));
|
|
|
|
|
|
|
|
menuMode->Check(miModeGrid, true);
|
|
|
|
menuCustomColor->Check(miColorRed, true);
|
|
|
|
|
|
|
|
SetMenuBar(menu);
|
|
|
|
|
|
|
|
//misc
|
|
|
|
model= NULL;
|
|
|
|
rotX= 0.0f;
|
|
|
|
rotY= 0.0f;
|
|
|
|
zoom= 1.0f;
|
|
|
|
lastX= 0;
|
|
|
|
lastY= 0;
|
|
|
|
anim= 0.0f;
|
|
|
|
|
|
|
|
CreateStatusBar();
|
|
|
|
|
|
|
|
timer = new wxTimer(this);
|
|
|
|
timer->Start(100);
|
|
|
|
|
|
|
|
glCanvas->SetFocus();
|
|
|
|
}
|
|
|
|
|
|
|
|
MainWindow::~MainWindow(){
|
|
|
|
delete renderer;
|
|
|
|
delete model;
|
|
|
|
delete timer;
|
|
|
|
delete glCanvas;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::init(){
|
|
|
|
glCanvas->SetCurrent();
|
|
|
|
renderer->init();
|
|
|
|
|
2010-05-25 18:06:42 +00:00
|
|
|
loadModel("");
|
2010-03-13 10:39:22 +00:00
|
|
|
|
|
|
|
//SetTitle(ToUnicode(winHeader + "; " + modelPath));
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::onPaint(wxPaintEvent &event){
|
|
|
|
renderer->reset(GetClientSize().x, GetClientSize().y, playerColor);
|
|
|
|
|
|
|
|
renderer->transform(rotX, rotY, zoom);
|
|
|
|
renderer->renderGrid();
|
|
|
|
|
|
|
|
renderer->renderTheModel(model, anim);
|
|
|
|
|
2010-05-25 18:06:42 +00:00
|
|
|
//int updateLoops = 100;
|
|
|
|
int updateLoops = 1;
|
|
|
|
for(int i=0; i< updateLoops; ++i) {
|
|
|
|
renderer->updateParticleManager();
|
|
|
|
}
|
|
|
|
|
|
|
|
renderer->renderParticleManager();
|
|
|
|
|
2010-03-13 10:39:22 +00:00
|
|
|
glCanvas->SwapBuffers();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::onClose(wxCloseEvent &event){
|
|
|
|
delete this;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::onMouseMove(wxMouseEvent &event){
|
|
|
|
int x= event.GetX();
|
|
|
|
int y= event.GetY();
|
|
|
|
wxPaintEvent paintEvent;
|
|
|
|
|
|
|
|
if(event.LeftIsDown()){
|
|
|
|
rotX+= clamp(lastX-x, -10, 10);
|
|
|
|
rotY+= clamp(lastY-y, -10, 10);
|
|
|
|
onPaint(paintEvent);
|
|
|
|
}
|
|
|
|
else if(event.RightIsDown()){
|
|
|
|
zoom*= 1.0f+(lastX-x+lastY-y)/100.0f;
|
|
|
|
zoom= clamp(zoom, 0.1f, 10.0f);
|
|
|
|
onPaint(paintEvent);
|
|
|
|
}
|
|
|
|
|
|
|
|
lastX= x;
|
|
|
|
lastY= y;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::onMenuFileLoad(wxCommandEvent &event){
|
|
|
|
string fileName;
|
|
|
|
wxFileDialog fileDialog(this);
|
|
|
|
fileDialog.SetWildcard(wxT("G3D files (*.g3d)|*.g3d"));
|
|
|
|
if(fileDialog.ShowModal()==wxID_OK){
|
2010-05-25 18:06:42 +00:00
|
|
|
modelPathList.clear();
|
|
|
|
loadModel((const char*)wxFNCONV(fileDialog.GetPath().c_str()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::onMenuFileLoadParticleXML(wxCommandEvent &event){
|
|
|
|
string fileName;
|
|
|
|
wxFileDialog fileDialog(this);
|
|
|
|
fileDialog.SetWildcard(wxT("XML files (*.xml)|*.xml"));
|
|
|
|
if(fileDialog.ShowModal()==wxID_OK){
|
|
|
|
string path = (const char*)wxFNCONV(fileDialog.GetPath().c_str());
|
|
|
|
loadParticle(path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-24 10:52:58 +00:00
|
|
|
void MainWindow::onMenuFileLoadProjectileParticleXML(wxCommandEvent &event){
|
|
|
|
string fileName;
|
|
|
|
wxFileDialog fileDialog(this);
|
|
|
|
fileDialog.SetWildcard(wxT("XML files (*.xml)|*.xml"));
|
|
|
|
if(fileDialog.ShowModal()==wxID_OK){
|
|
|
|
string path = (const char*)wxFNCONV(fileDialog.GetPath().c_str());
|
|
|
|
loadProjectileParticle(path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-25 18:06:42 +00:00
|
|
|
void MainWindow::loadModel(string path) {
|
|
|
|
if(path != "" && fileExists(path) == true) {
|
|
|
|
this->modelPathList.push_back(path);
|
|
|
|
}
|
|
|
|
|
|
|
|
for(int idx =0; idx < this->modelPathList.size(); idx++) {
|
|
|
|
string modelPath = this->modelPathList[idx];
|
|
|
|
|
|
|
|
//this->modelPath = path;
|
2010-03-13 10:39:22 +00:00
|
|
|
delete model;
|
|
|
|
Model *tmpModel= new ModelGl();
|
2010-05-25 18:06:42 +00:00
|
|
|
renderer->loadTheModel(tmpModel, modelPath);
|
2010-03-13 10:39:22 +00:00
|
|
|
model= tmpModel;
|
|
|
|
GetStatusBar()->SetStatusText(ToUnicode(getModelInfo().c_str()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-25 18:06:42 +00:00
|
|
|
void MainWindow::loadParticle(string path) {
|
|
|
|
if(path != "" && fileExists(path) == true) {
|
|
|
|
this->particlePathList.push_back(path);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(this->particlePathList.size() > 0) {
|
2010-06-24 10:52:58 +00:00
|
|
|
renderer->initModelManager();
|
|
|
|
|
2010-05-25 18:06:42 +00:00
|
|
|
for(int idx = 0; idx < this->particlePathList.size(); idx++) {
|
|
|
|
string particlePath = this->particlePathList[idx];
|
|
|
|
string dir= extractDirectoryPathFromFile(particlePath);
|
|
|
|
|
2010-06-24 13:18:11 +00:00
|
|
|
size_t pos = dir.find_last_of(folderDelimiter);
|
2010-05-25 18:06:42 +00:00
|
|
|
if(pos == dir.length()-1) {
|
|
|
|
dir.erase(dir.length() -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
particlePath= extractFileFromDirectoryPath(particlePath);
|
|
|
|
|
2010-06-24 13:18:11 +00:00
|
|
|
std::string unitXML = dir + folderDelimiter + extractFileFromDirectoryPath(dir) + ".xml";
|
2010-05-25 18:06:42 +00:00
|
|
|
|
|
|
|
int size = -1;
|
|
|
|
int height = -1;
|
|
|
|
|
|
|
|
if(fileExists(unitXML) == true) {
|
|
|
|
XmlTree xmlTree;
|
|
|
|
xmlTree.load(unitXML);
|
|
|
|
const XmlNode *unitNode= xmlTree.getRootNode();
|
|
|
|
const XmlNode *parametersNode= unitNode->getChild("parameters");
|
|
|
|
//size
|
|
|
|
size= parametersNode->getChild("size")->getAttribute("value")->getIntValue();
|
|
|
|
//height
|
|
|
|
height= parametersNode->getChild("height")->getAttribute("value")->getIntValue();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::cout << "About to load [" << particlePath << "] from [" << dir << "] unit [" << unitXML << "]" << std::endl;
|
|
|
|
|
|
|
|
UnitParticleSystemType *unitParticleSystemType= new UnitParticleSystemType();
|
2010-06-24 13:18:11 +00:00
|
|
|
unitParticleSystemType->load(dir, dir + folderDelimiter + particlePath, renderer);
|
2010-05-25 18:06:42 +00:00
|
|
|
unitParticleSystemTypes.push_back(unitParticleSystemType);
|
|
|
|
|
|
|
|
for(std::vector<UnitParticleSystemType *>::const_iterator it= unitParticleSystemTypes.begin(); it != unitParticleSystemTypes.end(); ++it) {
|
|
|
|
UnitParticleSystem *ups= new UnitParticleSystem(200);
|
|
|
|
(*it)->setValues(ups);
|
|
|
|
if(size > 0) {
|
|
|
|
//getCurrVectorFlat() + Vec3f(0.f, type->getHeight()/2.f, 0.f);
|
|
|
|
Vec3f vec = Vec3f(0.f, height / 2.f, 0.f);
|
|
|
|
ups->setPos(vec);
|
|
|
|
}
|
|
|
|
//ups->setFactionColor(getFaction()->getTexture()->getPixmap()->getPixel3f(0,0));
|
|
|
|
ups->setFactionColor(renderer->getPlayerColorTexture(playerColor)->getPixmap()->getPixel3f(0,0));
|
|
|
|
unitParticleSystems.push_back(ups);
|
|
|
|
renderer->manageParticleSystem(ups);
|
|
|
|
|
|
|
|
ups->setVisible(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
renderer->initTextureManager();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-24 10:52:58 +00:00
|
|
|
void MainWindow::loadProjectileParticle(string path) {
|
|
|
|
if(path != "" && fileExists(path) == true) {
|
|
|
|
this->particleProjectilePathList.push_back(path);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(this->particleProjectilePathList.size() > 0) {
|
|
|
|
renderer->initModelManager();
|
|
|
|
|
|
|
|
for(int idx = 0; idx < this->particleProjectilePathList.size(); idx++) {
|
|
|
|
string particlePath = this->particleProjectilePathList[idx];
|
|
|
|
string dir= extractDirectoryPathFromFile(particlePath);
|
|
|
|
|
2010-06-24 13:18:11 +00:00
|
|
|
size_t pos = dir.find_last_of(folderDelimiter);
|
2010-06-24 10:52:58 +00:00
|
|
|
if(pos == dir.length()-1) {
|
|
|
|
dir.erase(dir.length() -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
particlePath= extractFileFromDirectoryPath(particlePath);
|
|
|
|
|
2010-06-24 13:18:11 +00:00
|
|
|
std::string unitXML = dir + folderDelimiter + extractFileFromDirectoryPath(dir) + ".xml";
|
2010-06-24 10:52:58 +00:00
|
|
|
|
|
|
|
int size = -1;
|
|
|
|
int height = -1;
|
|
|
|
|
|
|
|
if(fileExists(unitXML) == true) {
|
|
|
|
XmlTree xmlTree;
|
|
|
|
xmlTree.load(unitXML);
|
|
|
|
const XmlNode *unitNode= xmlTree.getRootNode();
|
|
|
|
const XmlNode *parametersNode= unitNode->getChild("parameters");
|
|
|
|
//size
|
|
|
|
size= parametersNode->getChild("size")->getAttribute("value")->getIntValue();
|
|
|
|
//height
|
|
|
|
height= parametersNode->getChild("height")->getAttribute("value")->getIntValue();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::cout << "About to load [" << particlePath << "] from [" << dir << "] unit [" << unitXML << "]" << std::endl;
|
|
|
|
|
|
|
|
XmlTree xmlTree;
|
2010-06-24 13:18:11 +00:00
|
|
|
xmlTree.load(dir + folderDelimiter + particlePath);
|
2010-06-24 10:52:58 +00:00
|
|
|
const XmlNode *particleSystemNode= xmlTree.getRootNode();
|
|
|
|
|
|
|
|
std::cout << "Loaded successfully, loading values..." << std::endl;
|
|
|
|
|
|
|
|
ParticleSystemTypeProjectile *projectileParticleSystemType= new ParticleSystemTypeProjectile();
|
2010-06-24 13:18:11 +00:00
|
|
|
projectileParticleSystemType->load(dir, dir + folderDelimiter + particlePath,renderer);
|
2010-06-24 10:52:58 +00:00
|
|
|
|
|
|
|
std::cout << "Values loaded, about to read..." << std::endl;
|
|
|
|
|
|
|
|
projectileParticleSystemTypes.push_back(projectileParticleSystemType);
|
|
|
|
|
|
|
|
for(std::vector<ParticleSystemTypeProjectile *>::const_iterator it= projectileParticleSystemTypes.begin(); it != projectileParticleSystemTypes.end(); ++it) {
|
|
|
|
|
|
|
|
ProjectileParticleSystem *ps = (*it)->create();
|
|
|
|
|
|
|
|
if(size > 0) {
|
|
|
|
Vec3f vec = Vec3f(0.f, height / 2.f, 0.f);
|
|
|
|
//ps->setPos(vec);
|
|
|
|
|
|
|
|
Vec3f vec2 = Vec3f(size * 2.f, height * 2.f, height * 2.f);
|
|
|
|
ps->setPath(vec, vec2);
|
|
|
|
}
|
|
|
|
ps->setFactionColor(renderer->getPlayerColorTexture(playerColor)->getPixmap()->getPixel3f(0,0));
|
|
|
|
|
|
|
|
projectileParticleSystems.push_back(ps);
|
|
|
|
|
|
|
|
ps->setVisible(true);
|
|
|
|
renderer->manageParticleSystem(ps);
|
|
|
|
|
2010-06-24 13:18:11 +00:00
|
|
|
//MessageBox(NULL,"hi","hi",MB_OK);
|
2010-06-24 10:52:58 +00:00
|
|
|
//psProj= pstProj->create();
|
|
|
|
//psProj->setPath(startPos, endPos);
|
|
|
|
//psProj->setObserver(new ParticleDamager(unit, this, gameCamera));
|
|
|
|
//psProj->setVisible(visible);
|
|
|
|
//psProj->setFactionColor(unit->getFaction()->getTexture()->getPixmap()->getPixel3f(0,0));
|
|
|
|
//renderer.manageParticleSystem(psProj, rsGame);
|
|
|
|
}
|
|
|
|
|
|
|
|
renderer->initTextureManager();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-13 10:39:22 +00:00
|
|
|
void MainWindow::onMenuModeNormals(wxCommandEvent &event){
|
|
|
|
renderer->toggleNormals();
|
|
|
|
menuMode->Check(miModeNormals, renderer->getNormals());
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::onMenuModeWireframe(wxCommandEvent &event){
|
|
|
|
renderer->toggleWireframe();
|
|
|
|
menuMode->Check(miModeWireframe, renderer->getWireframe());
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::onMenuModeGrid(wxCommandEvent &event){
|
|
|
|
renderer->toggleGrid();
|
|
|
|
menuMode->Check(miModeGrid, renderer->getGrid());
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::onMenuSpeedSlower(wxCommandEvent &event){
|
|
|
|
speed/= 1.5f;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::onMenuSpeedFaster(wxCommandEvent &event){
|
|
|
|
speed*= 1.5f;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::onMenuColorRed(wxCommandEvent &event){
|
|
|
|
playerColor= Renderer::pcRed;
|
|
|
|
menuCustomColor->Check(miColorRed, true);
|
|
|
|
menuCustomColor->Check(miColorBlue, false);
|
|
|
|
menuCustomColor->Check(miColorYellow, false);
|
|
|
|
menuCustomColor->Check(miColorGreen, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::onMenuColorBlue(wxCommandEvent &event){
|
|
|
|
playerColor= Renderer::pcBlue;
|
|
|
|
menuCustomColor->Check(miColorRed, false);
|
|
|
|
menuCustomColor->Check(miColorBlue, true);
|
|
|
|
menuCustomColor->Check(miColorYellow, false);
|
|
|
|
menuCustomColor->Check(miColorGreen, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::onMenuColorYellow(wxCommandEvent &event){
|
|
|
|
playerColor= Renderer::pcYellow;
|
|
|
|
menuCustomColor->Check(miColorRed, false);
|
|
|
|
menuCustomColor->Check(miColorBlue, false);
|
|
|
|
menuCustomColor->Check(miColorYellow, true);
|
|
|
|
menuCustomColor->Check(miColorGreen, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::onMenuColorGreen(wxCommandEvent &event){
|
|
|
|
playerColor= Renderer::pcGreen;
|
|
|
|
menuCustomColor->Check(miColorRed, false);
|
|
|
|
menuCustomColor->Check(miColorBlue, false);
|
|
|
|
menuCustomColor->Check(miColorYellow, false);
|
|
|
|
menuCustomColor->Check(miColorGreen, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::onTimer(wxTimerEvent &event){
|
|
|
|
wxPaintEvent paintEvent;
|
|
|
|
|
|
|
|
anim= anim+speed;
|
|
|
|
if(anim>1.0f){
|
|
|
|
anim-= 1.f;
|
|
|
|
}
|
|
|
|
onPaint(paintEvent);
|
|
|
|
}
|
|
|
|
|
|
|
|
string MainWindow::getModelInfo(){
|
|
|
|
string str;
|
|
|
|
|
|
|
|
if(model!=NULL){
|
|
|
|
str+= "Meshes: "+intToStr(model->getMeshCount());
|
|
|
|
str+= ", Vertices: "+intToStr(model->getVertexCount());
|
|
|
|
str+= ", Triangles: "+intToStr(model->getTriangleCount());
|
|
|
|
str+= ", Version: "+intToStr(model->getFileVersion());
|
|
|
|
}
|
|
|
|
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
2010-05-25 18:06:42 +00:00
|
|
|
void MainWindow::onKeyDown(wxKeyEvent &e) {
|
|
|
|
/*
|
|
|
|
if (currentBrush == btHeight || currentBrush == btGradient) { // 'height' brush
|
|
|
|
if (e.GetKeyCode() >= '0' && e.GetKeyCode() <= '5') {
|
|
|
|
height = e.GetKeyCode() - 48; // '0'-'5' == 0-5
|
|
|
|
if (e.GetModifiers() == wxMOD_CONTROL) { // Ctrl means negative
|
|
|
|
height = -height ;
|
|
|
|
}
|
|
|
|
int id_offset = heightCount / 2 + height + 1;
|
|
|
|
if (currentBrush == btHeight) {
|
|
|
|
wxCommandEvent evt(wxEVT_NULL, miBrushHeight + id_offset);
|
|
|
|
onMenuBrushHeight(evt);
|
|
|
|
} else {
|
|
|
|
wxCommandEvent evt(wxEVT_NULL, miBrushGradient + id_offset);
|
|
|
|
onMenuBrushGradient(evt);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (currentBrush == btSurface) { // surface texture
|
|
|
|
if (e.GetKeyCode() >= '1' && e.GetKeyCode() <= '5') {
|
|
|
|
surface = e.GetKeyCode() - 48; // '1'-'5' == 1-5
|
|
|
|
wxCommandEvent evt(wxEVT_NULL, miBrushSurface + surface);
|
|
|
|
onMenuBrushSurface(evt);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (currentBrush == btObject) {
|
|
|
|
bool valid = true;
|
|
|
|
if (e.GetKeyCode() >= '1' && e.GetKeyCode() <= '9') {
|
|
|
|
object = e.GetKeyCode() - 48; // '1'-'9' == 1-9
|
|
|
|
} else if (e.GetKeyCode() == '0') { // '0' == 10
|
|
|
|
object = 10;
|
|
|
|
} else if (e.GetKeyCode() == '-') { // '-' == 0
|
|
|
|
object = 0;
|
|
|
|
} else {
|
|
|
|
valid = false;
|
|
|
|
}
|
|
|
|
if (valid) {
|
|
|
|
wxCommandEvent evt(wxEVT_NULL, miBrushObject + object + 1);
|
|
|
|
onMenuBrushObject(evt);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (currentBrush == btResource) {
|
|
|
|
if (e.GetKeyCode() >= '0' && e.GetKeyCode() <= '5') {
|
|
|
|
resource = e.GetKeyCode() - 48; // '0'-'5' == 0-5
|
|
|
|
wxCommandEvent evt(wxEVT_NULL, miBrushResource + resource + 1);
|
|
|
|
onMenuBrushResource(evt);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (currentBrush == btStartLocation) {
|
|
|
|
if (e.GetKeyCode() >= '1' && e.GetKeyCode() <= '8') {
|
|
|
|
startLocation = e.GetKeyCode() - 48; // '1'-'8' == 0-7
|
|
|
|
wxCommandEvent evt(wxEVT_NULL, miBrushStartLocation + startLocation);
|
|
|
|
onMenuBrushStartLocation(evt);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (e.GetKeyCode() == 'H') {
|
|
|
|
wxCommandEvent evt(wxEVT_NULL, miBrushHeight + height + heightCount / 2 + 1);
|
|
|
|
onMenuBrushHeight(evt);
|
|
|
|
} else if (e.GetKeyCode() == ' ') {
|
|
|
|
if (resourceUnderMouse != 0) {
|
|
|
|
wxCommandEvent evt(wxEVT_NULL, miBrushResource + resourceUnderMouse + 1);
|
|
|
|
onMenuBrushResource(evt);
|
|
|
|
} else {
|
|
|
|
wxCommandEvent evt(wxEVT_NULL, miBrushObject + objectUnderMouse + 1);
|
|
|
|
onMenuBrushObject(evt);
|
|
|
|
}
|
|
|
|
} else if (e.GetKeyCode() == 'G') {
|
|
|
|
wxCommandEvent evt(wxEVT_NULL, miBrushGradient + height + heightCount / 2 + 1);
|
|
|
|
onMenuBrushGradient(evt);
|
|
|
|
} else if (e.GetKeyCode() == 'S') {
|
|
|
|
wxCommandEvent evt(wxEVT_NULL, miBrushSurface + surface);
|
|
|
|
onMenuBrushSurface(evt);
|
|
|
|
} else if (e.GetKeyCode() == 'O') {
|
|
|
|
wxCommandEvent evt(wxEVT_NULL, miBrushObject + object + 1);
|
|
|
|
onMenuBrushObject(evt);
|
|
|
|
} else if (e.GetKeyCode() == 'R') {
|
|
|
|
wxCommandEvent evt(wxEVT_NULL, miBrushResource + resource + 1);
|
|
|
|
onMenuBrushResource(evt);
|
|
|
|
} else if (e.GetKeyCode() == 'L') {
|
|
|
|
wxCommandEvent evt(wxEVT_NULL, miBrushStartLocation + startLocation + 1);
|
|
|
|
onMenuBrushStartLocation(evt);
|
|
|
|
} else {
|
|
|
|
e.Skip();
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (e.GetKeyCode() == 'R') {
|
|
|
|
renderer->end();
|
|
|
|
|
|
|
|
for(int idx = 0; idx < unitParticleSystems.size(); ++idx) {
|
|
|
|
//UnitParticleSystem *ups = unitParticleSystems[idx];
|
|
|
|
//delete ups;
|
|
|
|
//ups = NULL;
|
|
|
|
}
|
|
|
|
unitParticleSystems.clear();
|
|
|
|
|
|
|
|
for(int idx = 0; idx < unitParticleSystemTypes.size(); ++idx) {
|
|
|
|
//UnitParticleSystemType *unitParticleSystemType = unitParticleSystemTypes[idx];
|
|
|
|
//delete unitParticleSystemType;
|
|
|
|
//unitParticleSystemType = NULL;
|
|
|
|
}
|
|
|
|
unitParticleSystemTypes.clear();
|
|
|
|
|
|
|
|
loadModel("");
|
|
|
|
loadParticle("");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-13 10:39:22 +00:00
|
|
|
BEGIN_EVENT_TABLE(MainWindow, wxFrame)
|
|
|
|
EVT_TIMER(-1, MainWindow::onTimer)
|
|
|
|
EVT_CLOSE(MainWindow::onClose)
|
|
|
|
EVT_MENU(miFileLoad, MainWindow::onMenuFileLoad)
|
2010-05-25 18:06:42 +00:00
|
|
|
EVT_MENU(miFileLoadParticleXML, MainWindow::onMenuFileLoadParticleXML)
|
2010-06-24 10:52:58 +00:00
|
|
|
EVT_MENU(miFileLoadProjectileParticleXML, MainWindow::onMenuFileLoadProjectileParticleXML)
|
2010-03-13 10:39:22 +00:00
|
|
|
|
|
|
|
EVT_MENU(miModeWireframe, MainWindow::onMenuModeWireframe)
|
|
|
|
EVT_MENU(miModeNormals, MainWindow::onMenuModeNormals)
|
|
|
|
EVT_MENU(miModeGrid, MainWindow::onMenuModeGrid)
|
|
|
|
|
|
|
|
EVT_MENU(miSpeedFaster, MainWindow::onMenuSpeedFaster)
|
|
|
|
EVT_MENU(miSpeedSlower, MainWindow::onMenuSpeedSlower)
|
|
|
|
|
|
|
|
EVT_MENU(miColorRed, MainWindow::onMenuColorRed)
|
|
|
|
EVT_MENU(miColorBlue, MainWindow::onMenuColorBlue)
|
|
|
|
EVT_MENU(miColorYellow, MainWindow::onMenuColorYellow)
|
|
|
|
EVT_MENU(miColorGreen, MainWindow::onMenuColorGreen)
|
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
|
|
|
// =====================================================
|
|
|
|
// class GlCanvas
|
|
|
|
// =====================================================
|
|
|
|
|
2010-05-25 18:06:42 +00:00
|
|
|
void translateCoords(wxWindow *wnd, int &x, int &y) {
|
|
|
|
#ifdef WIN32
|
|
|
|
int cx, cy;
|
|
|
|
wnd->GetPosition(&cx, &cy);
|
|
|
|
x += cx;
|
|
|
|
y += cy;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2010-03-13 10:39:22 +00:00
|
|
|
GlCanvas::GlCanvas(MainWindow * mainWindow):
|
|
|
|
wxGLCanvas(mainWindow, -1, wxDefaultPosition)
|
|
|
|
{
|
|
|
|
this->mainWindow = mainWindow;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GlCanvas::onMouseMove(wxMouseEvent &event){
|
|
|
|
mainWindow->onMouseMove(event);
|
|
|
|
}
|
|
|
|
|
2010-05-25 18:06:42 +00:00
|
|
|
void GlCanvas::onKeyDown(wxKeyEvent &event) {
|
|
|
|
int x, y;
|
|
|
|
event.GetPosition(&x, &y);
|
|
|
|
translateCoords(this, x, y);
|
|
|
|
mainWindow->onKeyDown(event);
|
|
|
|
}
|
|
|
|
|
2010-03-13 10:39:22 +00:00
|
|
|
BEGIN_EVENT_TABLE(GlCanvas, wxGLCanvas)
|
|
|
|
EVT_MOTION(GlCanvas::onMouseMove)
|
2010-05-25 18:06:42 +00:00
|
|
|
EVT_KEY_DOWN(GlCanvas::onKeyDown)
|
2010-03-13 10:39:22 +00:00
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
|
|
|
// ===============================================
|
|
|
|
// class App
|
|
|
|
// ===============================================
|
|
|
|
|
|
|
|
bool App::OnInit(){
|
|
|
|
std::string modelPath;
|
|
|
|
if(argc==2){
|
|
|
|
modelPath= wxFNCONV(argv[1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
mainWindow= new MainWindow(modelPath);
|
|
|
|
mainWindow->Show();
|
|
|
|
mainWindow->init();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
int App::MainLoop(){
|
|
|
|
try{
|
|
|
|
return wxApp::MainLoop();
|
|
|
|
}
|
|
|
|
catch(const exception &e){
|
|
|
|
wxMessageDialog(NULL, ToUnicode(e.what()), ToUnicode("Exception"), wxOK | wxICON_ERROR).ShowModal();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int App::OnExit(){
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
}}//end namespace
|
|
|
|
|
|
|
|
IMPLEMENT_APP(Shared::G3dViewer::App)
|