- added support for showing projectile particles in the g3d viewer

This commit is contained in:
Mark Vejvoda
2010-06-24 10:52:58 +00:00
parent 0340d57a8d
commit a81286cbba
23 changed files with 853 additions and 54 deletions

View File

@@ -2,7 +2,6 @@
#include <stdexcept>
//#include "graphics_factory_gl.h"
#include "model_gl.h"
#include "graphics_interface.h"
#include "util.h"
@@ -68,6 +67,7 @@ MainWindow::MainWindow(const string &modelPath)
menuFile= new wxMenu();
menuFile->Append(miFileLoad, wxT("Load"));
menuFile->Append(miFileLoadParticleXML, wxT("Load Particle XML"));
menuFile->Append(miFileLoadProjectileParticleXML, wxT("Load Projectile Particle XML"));
menu->Append(menuFile, wxT("File"));
//mode
@@ -192,6 +192,16 @@ void MainWindow::onMenuFileLoadParticleXML(wxCommandEvent &event){
}
}
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);
}
}
void MainWindow::loadModel(string path) {
if(path != "" && fileExists(path) == true) {
this->modelPathList.push_back(path);
@@ -215,6 +225,8 @@ void MainWindow::loadParticle(string path) {
}
if(this->particlePathList.size() > 0) {
renderer->initModelManager();
for(int idx = 0; idx < this->particlePathList.size(); idx++) {
string particlePath = this->particlePathList[idx];
string dir= extractDirectoryPathFromFile(particlePath);
@@ -245,7 +257,7 @@ void MainWindow::loadParticle(string path) {
std::cout << "About to load [" << particlePath << "] from [" << dir << "] unit [" << unitXML << "]" << std::endl;
UnitParticleSystemType *unitParticleSystemType= new UnitParticleSystemType();
unitParticleSystemType->load(dir, dir + "/" + particlePath, renderer->getNewTexture2D());
unitParticleSystemType->load(dir, dir + "/" + particlePath, renderer);
unitParticleSystemTypes.push_back(unitParticleSystemType);
for(std::vector<UnitParticleSystemType *>::const_iterator it= unitParticleSystemTypes.begin(); it != unitParticleSystemTypes.end(); ++it) {
@@ -269,6 +281,87 @@ void MainWindow::loadParticle(string path) {
}
}
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);
size_t pos = dir.find_last_of("/");
if(pos == dir.length()-1) {
dir.erase(dir.length() -1);
}
particlePath= extractFileFromDirectoryPath(particlePath);
std::string unitXML = dir + "/" + extractFileFromDirectoryPath(dir) + ".xml";
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;
xmlTree.load(dir + "/" + particlePath);
const XmlNode *particleSystemNode= xmlTree.getRootNode();
std::cout << "Loaded successfully, loading values..." << std::endl;
ParticleSystemTypeProjectile *projectileParticleSystemType= new ParticleSystemTypeProjectile();
projectileParticleSystemType->load(dir, dir + "/" + particlePath,renderer);
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);
//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();
}
}
}
void MainWindow::onMenuModeNormals(wxCommandEvent &event){
renderer->toggleNormals();
menuMode->Check(miModeNormals, renderer->getNormals());
@@ -465,6 +558,7 @@ BEGIN_EVENT_TABLE(MainWindow, wxFrame)
EVT_CLOSE(MainWindow::onClose)
EVT_MENU(miFileLoad, MainWindow::onMenuFileLoad)
EVT_MENU(miFileLoadParticleXML, MainWindow::onMenuFileLoadParticleXML)
EVT_MENU(miFileLoadProjectileParticleXML, MainWindow::onMenuFileLoadProjectileParticleXML)
EVT_MENU(miModeWireframe, MainWindow::onMenuModeWireframe)
EVT_MENU(miModeNormals, MainWindow::onMenuModeNormals)

View File

@@ -33,6 +33,7 @@ public:
enum MenuId{
miFileLoad,
miFileLoadParticleXML,
miFileLoadProjectileParticleXML,
miModeWireframe,
miModeNormals,
miModeGrid,
@@ -62,6 +63,7 @@ private:
//string ParticlePath;
std::vector<string> modelPathList;
std::vector<string> particlePathList;
std::vector<string> particleProjectilePathList;
float speed;
float anim;
@@ -72,8 +74,12 @@ private:
std::vector<UnitParticleSystemType *> unitParticleSystemTypes;
std::vector<UnitParticleSystem *> unitParticleSystems;
std::vector<ParticleSystemTypeProjectile *> projectileParticleSystemTypes;
std::vector<ProjectileParticleSystem *> projectileParticleSystems;
void loadModel(string path);
void loadParticle(string path);
void loadProjectileParticle(string path);
public:
MainWindow(const string &modelPath);
@@ -86,6 +92,7 @@ public:
void onClose(wxCloseEvent &event);
void onMenuFileLoad(wxCommandEvent &event);
void onMenuFileLoadParticleXML(wxCommandEvent &event);
void onMenuFileLoadProjectileParticleXML(wxCommandEvent &event);
void onMenuModeNormals(wxCommandEvent &event);
void onMenuModeWireframe(wxCommandEvent &event);
void onMenuModeGrid(wxCommandEvent &event);

View File

@@ -78,7 +78,7 @@ Renderer::Renderer(){
modelRenderer = NULL;
textureManager = NULL;
particleRenderer = NULL;
particleManager = NULL;
modelManager = NULL;
}
Renderer::~Renderer(){
@@ -88,6 +88,7 @@ Renderer::~Renderer(){
//resources
delete particleManager;
delete modelManager;
}
Renderer * Renderer::getInstance(){
@@ -141,6 +142,11 @@ Texture2D * Renderer::getNewTexture2D() {
return newTexture;
}
Model * Renderer::getNewModel() {
Model *newModel = modelManager->newModel();
return newModel;
}
void Renderer::init(){
assertGl();
@@ -157,6 +163,9 @@ void Renderer::init(){
//resources
particleManager= gf->newParticleManager();
modelManager = gf->newModelManager();
modelManager->setTextureManager(textureManager);
//red tex
customTextureRed= textureManager->newTexture2D();
customTextureRed->getPixmap()->init(1, 1, 3);
@@ -293,6 +302,7 @@ void Renderer::loadTheModel(Model *model, string file){
model->setTextureManager(textureManager);
model->loadG3d(file);
textureManager->init();
modelManager->init();
}
void Renderer::renderTheModel(Model *model, float f){
@@ -355,10 +365,15 @@ void Renderer::initTextureManager() {
textureManager->init();
}
void Renderer::initModelManager() {
modelManager->init();
}
void Renderer::end() {
//delete resources
//textureManager->end();
particleManager->end();
modelManager->end();
}
}}//end namespace

View File

@@ -14,12 +14,15 @@
#include "texture.h"
#include "particle_renderer.h"
#include "model_manager.h"
#include "graphics_interface.h"
//#include "model_manager.h"
//#include "graphics_factory_gl.h"
using Shared::Graphics::ModelRenderer;
using Shared::Graphics::TextureManager;
using Shared::Graphics::ModelManager;
using Shared::Graphics::Model;
using Shared::Graphics::Texture2D;
using Shared::Graphics::ParticleRenderer;
@@ -31,6 +34,8 @@ using Shared::Graphics::MeshCallback;
using Shared::Graphics::Mesh;
using Shared::Graphics::Texture;
using namespace Shared::Graphics;
namespace Shared{ namespace G3dViewer{
// ===============================================
@@ -50,7 +55,7 @@ public:
// class Renderer
// ===============================
class Renderer{
class Renderer : public RendererInterface {
public:
static const int windowX= 100;
static const int windowY= 100;
@@ -75,6 +80,7 @@ private:
ParticleRenderer *particleRenderer;
ParticleManager *particleManager;
ModelManager *modelManager;
Texture2D *customTextureRed;
Texture2D *customTextureBlue;
@@ -110,8 +116,16 @@ public:
void updateParticleManager();
void renderParticleManager();
Texture2D *getPlayerColorTexture(PlayerColor playerColor);
Texture2D * getNewTexture2D();
Model * getNewModel();
Model *newModel(ResourceScope rs) { return getNewModel(); }
Texture2D *newTexture2D(ResourceScope rs) { return getNewTexture2D(); }
void initTextureManager();
void initModelManager();
void end();
};