PositionAttitudeTransform *VideoGeode::createVideoSphere(float size, bool texRepeat) { Geode *sphere = new Geode(); sphere->addDrawable(new ShapeDrawable(new Sphere(Vec3(0, 0, 4), size))); // assign the material to the sphere StateSet *sphereStateSet = sphere->getOrCreateStateSet(); sphereStateSet->ref(); sphereStateSet->setAttribute(_material); try { sphereStateSet->setTextureAttributeAndModes(0, createVideoTexture(texRepeat), StateAttribute::ON); } catch (char *e) { throw e; } PositionAttitudeTransform *sphereTransform = new PositionAttitudeTransform(); sphereTransform->addChild(sphere); return sphereTransform; }
PositionAttitudeTransform *VideoGeode::createVideoPlane(float sizeX, float sizeY, bool texRepeat) { // vertex array Vec3Array *vertexArray = new Vec3Array(); sizeX /= 2.0; sizeY /= 2.0; vertexArray->push_back(Vec3(-sizeX, 0, -sizeY)); vertexArray->push_back(Vec3(sizeX, 0, -sizeY)); vertexArray->push_back(Vec3(sizeX, 0, sizeY)); vertexArray->push_back(Vec3(-sizeX, 0, sizeY)); /*vertexArray->push_back(Vec3(-sizeX, -sizeY, 0)); vertexArray->push_back(Vec3(sizeX, -sizeY, 0)); vertexArray->push_back(Vec3(sizeX, sizeY, 0)); vertexArray->push_back(Vec3(-sizeX, sizeY, 0));*/ // face array DrawElementsUInt *faceArray = new DrawElementsUInt(PrimitiveSet::TRIANGLES, 0); faceArray->push_back(0); // face 1 faceArray->push_back(1); faceArray->push_back(2); faceArray->push_back(2); // face 2 faceArray->push_back(3); faceArray->push_back(0); // normal array Vec3Array *normalArray = new Vec3Array(); normalArray->push_back(Vec3(0, 0, 1)); // normal index TemplateIndexArray<unsigned int, Array::UIntArrayType, 24, 4> *normalIndexArray; normalIndexArray = new TemplateIndexArray<unsigned int, Array::UIntArrayType, 24, 4>(); normalIndexArray->push_back(0); normalIndexArray->push_back(0); normalIndexArray->push_back(0); normalIndexArray->push_back(0); // texture coordinates Vec2Array *texCoords = new Vec2Array(); texCoords->push_back(Vec2(0.0f, 0.0f)); texCoords->push_back(Vec2(1.0f, 0.0f)); texCoords->push_back(Vec2(1.0f, 1.0f)); texCoords->push_back(Vec2(0.0f, 1.0f)); Geometry *geometry = new Geometry(); geometry->setVertexArray(vertexArray); geometry->setNormalArray(normalArray); geometry->setNormalIndices(normalIndexArray); geometry->setNormalBinding(Geometry::BIND_PER_VERTEX); geometry->setTexCoordArray(0, texCoords); geometry->addPrimitiveSet(faceArray); Geode *plane = new Geode(); plane->addDrawable(geometry); // assign the material to the sphere StateSet *planeStateSet = plane->getOrCreateStateSet(); planeStateSet->ref(); planeStateSet->setAttribute(_material); try { planeStateSet->setTextureAttributeAndModes(0, createVideoTexture(texRepeat), StateAttribute::ON); } catch (char *e) { throw e; } PositionAttitudeTransform *planeTransform = new PositionAttitudeTransform(); planeTransform->addChild(plane); return planeTransform; }