Posted: Fri Feb 04, 2005 3:06 am
how was the grass done? i found a grass shader that has wind sway and all that good stuff, would a shader work better than actual mesh with an animation?
Code: Select all
#include "LevelMap.h"
#include <OgreConfigFile.h>
#include "OgreLogManager.h"
LevelMap::LevelMap(String configFile, String mapName) {
ConfigFile config;
config.load(configFile);
String mapFilename = config.getSetting(mapName) ;
mScale.x = StringUtil::toReal(config.getSetting("Scale.x"));
mScale.y = StringUtil::toReal(config.getSetting("Scale.y"));
mScale.z = StringUtil::toReal(config.getSetting("Scale.z"));
ilGenImages(1, &id);
ilBindImage(id);
//const char*String s = (const char*) mapFilename ;
char*s;
strcpy(s, mapFilename.c_str());
LogManager::getSingleton().logMessage(s) ;
ilLoadImage((ILstring) s); // Loads into the current bound image
mWidth = ilGetInteger(IL_IMAGE_WIDTH) ;
mHeight = ilGetInteger(IL_IMAGE_HEIGHT) ;
}
Real LevelMap::getWidth() {
return mWidth ;
}
Real LevelMap::getHeight() {
return mHeight ;
}
Vector3 LevelMap::getScale() {
return mScale ;
}
void LevelMap::getRGBAt(Real x, Real z, int rgb[3]) {
int int_x,int_z ;
int_x = (int) floor(x/mScale.x) ;
int_z = (int) floor(z/mScale.z) ;
if (int_x> mWidth-1 || int_z>mHeight-1 || x<0 || z<0) {
rgb[0] = 0;
rgb[1] = 0;
rgb[2] = 0;
return ;
}
ilBindImage(id);
ILubyte data[3] ;
ilCopyPixels(int_x, int_z, 0, 1, 1, 1, IL_RGB, IL_UNSIGNED_BYTE, data);
rgb[0] = data[0];
rgb[1] = data[1];
rgb[2] = data[2];
}
Code: Select all
#ifndef LEVELMAP_H
#define LEVELMAP_H
class LevelMap ;
#include <Ogre.h>
#include <il/il.h>
#include <il/ilu.h>
using namespace Ogre;
class LevelMap {
public:
LevelMap(String configFile, String mapName) ;
void getRGBAt(Real x, Real z, int rgb[3]) ;
Real getWidth() ;
Real getHeight() ;
Vector3 getScale() ;
protected:
Vector3 mScale ;
Real mWidth ;
Real mHeight ;
ILuint id ;
} ;
#endif
Code: Select all
/*Some littles things:
-I apologize for my poor english comments and for french variables names:)
-This is not a definitive program, and I wrote it initially to be used by me alone, so
this is not very ergonomic. I tried to improve the ergonomy for this release, but It's very far to be perferct.
-Everywhere in this code, I use the Camera to call the SceneManager. I use it to load objects in the Frame listener, and it's the easiest way to do(I think).
-The PlatypAce will be a full level-loading program, wich determines what level he has to load(and to unload) with defined conditions. This is not operational for the moment
(It has already been so, but I've lost the sources some months ago).
-The LevelMap program Is for EarthQuakeProof. Thx to him :)
-Be aware that if there is a coloured pixel on the image wich color is not corresponding to a defined Entity Type, you'll get an error. I've not "securised" it.
*/
#include "LevelMap.h"
#include "OgrePagingLandScapeRaySceneQuery.h"
#include "platypace.h"
//constructors and destructors are blanks for the moment :(
PlatypAce::PlatypAce()
{
}
PlatypAce::~PlatypAce()
{
}
void PlatypAce::entTypes(Camera*mCamera)//defines the array of entity types we will load
{
//some examples of entities
type[001]= mCamera->getSceneManager()->createEntity("type001", "rocher.mesh");
type[100]= mCamera->getSceneManager()->createEntity("type100", "fish.mesh");
type[101]= mCamera->getSceneManager()->createEntity("type101", "herbe.mesh");
}
//Loads the Level Meshes.
//Todo: rework it as soon as I've the 1.0.0 compiled :) to us geometry batcher.
void PlatypAce::ChargerNiveau(LevelMap*Platypus,
SceneNode* Objnode,
Camera*mCamera,
char nom[]
)
/*Description of parameters :
-Platypus is referring to the LevelMap we are working on.
I've made it a parameter in order to load several different levels wich entities' base names are different.
-Objnode is the "Big" node wich is the father of all the "little" node, for all Level. So it is easy to
clear the level: just to do "Objnode->removeAndDestroyAllChildren();"
-mCamera is the used Camera(yes! :D).
-nom is the char array wich contains the base name of all entities loaded in this program.
*/
{
entTypes(mCamera); //defines the entities.
RaySceneQuery* mRayQuery; //I use A raySceneQuerry to calculate the terrain Height
mRayQuery = mCamera->getSceneManager()->createRayQuery(Ray(Vector3(0.0f, 0.0f, 0.0f), Vector3::UNIT_Y));
SceneNode*objnode; //the "little" node
int couleur[3];
Vector3 objPos; //the position of the object.
char cloneEntName[21]; //the definitive entity name.
for (int x = 0; x < Platypus->getWidth(); ++x)// Scann the image for all X pixels
{
for (int z = 0; z < Platypus->getHeight(); ++z) // Scann the image for all Z pixels(notice that I used "z" to be
{ //in the same coordinates name that the engine, and no the picture one's.
Platypus->getRGBAt(x,z,couleur);//Analyses the color of the scanned pixel; The color is stocked in "couleur" Vector3
if (couleur[0]!=0) //if the pixel is not black
{
objnode = mCamera->getSceneManager()->createSceneNode();
objPos.x = x*67-66666;//this are my own settings, calculated for my own needs, so do what you want :) ;
objPos.z = z*67-66666;
////Part Calculating the height of the terrain
mRayQuery->setRay (Ray(objPos, Vector3::UNIT_Y));
mRayQuery->setQueryMask (RSQ_Height);
RaySceneQueryResult& qryResult = mRayQuery->execute();
RaySceneQueryResult::iterator it = qryResult.begin();
if (it != qryResult.end() && it->worldFragment)
{
objPos.y = it->worldFragment->singleIntersection.y;
}
////End of Part Calculating the height of the terrain
//We position the object at world coordinates wich are corresponding to pixel position
//objnode->setPosition( objPos.x,objPos.y+2.5,objPos.z);
objnode->setPosition(objPos);
Objnode->addChild(objnode); //we attach the "little" node to the "big" one
sprintf(cloneEntName, nom,x,z);// generate the name of the cloned Entity.The name is XentNameZ formatted to have different name in all cases.
cloneEnt = type[couleur[0]]->clone(cloneEntName); //we clone the entity wich type is the same as the red color value.
//this is the more important part of the program.
// Attach to new node
objnode->attachObject(cloneEnt); //we attach the entity
}
}
}
}
Code: Select all
class PlatypAce {
public:
PlatypAce();
~PlatypAce();
void PlatypusEnt(Entity*type[],Camera*mCamera);
void ChargerNiveau(LevelMap*Platypus,
SceneNode* Objnode,
Camera*mCamera,
char nom[]
);
protected:
char NewLevel;
Entity*type[256];
void entTypes(Camera*);
Entity*cloneEnt;
};
Code: Select all
platypus=platypus.png
Scale.x=1
Scale.y=1
Scale.z=1