本文整理汇总了C++中LSystem类的典型用法代码示例。如果您正苦于以下问题:C++ LSystem类的具体用法?C++ LSystem怎么用?C++ LSystem使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了LSystem类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: LSystem
std::vector<Frame* > frameFactory::getLsystemFrame(const std::string& name)
{
std::map<string, std::vector<Frame *> >::const_iterator pos = lsysFrames.find(name);
if ( pos == lsysFrames.end() ) {
LSystem* lsystem = new LSystem(gdata->getXmlStr(name+"SpriteFile"));
lsystems[name] = lsystem;
SDL_Surface * const surface = lsystem->getSurface();
bool transparency = gdata->getXmlBool(name+"SpriteTransparency");
if ( transparency ) {
// We need to make the L-System surface transparent for Magenta:
Uint32 colorkey = SDL_MapRGB(surface->format, 255, 0, 255);
// Note that we're violating const with a C function:
SDL_SetColorKey(surface, SDL_SRCCOLORKEY|SDL_RLEACCEL, colorkey);
}
surfaceMap[name] = surface;
std::vector<Frame *> frame;
frame.push_back(new Frame(surface,
gdata->getXmlInt(name+"SpriteWidth"),
gdata->getXmlInt(name+"SpriteHeight"),
gdata->getXmlInt(name+"SpritesrcX"),
gdata->getXmlInt(name+"SpritesrcY")));
lsysFrames[name] = frame;
return frame;
}
else {
return pos->second;
}
}
示例2: buildLSystem
void CloudsVisualSystemLSystem::buildLSystem(){
// Clear
//
lsysLines.clear();
lsysLines.push_back(ofPolyline());
lsysNodes.clear();
lsysOriginal.clear();
LSystem sys;
sys.initialPos.set(0,0);
sys.unoise = 0.0;
sys.utime = 0.0;
sys.ds = lsysScale;
sys.setAngle( lsysAngle );
sys.addAxion( lsysAxiom );
sys.addRule( lsysRule1 );
if (lsysRule2.size() > 0){
sys.addRule( lsysRule2);
}
sys.make( lsysDepth );
lsysOriginal = sys.mesh;
if ( lsysOriginal.getVertices().size() > 2){
lineTo( lsysOriginal.getVertices()[0] );
addNode( lsysOriginal.getVertices()[0] );
for (int i = 1; i < lsysOriginal.getVertices().size();i++){
if ( i%2 == 1){
lineTo( lsysOriginal.getVertices()[i]);
} else {
if ( lsysOriginal.getVertices()[i] != lsysOriginal.getVertices()[i-1]){
lsysLines.push_back(ofPolyline());
lineTo( lsysOriginal.getVertices()[i] );
addNode( lsysOriginal.getVertices()[i] );
}
}
}
}
if ( lsysNodes.size() > 0){
lsysNodes[0].startTime = 0;
}
}
示例3: createMesh
MObject LSystemNode::createMesh(const double & angle, const double & step, const MString & grammar,
const MTime& time, MObject& outData, MStatus& stat)
{
//int numVertices, frame;
//float cubeSize;
//MFloatPointArray points;
MPointArray points;
MIntArray faceCounts;
MIntArray faceConnects;
MFnMesh meshFS;
LSystem lsys;
lsys.setDefaultAngle(angle); //angle
lsys.setDefaultStep(step); //step size
string gram = grammar.asChar(); //grammar
lsys.loadProgramFromString(gram);
std::vector<LSystem::Branch> branches;
lsys.process((int)time.value(),branches);
CylinderMesh*cm;
for(int j = 0;j<branches.size();j++)
{
vec3 Bstart = branches[j].first;
vec3 Bend = branches[j].second;
MPoint b_start(Bstart[0],Bstart[1],Bstart[2]);
MPoint b_end(Bend[0],Bend[1],Bend[2]);
cm = new CylinderMesh(b_start,b_end);
cm->appendToMesh(points,faceCounts,faceConnects);
}
/*
// Scale the cube on the frame number, wrap every 10 frames.
frame = (int)time.as( MTime::kFilm );
if (frame == 0)
frame = 1;
cubeSize = 0.5f * (float)( frame % 10);
const int numFaces = 6;
numVertices = 8;
const int numFaceConnects = 24;*/
/*
MFloatPoint vtx_1( -cubeSize, -cubeSize, -cubeSize );
MFloatPoint vtx_2( cubeSize, -cubeSize, -cubeSize );
MFloatPoint vtx_3( cubeSize, -cubeSize, cubeSize );
MFloatPoint vtx_4( -cubeSize, -cubeSize, cubeSize );
MFloatPoint vtx_5( -cubeSize, cubeSize, -cubeSize );
MFloatPoint vtx_6( -cubeSize, cubeSize, cubeSize );
MFloatPoint vtx_7( cubeSize, cubeSize, cubeSize );
MFloatPoint vtx_8( cubeSize, cubeSize, -cubeSize );
points.append( vtx_1 );
points.append( vtx_2 );
points.append( vtx_3 );
points.append( vtx_4 );
points.append( vtx_5 );
points.append( vtx_6 );
points.append( vtx_7 );
points.append( vtx_8 );
// Set up an array containing the number of vertices
// for each of the 6 cube faces (4 verticies per face)
//
int face_counts[numFaces] = { 4, 4, 4, 4, 4, 4 };
MIntArray faceCounts( face_counts, numFaces );
// Set up and array to assign vertices from points to each face
//
int face_connects[ numFaceConnects ] =
{ 0, 1, 2, 3,
4, 5, 6, 7,
3, 2, 6, 5,
0, 3, 5, 4,
0, 4, 7, 1,
1, 7, 6, 2
};
MIntArray faceConnects( face_connects, numFaceConnects );
MObject newMesh = meshFS.create(numVertices, numFaces, points, faceCounts, faceConnects, outData, &stat);
return newMesh;*/
MObject newMesh = meshFS.create(points.length()
,faceCounts.length(),points,faceCounts
,faceConnects,outData,&stat);
return newMesh;
}
示例4: McheckErr
MStatus LSystemNode::compute(const MPlug& plug, MDataBlock& data)
{
MStatus returnStatus;
if (plug == outputMesh) {
/* Get time */
MDataHandle timeData = data.inputValue( time, &returnStatus );
McheckErr(returnStatus, "Error getting time data handle\n");
MTime time = timeData.asTime();
MDataHandle angleData = data.inputValue( angle, &returnStatus );
McheckErr(returnStatus, "Error getting time data handle\n");
double angle_value = angleData.asDouble();
MDataHandle stepsData = data.inputValue( steps, &returnStatus );
McheckErr(returnStatus, "Error getting time data handle\n");
double steps_value = stepsData.asDouble();
MDataHandle grammarData = data.inputValue( grammar, &returnStatus );
McheckErr(returnStatus, "Error getting time data handle\n");
MString grammar_value = grammarData.asString();
/* Get output object */
MDataHandle outputHandle = data.outputValue(outputMesh, &returnStatus);
McheckErr(returnStatus, "ERROR getting polygon data handle\n");
MFnMeshData dataCreator;
MObject newOutputData = dataCreator.create(&returnStatus);
McheckErr(returnStatus, "ERROR creating outputData");
MFnMesh myMesh;
MPointArray points;
MIntArray faceCounts;
MIntArray faceConnects;
//MString grammar = ("F\\nF->F[+F]F[-F]F");
CylinderMesh *cm;
LSystem system;
system.loadProgramFromString(grammar_value.asChar());
system.setDefaultAngle(angle_value);
system.setDefaultStep(steps_value);
std::vector<LSystem::Branch> branches;
system.process(time.value(), branches);
int k = branches.size();
for(int j = 0; j < branches.size(); j++)
{
//1. find the position for start and end point of current branch
//2. generate a cylinder
MPoint start(branches[j].first[0],branches[j].first[1],branches[j].first[2]);
MPoint end(branches[j].second[0],branches[j].second[1],branches[j].second[2]);
cm = new CylinderMesh(start, end);
cm->appendToMesh(points, faceCounts, faceConnects);
}
MObject newMesh = myMesh.create(points.length(), faceCounts.length(),
points, faceCounts, faceConnects,
newOutputData, &returnStatus);
McheckErr(returnStatus, "ERROR creating new mesh");
outputHandle.set(newOutputData);
data.setClean( plug );
} else
return MS::kUnknownParameter;
return MS::kSuccess;
}
示例5: Material
void MainApplication::initScene()
{
m_components.clear();
Material * grassMaterial = new Material(Shader::find("shader"));
grassMaterial->setTexture(new Texture("resources/ground.bmp"));
grassMaterial->setDiffuseColor(glm::vec4(1.0f, 1.0f, 1.0f, 1.0f));
grassMaterial->setAmbientColor(glm::vec4(0.5f, 0.5f, 0.5f, 1.0f));
Mesh * terrain = MeshFactory::Terrain();
MeshObject * grass = new MeshObject(terrain, grassMaterial);
grass->transform().scale(glm::vec3(10.0f));
grass->transform().translate(glm::vec3(-5.0f, 0.0f, -5.0f));
m_components.push_back(grass);
{ // palm tree
PlantDefinition * def = new PlantDefinition();
def->iterations = 2;
def->angle = 22.5f;
def->diameter = 0.10f;
def->length = 0.20f;
def->thinning = 1.9f;
def->axiom = "F";
def->addTerminals("+-!?&/[]Q");
def->addProduction('F', "F[-F]F[+F]F[&F]F[/F]F[QQQQQ]F");
def->barkTexture = "resources/bark_palm.bmp";
def->leafTexture = "resources/palm_leaf.bmp";
def->size = 0.5f;
LSystem * system = new LSystem(def);
glm::vec3 position = terrain->vertexAt(random.randXX(0, terrain->vertices().size()-1)).position;
position = glm::vec3(grass->transform().world() * glm::vec4(position, 1.0f));
system->transform().translate(position);
m_components.push_back(system);
}
{ // tropical tree
PlantDefinition * def = new PlantDefinition();
def->addTerminals("+-!?&/[]<Q`");
def->iterations = 7;
def->angle = 22.5f;
def->diameter = 0.15f;
def->length = 0.15f;
def->thinning = 1.5f;
def->axiom = "A";
def->addProduction('A', "[+FLA]?????[+FLA]???????`[+FLA]");
def->addProduction('F', "S?????F");
def->addProduction('S', "F");
def->addProduction('L', "[Q--Q][Q&&Q]");
def->barkTexture = "resources/bark.bmp";
def->leafTexture = "resources/leaf.bmp";
LSystem * system = new LSystem(def);
glm::vec3 position = terrain->vertexAt(random.randXX(0, terrain->vertices().size()-1)).position;
position = glm::vec3(grass->transform().world() * glm::vec4(position, 1.0f));
system->transform().translate(position);
m_components.push_back(system);
}
{ // small tree
PlantDefinition * def = new PlantDefinition();
def->addTerminals("+-!?&/[]<FQ");
def->iterations = 13;
def->angle = 15.0f;
def->diameter = 0.02f;
def->length = 0.15f;
def->thinning = 1.3f;
def->axiom = "FA";
def->addProduction('A', "/FB???B?????BQ");
def->addProduction('B', "[//F??????A]");
def->barkTexture = "resources/bark2.bmp";
def->leafTexture = "resources/papaya_leaf.bmp";
LSystem * system = new LSystem(def, 2000.0f);
glm::vec3 position = terrain->vertexAt(random.randXX(0, terrain->vertices().size()-1)).position;
position = glm::vec3(grass->transform().world() * glm::vec4(position, 1.0f));
system->transform().translate(position);
m_components.push_back(system);
}
{ // "maple" tree
PlantDefinition * def = new PlantDefinition();
def->addTerminals("+-!?&/[]<FQ");
def->iterations = 6;
def->angle = 19.0f;
def->diameter = 0.075f;
def->length = 0.20f;
def->thinning = 2.0f;
def->axiom = "F&A";
def->addProduction('A', "F[-F/AQ]?[+FAQ]&[!FAQ]");
def->barkTexture = "resources/bark_maple.bmp";
def->leafTexture = "resources/maple_leaf.bmp";
LSystem * system = new LSystem(def, 6000.0f);
//.........这里部分代码省略.........
示例6: init
//Initializes stuff
void init()
{
#if 1
GLfloat mat_ambient[] = {0.8,0.15,0.05,1.0};
GLfloat mat_specular[] = {0.8,0.15,0.04,1.0};
GLfloat mat_shininess[] = {10.0};
GLfloat light_position[] = {10.0,10.0,1.0,1.0 };
GLfloat model_ambient[] = {0.8,0.15,0.04,1.0 };
GLfloat mat_diffuse[] = {0.8,0.15,0.05,1.0 };
#endif
glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
glClearColor(0, 0, 0, 0);
#if 1
glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);
glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, model_ambient);
#endif
glEnable(GL_LIGHT0);
glEnable(GL_LIGHTING);
glEnable(GL_COLOR_MATERIAL);
glEnable(GL_AUTO_NORMAL);
glEnable(GL_NORMALIZE);
//glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
//glEnable(GL_BLEND);
g_log_set_handler ("parse", (GLogLevelFlags)(G_LOG_LEVEL_INFO | G_LOG_LEVEL_DEBUG | G_LOG_LEVEL_MESSAGE),
parse_log_handler, NULL);
g_log_set_handler ("parse_command", (GLogLevelFlags)(G_LOG_LEVEL_INFO | G_LOG_LEVEL_DEBUG | G_LOG_LEVEL_MESSAGE),
parse_command_log_handler, NULL);
g_log_set_handler ("Rule",
(GLogLevelFlags)(G_LOG_LEVEL_INFO | G_LOG_LEVEL_DEBUG | G_LOG_LEVEL_MESSAGE),
Rule_log_handler, NULL);
g_log_set_handler ("Function",
(GLogLevelFlags)(G_LOG_LEVEL_INFO | G_LOG_LEVEL_DEBUG | G_LOG_LEVEL_MESSAGE),
Function_log_handler, NULL);
g_log_set_handler ("lsys",
(GLogLevelFlags)(G_LOG_LEVEL_INFO | G_LOG_LEVEL_DEBUG | G_LOG_LEVEL_MESSAGE),
lsys_log_handler, NULL);
lsys.AddFunction_SpaceTransform("rx", 0x1, 0x0, 0x0); // create a rotation function around z
//lsys.AddFunction_SpaceTransform("ry", 0x2, 0x0, 0x0); // create a rotation function around y
//lsys.AddFunction_SpaceTransform("G", 0x0, 0x2, 0x0); // create a translation function along x
lsys.AddFunction_Primitive("F", PRIMITIVE_LINE, 0.1, 0.5, 0.1); // create a line function
//lsys.AddFunction_Primitive("G", PRIMITIVE_CYLINDER, 0.160, 0.047, 0.02); // create a line function
lsys.PrintFunctionSet();
lsys.SetResult(0, "rx(60) F(3) rx(-120) F(3) rx(-120) F(3)");
//lsys.AddRule("F(t),*,*,[]:<0.5> G(t) [ rz(25) F(t) ] [ rz(-25) F(t) ] G(t) F(t) <> G(t) [ rz(5) F(t) ] [ rz(-5) F(t) ] G(t) F(t)");
//lsys.AddRule("F(t),*,*,[]:<0.1> G(t) [ ry(60) rz(45) F(t*0.75) ] [ ry(-60) rz(15) F(t*0.75) ] [ ry(-180) rz(25) F(t*0.75) ] <> G(t) [ ry(60) rz(25) F(t*0.75) ] [ ry(-60) rz(25) F(t*0.75) ] [ ry(-180) rz(25) F(t*0.75) ] ");
/*lsys.AddRule("F(t),*,*,[]:<0.1> G(t) [ ry(60) rz(45) F(t*0.75) ] [ ry(-60) rz(15) F(t*0.75) ] [ ry(-180) rz(25) F(t*0.75) ] <> G(t) [ ry(60) rz(25) F(t*0.75) ] [ ry(120) rz(25) F(t*0.75) ] [ ry(180) rz(25) F(t*0.75) ] ");*/
lsys.AddRule("F(t),*,*,[]:<> F(t/3) rx(-60) F(t/3) rx(120) F(t/3) rx(-60) F(t/3)");
//lsys.AddRule("G(t),*,*,[]:<> G(t*1.1)");
}
示例7: draw
void draw()
{
glMatrixMode(GL_MODELVIEW);
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glRotatef(rotX,1,0,0);
glRotatef(rotY,0,1,0);
glPushMatrix();
glTranslatef(3,0,0);
drawCoordinate();
glPopMatrix();
glScaled(zoom,zoom,zoom);
glPushMatrix();
lsys.DrawLevel(level);
glPopMatrix();
glPopMatrix();
glutSwapBuffers();
}
示例8: idle
void idle(void)
{
lsys.Animate();
glutPostRedisplay();
}