本文整理汇总了C++中Sphere::addChild方法的典型用法代码示例。如果您正苦于以下问题:C++ Sphere::addChild方法的具体用法?C++ Sphere::addChild怎么用?C++ Sphere::addChild使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Sphere
的用法示例。
在下文中一共展示了Sphere::addChild方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: setup
void setup()
{
size(1024, 768);
background(0);
setFrameRate(60);
// Setup lighting
ambientLight(30);
light.init(200, 200, 200, 0, 3, 0);
// Uncomment this line to see the position of the light
light.drawDebug(true);
// Init 3d object's properties
box.init(50, 25, 75);
box.setPosition(width/2.0f, height/2.0f);
sphere1.init(30);
sphere2.init(60);
sphere3.init(100);
// Now, we make the spheres children of the box's (scene node)
box.addChild( sphere1 );
box.addChild( sphere2 );
box.addChild( sphere3 );
// Translate the sphere (relative to its parent, the box)
// This way, when we rotate the box (parent object), the spheres will orbitate around it
sphere1.setPosition( 2, 0, 0 );
sphere2.setPosition( 5, 0, 0 );
sphere3.setPosition( 7, 0, 0 );
// Add the second light as child of one of the spheres
sphere1.addChild( light );
}
示例2: initialize
void MyScene::initialize()
{
checkOpenGLErrors("MyScene::initialize0");
// Initialize OpenGL
glEnable(GL_DEPTH_TEST); // Turn depth testing
glClearColor(0.5f, 0.5f, 0.5f, 1.0f); // Set the window clear color
// Build shader proram
ShaderInfo shaders[] = {
{ GL_VERTEX_SHADER, "vertexShaderPerPixel.vs.glsl" },
{ GL_FRAGMENT_SHADER, "fragmentShaderPerPixel.fs.glsl" },
{ GL_NONE, NULL } // signals that there are no more shaders
};
perPixelShaderProgram = BuildShaderProgram(shaders);
checkOpenGLErrors("MyScene::initialize1");
// Set up the uniform blocks for this shader
SharedProjectionAndViewing::setUniformBlockForShader(perPixelShaderProgram);
SharedMaterialProperties::setUniformBlockForShader(perPixelShaderProgram);
SharedGeneralLighting::setUniformBlockForShader(perPixelShaderProgram);
// Build shader proram
ShaderInfo shadersPointFive[] = {
{ GL_VERTEX_SHADER, "vertexShaderPerPixel.vs.glsl" },
{ GL_FRAGMENT_SHADER, "fragmentShaderPerPixelMultiTexture.fs.glsl" },
{ GL_NONE, NULL } // signals that there are no more shaders
};
GLuint modelShaderProgram = BuildShaderProgram(shadersPointFive);
checkOpenGLErrors("MyScene::initialize1");
// Set up the uniform blocks for this shader
SharedProjectionAndViewing::setUniformBlockForShader(modelShaderProgram);
SharedMaterialProperties::setUniformBlockForShader(modelShaderProgram);
SharedGeneralLighting::setUniformBlockForShader(modelShaderProgram);
// Build shader proram
ShaderInfo shaders2[] = {
{ GL_VERTEX_SHADER, "vertexShader.vs.glsl" },
{ GL_FRAGMENT_SHADER, "fragmentShader.fs.glsl" },
{ GL_NONE, NULL } // signals that there are no more shaders
};
shaderProgram = BuildShaderProgram(shaders2);
checkOpenGLErrors("MyScene::initialize2");
// Set up the uniform blocks for this shader
SharedProjectionAndViewing::setUniformBlockForShader(shaderProgram);
SharedMaterialProperties::setUniformBlockForShader(shaderProgram);
SharedGeneralLighting::setUniformBlockForShader(shaderProgram);
Cube* cube = new Cube();
//cube->initialize();
cube->material.setAmbientAndDiffuseMat(glm::vec4(0.1f, 0.1f, 1.0f, 1.0f));
cube->material.setupTexture("Brick.bmp", DECAL);
//cube->addBehavior(new Behavior());
vector<glm::vec3> p;
p.push_back(glm::vec3(0.0f, 0.0f, 0.0f));
p.push_back(glm::vec3(0.0f, 0.0f, 20.0f));
p.push_back(glm::vec3(0.0f, 10.0f, 20.0f));
p.push_back(glm::vec3(0.0f, 10.0f, -20.0f));
//points.push_back(glm::vec3(0.0f, 0.0f, 0.0f));
//points.push_back(glm::vec3(0.0f, 0.0f, 5.0f));
cube->addBehavior(new WaypointBehavior(p, 1));
addChild(cube);
Sphere* sun = new Sphere(1, 64, 64);
//sphere->initialize();
sun->material.setAmbientAndDiffuseMat(glm::vec4(1.0f, 1.0f, 0.1f, 1.0f));
sun->material.setupTexture("preview_sun.jpg", REPLACE_AMBIENT_DIFFUSE);
sun->addBehavior(new Behavior());
sun->addBehavior(new OrbitBehavior(glm::vec3(0.0f, 1.0f, 0.0f), 2.0f, 1.0f));
addChild(sun);
Sphere* earth = new Sphere(0.5);
//earth->initialize();
earth->material.setAmbientAndDiffuseMat(glm::vec4(0.0f, 0.5f, 0.0f, 1.0f));
earth->material.setupTexture("earth.bmp", REPLACE_AMBIENT_DIFFUSE);
earth->addBehavior(new Behavior());
earth->addBehavior(new OrbitBehavior(glm::vec3(0.0f, 1.0f, 0.0f), 2.5f, 1.5f));
sun->addChild(earth);
Sphere* moon = new Sphere(0.25);
//moon->initialize();
moon->material.setupTexture("moon.bmp", REPLACE_AMBIENT_DIFFUSE);
moon->addBehavior(new Behavior());
moon->addBehavior(new OrbitBehavior(glm::vec3(0.0f, 1.0f, 0.0f), 1.0f, 2.0f));
earth->addChild(moon);
//Model ===================================================
AssimpModel* model = new AssimpModel("model/nanosuit.obj");
//model->initialize();
//.........这里部分代码省略.........