本文整理汇总了C++中DrawElementsUInt::push_back方法的典型用法代码示例。如果您正苦于以下问题:C++ DrawElementsUInt::push_back方法的具体用法?C++ DrawElementsUInt::push_back怎么用?C++ DrawElementsUInt::push_back使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DrawElementsUInt
的用法示例。
在下文中一共展示了DrawElementsUInt::push_back方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: doEarClipping
void doEarClipping( Geometry* planeGeometry, Vec2Array* planeVertices ) {
//list of all unclipped vertices
vector<int> remainingVertices;
for ( int i = 0; i < planeVertices->size(); i++ ){
remainingVertices.push_back( i );
}
while(remainingVertices.size() > 0) {
DrawElementsUInt* currTriangle =
new DrawElementsUInt( PrimitiveSet::TRIANGLES, 0 );
if ( remainingVertices.size() == 3 ) {
currTriangle->push_back( remainingVertices[0] );
currTriangle->push_back( remainingVertices[1] );
currTriangle->push_back( remainingVertices[2] );
remainingVertices.clear();
}
else {
int currEarIndex = findEar( planeVertices, remainingVertices );
if ( currEarIndex == 0 ){
currTriangle->push_back( remainingVertices.back() );
}
else {
currTriangle->push_back( remainingVertices[(currEarIndex-1)] );
}
currTriangle->push_back( remainingVertices[currEarIndex] );
if ( currEarIndex == remainingVertices.size() - 1 ) {
currTriangle->push_back( remainingVertices.front() );
}
else {
currTriangle->push_back( remainingVertices[(currEarIndex+1)] );
}
remainingVertices.erase( remainingVertices.begin() + currEarIndex );
}
planeGeometry-> addPrimitiveSet( currTriangle );
}
}
示例2: combinePolygons
DrawElementsUInt* combinePolygons( DrawElementsUInt* poly1, DrawElementsUInt* poly2){
DrawElementsUInt* candidatePoly = new DrawElementsUInt( PrimitiveSet::POLYGON, 0 );
for (int i = 0; i < poly1->size(); i++){
candidatePoly->push_back(poly1->at(i));
}
//Look for a shared edge
int sharedIndex1 = -1;
int sharedIndex2 = -1;
bool opposite = false;
for (int i = 0; i < candidatePoly->size(); i++) {
if (sharedIndex1 != -1) {
break;
}
for (int j = 0; j < poly2->size(); j++) {
int ind11 = candidatePoly->at(i);
int ind12 = candidatePoly->at((i+1) % candidatePoly->size());
int ind21 = poly2->at(j);
int ind22 = poly2->at((j+1) % poly2->size());
if ((ind11 == ind21) && (ind12 == ind22)){
sharedIndex1 = i;
sharedIndex2 = j;
break;
}
if ((ind11 == ind22) && (ind12 == ind21)){
sharedIndex1 = i;
sharedIndex2 = j;
opposite = true;
break;
}
}
}
if (sharedIndex1 == -1){
return NULL;
}
//insert places elements before selected location, so we go backwards when ordering is the same.
if (!opposite){
for (int i = poly2->size()-1; i >= 0; --i) {
int index = (sharedIndex2 + i + 2) % poly2->size();
candidatePoly->insert(candidatePoly->begin() + sharedIndex1 + 1, poly2->at(index));
}
}
else {
int offset = sharedIndex1 + 1;
for (int i = 0; i < poly2->size() - 2; ++i) {
int index = (sharedIndex2 + i + 2) % poly2->size();
candidatePoly->insert(candidatePoly->begin() + offset, poly2->at(index));
offset += 1;
}
}
return candidatePoly;
}
示例3: initBaseGeometry
/***************************************************************
* Function: initBaseGeometry()
***************************************************************/
void CAVEGeodeSnapWireframeCone::initBaseGeometry()
{
Vec3Array* vertices = new Vec3Array;
float rad = 1.0f, height = 1.0f, intvl = M_PI * 2 / gMinFanSegments;
// BaseGeometry contains (gMinFanSegments * 2) vertices
for (int i = 0; i < gMinFanSegments; i++)
{
vertices->push_back(Vec3(rad * cos(i * intvl), rad * sin(i * intvl), height));
}
for (int i = 0; i < gMinFanSegments; i++)
{
vertices->push_back(Vec3(rad * cos(i * intvl), rad * sin(i * intvl), 0));
}
mBaseGeometry->setVertexArray(vertices);
DrawElementsUInt* topEdges = new DrawElementsUInt(PrimitiveSet::LINE_STRIP, 0);
DrawElementsUInt* bottomEdges = new DrawElementsUInt(PrimitiveSet::LINE_STRIP, 0);
DrawElementsUInt* sideEdges = new DrawElementsUInt(PrimitiveSet::LINES, 0);
for (int i = 0; i < gMinFanSegments; i++)
{
topEdges->push_back(i);
bottomEdges->push_back(i + gMinFanSegments);
sideEdges->push_back(i);
sideEdges->push_back(i + gMinFanSegments);
}
topEdges->push_back(0);
bottomEdges->push_back(gMinFanSegments);
mBaseGeometry->addPrimitiveSet(topEdges);
mBaseGeometry->addPrimitiveSet(bottomEdges);
mBaseGeometry->addPrimitiveSet(sideEdges);
}
示例4: Widget
TFColorWidget::TFColorWidget(Interaction *interaction, Measure *b, int size)
: Widget()
, Events()
{
_interaction = interaction;
Geode *geode = new Geode();
_geom = new Geometry();
_geom->setUseDisplayList(false);
_vertices = new Vec3Array();
_vertices->push_back(Vec3(0, 0, 0));
_vertices->push_back(Vec3(0, 0, .2));
_vector = (*_vertices)[1] - (*_vertices)[0];
_vector.normalize();
_geom->setVertexArray(_vertices);
DrawElementsUInt *line = new DrawElementsUInt(osg::PrimitiveSet::LINES, 0);
line->push_back(0);
line->push_back(1);
_geom->addPrimitiveSet(line);
_colors = new Vec4Array(1);
(*_colors)[0].set(0.0, 0.0, 0.0, 1.0);
_geom->setColorArray(_colors);
_geom->setColorBinding(osg::Geometry::BIND_OVERALL);
geode->addDrawable(_geom);
_node->addChild(geode);
LineWidth *width = new LineWidth();
width->setWidth(size);
StateSet *state = _geom->getOrCreateStateSet();
state->setAttribute(width, osg::StateAttribute::ON);
state->setMode(GL_LIGHTING, StateAttribute::OFF);
_interaction->addListener(this, this);
}
示例5: mDOCollectorIndex
//Constructor: Making deep copy of 'refGeometry' without copy of 'mDOCollectorIndex'
CAVEGeometry::CAVEGeometry(CAVEGeometry *refGeometry): mDOCollectorIndex(-1)
{
/* copy primitive set and index clusters */
unsigned int nPrimitiveSets = refGeometry->getNumPrimitiveSets();
if (nPrimitiveSets > 0)
{
for (int i = 0; i < nPrimitiveSets; i++)
{
PrimitiveSet* primSetRef = refGeometry->getPrimitiveSet(i);
/* support primitive set 'DrawElementsUInt', add more types of primitive sets here if needed */
DrawElementsUInt* drawElementUIntRef = dynamic_cast <DrawElementsUInt*> (primSetRef);
if (drawElementUIntRef)
{
unsigned int nIdices = drawElementUIntRef->getNumIndices();
const GLenum &mode = drawElementUIntRef->getMode();
/* create duplicated primitive set, copy index field and add it to 'this' */
DrawElementsUInt* drawElementUIntDup = new DrawElementsUInt(mode, 0);
if (nIdices > 0)
{
for (int j = 0; j < nIdices; j++) drawElementUIntDup->push_back(drawElementUIntRef->index(j));
}
addPrimitiveSet(drawElementUIntDup);
}
}
}
/* copy the field of overlapping index by calling addIndexCluster() function sets */
const IndexClusterVector &refClusterVector = refGeometry->mIndexClusterVector;
if (refClusterVector.size() > 0)
{
for (IndexClusterVector::const_iterator itrCluster = refClusterVector.begin();
itrCluster != refClusterVector.end(); itrCluster++)
{
IndexClusterBase *clusterPtr = *itrCluster;
addIndexCluster(clusterPtr);
}
}
}
示例6: ANIMCreateSinglePageGeodeAnimation
/***************************************************************
* Function: ANIMCreateSinglePageGeodeAnimation()
***************************************************************/
void ANIMCreateSinglePageGeodeAnimation(const string& texfilename, Geode **flipUpGeode, Geode **flipDownGeode,
AnimationPathCallback **flipUpCallback, AnimationPathCallback **flipDownCallback)
{
/* coordinates of page object */
Vec3 topleft = Vec3(-0.19, 0, 0);
Vec3 bottomleft = Vec3(-0.19, 0, -0.28);
Vec3 bottomright = Vec3( 0.19, 0, -0.28);
Vec3 topright = Vec3( 0.19, 0, 0);
Vec3 start = Vec3(0, -0.004, 0);
Vec3 end = Vec3(0, 0.008, 0);
float pageH = 0.28, pageW = 0.38;
/* create page pain geometry */
*flipUpGeode = new Geode;
*flipDownGeode = new Geode;
Geometry *pageGeometry = new Geometry();
Vec3Array* vertices = new Vec3Array;
Vec2Array* texcoords = new Vec2Array(4);
Vec3Array* normals = new Vec3Array;
vertices->push_back(topleft); (*texcoords)[0].set(0, 1);
vertices->push_back(bottomleft); (*texcoords)[1].set(0, 0);
vertices->push_back(bottomright); (*texcoords)[2].set(1, 0);
vertices->push_back(topright); (*texcoords)[3].set(1, 1);
for (int i = 0; i < 4; i++)
{
normals->push_back(Vec3(0, -1, 0));
}
DrawElementsUInt* rectangle = new DrawElementsUInt(PrimitiveSet::POLYGON, 0);
rectangle->push_back(0); rectangle->push_back(1);
rectangle->push_back(2); rectangle->push_back(3);
pageGeometry->addPrimitiveSet(rectangle);
pageGeometry->setVertexArray(vertices);
pageGeometry->setTexCoordArray(0, texcoords);
pageGeometry->setNormalArray(normals);
pageGeometry->setNormalBinding(Geometry::BIND_PER_VERTEX);
(*flipUpGeode)->addDrawable(pageGeometry);
(*flipDownGeode)->addDrawable(pageGeometry);
/* apply image textures to page geodes */
Image* imgFloorplan = osgDB::readImageFile(texfilename);
int imgW = imgFloorplan->s();
int imgH = imgFloorplan->t();
Texture2D* texFloorplan = new Texture2D(imgFloorplan);
texFloorplan->setWrap(Texture::WRAP_S, Texture::CLAMP);
texFloorplan->setWrap(Texture::WRAP_T, Texture::CLAMP);
float imgRatio = (float) imgW / imgH;
float pageRatio = pageW / pageH;
if (imgRatio <= pageRatio)
{
(*texcoords)[0].set((1.0 - pageRatio / imgRatio) * 0.5, 1);
(*texcoords)[1].set((1.0 - pageRatio / imgRatio) * 0.5, 0);
(*texcoords)[2].set((1.0 + pageRatio / imgRatio) * 0.5, 0);
(*texcoords)[3].set((1.0 + pageRatio / imgRatio) * 0.5, 1);
}
else
{
(*texcoords)[0].set(0, (1.0 + imgRatio / pageRatio) * 0.5);
(*texcoords)[1].set(0, (1.0 - imgRatio / pageRatio) * 0.5);
(*texcoords)[2].set(1, (1.0 - imgRatio / pageRatio) * 0.5);
(*texcoords)[3].set(1, (1.0 + imgRatio / pageRatio) * 0.5);
}
Material *transmaterial = new Material;
transmaterial->setDiffuse(Material::FRONT_AND_BACK, Vec4(1, 1, 1, 1));
transmaterial->setAlpha(Material::FRONT_AND_BACK, 0.8f);
Material *solidmaterial = new Material;
solidmaterial->setDiffuse(Material::FRONT_AND_BACK, Vec4(1, 1, 1, 1));
solidmaterial->setAlpha(Material::FRONT_AND_BACK, 1.0f);
StateSet *flipUpStateSet = (*flipUpGeode)->getOrCreateStateSet();
flipUpStateSet->setTextureAttributeAndModes(0, texFloorplan, StateAttribute::ON);
flipUpStateSet->setMode(GL_BLEND, StateAttribute::OVERRIDE | StateAttribute::ON );
flipUpStateSet->setRenderingHint(StateSet::TRANSPARENT_BIN);
flipUpStateSet->setAttributeAndModes(transmaterial, StateAttribute::OVERRIDE | StateAttribute::ON);
StateSet *flipDownStateSet = (*flipDownGeode)->getOrCreateStateSet();
flipDownStateSet->setTextureAttributeAndModes(0, texFloorplan, StateAttribute::ON);
flipDownStateSet->setMode(GL_BLEND, StateAttribute::OVERRIDE | StateAttribute::ON );
flipDownStateSet->setRenderingHint(StateSet::TRANSPARENT_BIN);
flipDownStateSet->setAttributeAndModes(solidmaterial, StateAttribute::OVERRIDE | StateAttribute::ON);
/* create page flipping animation call backs */
AnimationPath* animationPathFlipUp = new AnimationPath;
AnimationPath* animationPathFlipDown = new AnimationPath;
animationPathFlipUp->setLoopMode(AnimationPath::NO_LOOPING);
animationPathFlipDown->setLoopMode(AnimationPath::NO_LOOPING);
Vec3 flipUpOffset, flipDownOffset;
Quat flipUpQuat, flipDownQuat;
//.........这里部分代码省略.........
示例7: Primitive_readLocalData
bool Primitive_readLocalData(Input& fr,osg::Geometry& geom)
{
bool iteratorAdvanced = false;
bool firstMatched = false;
if ((firstMatched = fr.matchSequence("DrawArrays %w %i %i %i")) ||
fr.matchSequence("DrawArrays %w %i %i") )
{
GLenum mode;
Geometry_matchPrimitiveModeStr(fr[1].getStr(),mode);
int first;
fr[2].getInt(first);
int count;
fr[3].getInt(count);
int numInstances = 0;
if (firstMatched)
{
fr[4].getInt(numInstances);
fr += 5;
}
else
{
fr += 4;
}
geom.addPrimitiveSet(new DrawArrays(mode, first, count, numInstances));
iteratorAdvanced = true;
}
else if ((firstMatched = fr.matchSequence("DrawArrayLengths %w %i %i %i {")) ||
fr.matchSequence("DrawArrayLengths %w %i %i {") )
{
int entry = fr[1].getNoNestedBrackets();
GLenum mode;
Geometry_matchPrimitiveModeStr(fr[1].getStr(),mode);
int first;
fr[2].getInt(first);
int capacity;
fr[3].getInt(capacity);
int numInstances = 0;
if (firstMatched)
{
fr[4].getInt(numInstances);
fr += 6;
}
else
{
fr += 5;
}
DrawArrayLengths* prim = new DrawArrayLengths;
prim->setMode(mode);
prim->setNumInstances(numInstances);
prim->setFirst(first);
prim->reserve(capacity);
while (!fr.eof() && fr[0].getNoNestedBrackets()>entry)
{
unsigned int i;
if (fr[0].getUInt(i))
{
prim->push_back(i);
++fr;
}
}
++fr;
geom.addPrimitiveSet(prim);
iteratorAdvanced = true;
}
else if ((firstMatched = fr.matchSequence("DrawElementsUByte %w %i %i {")) ||
fr.matchSequence("DrawElementsUByte %w %i {"))
{
int entry = fr[1].getNoNestedBrackets();
GLenum mode;
Geometry_matchPrimitiveModeStr(fr[1].getStr(),mode);
int capacity;
fr[2].getInt(capacity);
int numInstances = 0;
if (firstMatched)
{
fr[3].getInt(numInstances);
fr += 5;
}
else
{
fr += 4;
//.........这里部分代码省略.........
示例8: DrawElementsUInt
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;
}
示例9: createFloorplanGeometry
/***************************************************************
* Function: createFloorplanGeometry()
***************************************************************/
void VirtualScenicHandler::createFloorplanGeometry(const int numPages,
CAVEAnimationModeler::ANIMPageEntry **pageEntryArray)
{
if (numPages <= 0)
{
return;
}
for (int i = 0; i < numPages; i++)
{
// create floorplan geometry
float length = pageEntryArray[i]->mLength;
float width = pageEntryArray[i]->mWidth;
float altitude = pageEntryArray[i]->mAlti;
Geode *floorplanGeode = new Geode;
Geometry *floorplanGeometry = new Geometry;
Vec3Array* vertices = new Vec3Array;
Vec3Array* normals = new Vec3Array;
Vec2Array* texcoords = new Vec2Array(4);
vertices->push_back(Vec3(-length / 2, width / 2, altitude)); (*texcoords)[0].set(0, 1);
vertices->push_back(Vec3(-length / 2, -width / 2, altitude)); (*texcoords)[1].set(0, 0);
vertices->push_back(Vec3( length / 2, -width / 2, altitude)); (*texcoords)[2].set(1, 0);
vertices->push_back(Vec3( length / 2, width / 2, altitude)); (*texcoords)[3].set(1, 1);
for (int k = 0; k < 4; k++)
{
normals->push_back(Vec3(0, 0, 1));
}
DrawElementsUInt* rectangle = new DrawElementsUInt(PrimitiveSet::POLYGON, 0);
rectangle->push_back(0); rectangle->push_back(1);
rectangle->push_back(2); rectangle->push_back(3);
floorplanGeometry->addPrimitiveSet(rectangle);
floorplanGeometry->setVertexArray(vertices);
floorplanGeometry->setNormalArray(normals);
floorplanGeometry->setTexCoordArray(0, texcoords);
floorplanGeometry->setNormalBinding(Geometry::BIND_PER_VERTEX);
floorplanGeode->addDrawable(floorplanGeometry);
mFloorplanSwitch->addChild(floorplanGeode);
/* load floorplan images */
Material *transmaterial = new Material;
transmaterial->setDiffuse(Material::FRONT_AND_BACK, Vec4(1, 1, 1, 1));
transmaterial->setAlpha(Material::FRONT_AND_BACK, 1.0f);
Image* imgFloorplan = osgDB::readImageFile(pageEntryArray[i]->mTexFilename);
Texture2D* texFloorplan = new Texture2D(imgFloorplan);
StateSet *floorplanStateSet = floorplanGeode->getOrCreateStateSet();
floorplanStateSet->setTextureAttributeAndModes(0, texFloorplan, StateAttribute::ON);
floorplanStateSet->setMode(GL_BLEND, StateAttribute::OVERRIDE | StateAttribute::ON );
floorplanStateSet->setRenderingHint(StateSet::TRANSPARENT_BIN);
floorplanStateSet->setAttributeAndModes(transmaterial, StateAttribute::OVERRIDE | StateAttribute::ON);
}
}
示例10: initGeometryCylinder
/***************************************************************
* Function: initGeometryCylinder()
***************************************************************/
void CAVEGeodeShape::initGeometryCylinder(const Vec3 &initVect, const Vec3 &sVect)
{
int numFanSegs = CAVEGeodeSnapWireframeCylinder::gCurFanSegments;
float cx = initVect.x(), cy = initVect.y(), cz = initVect.z();
float rad = sVect.x(), height = sVect.z();
if (rad < 0) rad = -rad;
if (height < 0) { cz = initVect.z() + height; height = -height; }
/* take record of center vector and number of vertices, normals, texcoords */
mCenterVect = Vec3(cx, cy, cz + height * 0.5);
mNumVertices = mNumNormals = mNumTexcoords = (numFanSegs + 1) * 4;
/* create vertical edges, cap radiating edges and ring strips on side surface */
float intvl = M_PI * 2 / numFanSegs;
for (int i = 0; i <= numFanSegs; i++)
{
const float theta = i * intvl;
const float cost = cos(theta);
const float sint = sin(theta);
mVertexArray->push_back(Vec3(cx, cy, cz) + Vec3(rad * cost, rad * sint, height)); // top surface
mVertexArray->push_back(Vec3(cx, cy, cz) + Vec3(rad * cost, rad * sint, 0)); // bottom surface
mVertexArray->push_back(Vec3(cx, cy, cz) + Vec3(rad * cost, rad * sint, height)); // upper side
mVertexArray->push_back(Vec3(cx, cy, cz) + Vec3(rad * cost, rad * sint, 0)); // lower side
mNormalArray->push_back(Vec3(0, 0, 1));
mNormalArray->push_back(Vec3(0, 0, -1));
mNormalArray->push_back(Vec3(cost, sint, 0));
mNormalArray->push_back(Vec3(cost, sint, 0));
mUDirArray->push_back(Vec3(1, 0, 0)); mVDirArray->push_back(Vec3(0, 1, 0)); // top surface
mUDirArray->push_back(Vec3(1, 0, 0)); mVDirArray->push_back(Vec3(0, 1, 0)); // bottom surface
mUDirArray->push_back(Vec3(0, 0, 0)); mVDirArray->push_back(Vec3(0, 0, 1)); // upper side
mUDirArray->push_back(Vec3(0, 0, 0)); mVDirArray->push_back(Vec3(0, 0, 1)); // lower side
mTexcoordArray->push_back(Vec2(rad * cost, rad * sint) / gTextureTileSize);
mTexcoordArray->push_back(Vec2(rad * cost, rad * sint) / gTextureTileSize);
mTexcoordArray->push_back(Vec2(rad * intvl * i, height) / gTextureTileSize);
mTexcoordArray->push_back(Vec2(rad * intvl * i, 0.0f) / gTextureTileSize);
}
/* create geometries for each surface */
CAVEGeometry **geometryArrayPtr = new CAVEGeometry*[3];
for (int i = 0; i < 3; i++)
{
geometryArrayPtr[i] = new CAVEGeometry;
geometryArrayPtr[i]->setVertexArray(mVertexArray);
geometryArrayPtr[i]->setNormalArray(mNormalArray);
geometryArrayPtr[i]->setTexCoordArray(0, mTexcoordArray);
geometryArrayPtr[i]->setNormalBinding(Geometry::BIND_PER_VERTEX);
mGeometryVector.push_back(geometryArrayPtr[i]);
addDrawable(geometryArrayPtr[i]);
}
/* write primitive set and index clusters */
DrawElementsUInt* topSurface = new DrawElementsUInt(PrimitiveSet::POLYGON, 0);
DrawElementsUInt* bottomSurface = new DrawElementsUInt(PrimitiveSet::POLYGON, 0);
for (int i = 0; i <= numFanSegs; i++)
{
topSurface->push_back(i * 4);
bottomSurface->push_back((numFanSegs - i) * 4 + 1);
}
geometryArrayPtr[0]->addPrimitiveSet(topSurface);
geometryArrayPtr[1]->addPrimitiveSet(bottomSurface);
for (int i = 0; i < numFanSegs; i++)
{
DrawElementsUInt* sideSurface = new DrawElementsUInt(PrimitiveSet::POLYGON, 0);
sideSurface->push_back(i * 4 + 2); sideSurface->push_back(i * 4 + 3);
sideSurface->push_back(i * 4 + 7); sideSurface->push_back(i * 4 + 6);
geometryArrayPtr[2]->addPrimitiveSet(sideSurface);
}
for (int i = 0; i <= numFanSegs; i++)
{
geometryArrayPtr[0]->addIndexCluster(i * 4 , i * 4 + 2);
geometryArrayPtr[1]->addIndexCluster(i * 4 + 1, i * 4 + 3);
geometryArrayPtr[2]->addIndexCluster(i * 4 , i * 4 + 2);
geometryArrayPtr[2]->addIndexCluster(i * 4 + 1, i * 4 + 3);
}
}
示例11: initGeometryBox
/***************************************************************
* Function: initGeometryBox()
***************************************************************/
void CAVEGeodeShape::initGeometryBox(const Vec3 &initVect, const Vec3 &sVect)
{
float xMin, yMin, zMin, xMax, yMax, zMax;
xMin = initVect.x(); xMax = initVect.x() + sVect.x();
yMin = initVect.y(); yMax = initVect.y() + sVect.y();
zMin = initVect.z(); zMax = initVect.z() + sVect.z();
if (xMin > xMax) { xMin = initVect.x() + sVect.x(); xMax = initVect.x(); }
if (yMin > yMax) { yMin = initVect.y() + sVect.y(); yMax = initVect.y(); }
if (zMin > zMax) { zMin = initVect.z() + sVect.z(); zMax = initVect.z(); }
Vec3 up, down, front, back, left, right;
up = Vec3(0, 0, 1); down = Vec3(0, 0, -1);
front = Vec3(0, -1, 0); back = Vec3(0, 1, 0);
left = Vec3(-1, 0, 0); right = Vec3(1, 0, 0);
/* decide x, y, z span and write 'mCenterVect' */
float xspan = xMax - xMin, yspan = yMax - yMin, zspan = zMax - zMin;
mCenterVect = Vec3((xMax + xMin) * 0.5, (yMax + yMin) * 0.5, (zMax + zMin) * 0.5);
mNumVertices = mNumNormals = mNumTexcoords = 24;
mVertexArray->push_back(Vec3(xMax, yMax, zMax)); mNormalArray->push_back(up);
mVertexArray->push_back(Vec3(xMin, yMax, zMax)); mNormalArray->push_back(up);
mVertexArray->push_back(Vec3(xMin, yMin, zMax)); mNormalArray->push_back(up);
mVertexArray->push_back(Vec3(xMax, yMin, zMax)); mNormalArray->push_back(up);
mVertexArray->push_back(Vec3(xMax, yMax, zMin)); mNormalArray->push_back(down);
mVertexArray->push_back(Vec3(xMin, yMax, zMin)); mNormalArray->push_back(down);
mVertexArray->push_back(Vec3(xMin, yMin, zMin)); mNormalArray->push_back(down);
mVertexArray->push_back(Vec3(xMax, yMin, zMin)); mNormalArray->push_back(down);
for (int i = 0; i < 8; i++) { mUDirArray->push_back(right); mVDirArray->push_back(back); }
for (int i = 0; i < 2; i++)
{
mTexcoordArray->push_back(Vec2(xspan, yspan) / gTextureTileSize);
mTexcoordArray->push_back(Vec2(0, yspan) / gTextureTileSize);
mTexcoordArray->push_back(Vec2(0, 0) / gTextureTileSize);
mTexcoordArray->push_back(Vec2(xspan, 0) / gTextureTileSize);
}
mVertexArray->push_back(Vec3(xMax, yMin, zMax)); mNormalArray->push_back(front);
mVertexArray->push_back(Vec3(xMin, yMin, zMax)); mNormalArray->push_back(front);
mVertexArray->push_back(Vec3(xMin, yMin, zMin)); mNormalArray->push_back(front);
mVertexArray->push_back(Vec3(xMax, yMin, zMin)); mNormalArray->push_back(front);
mVertexArray->push_back(Vec3(xMax, yMax, zMax)); mNormalArray->push_back(back);
mVertexArray->push_back(Vec3(xMin, yMax, zMax)); mNormalArray->push_back(back);
mVertexArray->push_back(Vec3(xMin, yMax, zMin)); mNormalArray->push_back(back);
mVertexArray->push_back(Vec3(xMax, yMax, zMin)); mNormalArray->push_back(back);
for (int i = 0; i < 8; i++) { mUDirArray->push_back(right); mVDirArray->push_back(up); }
for (int i = 0; i < 2; i++)
{
mTexcoordArray->push_back(Vec2(xspan, zspan) / gTextureTileSize);
mTexcoordArray->push_back(Vec2(0, zspan) / gTextureTileSize);
mTexcoordArray->push_back(Vec2(0, 0) / gTextureTileSize);
mTexcoordArray->push_back(Vec2(xspan, 0) / gTextureTileSize);
}
mVertexArray->push_back(Vec3(xMin, yMax, zMax)); mNormalArray->push_back(left);
mVertexArray->push_back(Vec3(xMin, yMin, zMax)); mNormalArray->push_back(left);
mVertexArray->push_back(Vec3(xMin, yMin, zMin)); mNormalArray->push_back(left);
mVertexArray->push_back(Vec3(xMin, yMax, zMin)); mNormalArray->push_back(left);
mVertexArray->push_back(Vec3(xMax, yMax, zMax)); mNormalArray->push_back(right);
mVertexArray->push_back(Vec3(xMax, yMin, zMax)); mNormalArray->push_back(right);
mVertexArray->push_back(Vec3(xMax, yMin, zMin)); mNormalArray->push_back(right);
mVertexArray->push_back(Vec3(xMax, yMax, zMin)); mNormalArray->push_back(right);
for (int i = 0; i < 8; i++) { mUDirArray->push_back(back); mVDirArray->push_back(up); }
for (int i = 0; i < 2; i++)
{
mTexcoordArray->push_back(Vec2(yspan, zspan) / gTextureTileSize);
mTexcoordArray->push_back(Vec2(0, zspan) / gTextureTileSize);
mTexcoordArray->push_back(Vec2(0, 0) / gTextureTileSize);
mTexcoordArray->push_back(Vec2(yspan, 0) / gTextureTileSize);
}
/* create geometries for each surface */
CAVEGeometry **geometryArrayPtr = new CAVEGeometry*[6];
for (int i = 0; i < 6; i++)
{
geometryArrayPtr[i] = new CAVEGeometry;
geometryArrayPtr[i]->setVertexArray(mVertexArray);
geometryArrayPtr[i]->setNormalArray(mNormalArray);
geometryArrayPtr[i]->setTexCoordArray(0, mTexcoordArray);
geometryArrayPtr[i]->setNormalBinding(Geometry::BIND_PER_VERTEX);
mGeometryVector.push_back(geometryArrayPtr[i]);
addDrawable(geometryArrayPtr[i]);
}
/* write primitive set and index clusters */
DrawElementsUInt* topSurface = new DrawElementsUInt(PrimitiveSet::POLYGON, 0);
DrawElementsUInt* bottomSurface = new DrawElementsUInt(PrimitiveSet::POLYGON, 0);
DrawElementsUInt* frontSurface = new DrawElementsUInt(PrimitiveSet::POLYGON, 0);
DrawElementsUInt* backSurface = new DrawElementsUInt(PrimitiveSet::POLYGON, 0);
DrawElementsUInt* leftSurface = new DrawElementsUInt(PrimitiveSet::POLYGON, 0);
DrawElementsUInt* rightSurface = new DrawElementsUInt(PrimitiveSet::POLYGON, 0);
topSurface->push_back(0); bottomSurface->push_back(4);
//.........这里部分代码省略.........
示例12: generate
void BoxShape::generate()
{
/****************************************************************
* *
* Vertices *
* *
****************************************************************
*/
vertices = new Vec3Array();
//assuming box points coming this way: 5-----------6
// /| /|
// / | / |
// / | / |
// 0---4-------3---7
// | / | /
// | / | /
// |/ |/
// 1-----------2
// check if all 4 points are present, otherwise use default method to calculate vertices
if(!genVer)
{
vertices->push_back(p1);
vertices->push_back(p2);
vertices->push_back(p3);
vertices->push_back(p4);
vertices->push_back(p5);
vertices->push_back(p6);
vertices->push_back(p7);
vertices->push_back(p8);
//setVertexArray(vertices);
}
else if (genVer)
{ // -y = coming out of screen?
vertices->push_back(Vec3( center.x()-(width/2) , center.y()-(depth/2) , center.z()+(height/2) ));
vertices->push_back(Vec3( center.x()-(width/2) , center.y()-(depth/2) , center.z()-(height/2) ));
vertices->push_back(Vec3( center.x()+(width/2) , center.y()-(depth/2) , center.z()-(height/2) ));
vertices->push_back(Vec3( center.x()+(width/2) , center.y()-(depth/2) , center.z()+(height/2) ));
vertices->push_back(Vec3( center.x()-(width/2) , center.y()+(depth/2) , center.z()-(height/2) ));
vertices->push_back(Vec3( center.x()-(width/2) , center.y()+(depth/2) , center.z()+(height/2) ));
vertices->push_back(Vec3( center.x()+(width/2) , center.y()+(depth/2) , center.z()+(height/2) ));
vertices->push_back(Vec3( center.x()+(width/2) , center.y()+(depth/2) , center.z()-(height/2) ));
//setVertexArray(vertices);
}
setVertexArray(vertices);
//front face
DrawElementsUInt* frontface = new DrawElementsUInt(PrimitiveSet::QUADS, 0);
frontface->push_back(0);
frontface->push_back(1);
frontface->push_back(2);
frontface->push_back(3);
addPrimitiveSet(frontface);
//back face
DrawElementsUInt* backface = new DrawElementsUInt(PrimitiveSet::QUADS, 0);
backface->push_back(4);
backface->push_back(5);
backface->push_back(6);
backface->push_back(7);
addPrimitiveSet(backface);
//top face
DrawElementsUInt* topface = new DrawElementsUInt(PrimitiveSet::QUADS, 0);
topface->push_back(5);
topface->push_back(0);
topface->push_back(3);
topface->push_back(6);
addPrimitiveSet(topface);
//bottom face
DrawElementsUInt* bottomface = new DrawElementsUInt(PrimitiveSet::QUADS, 0);
bottomface->push_back(1);
bottomface->push_back(4);
bottomface->push_back(7);
bottomface->push_back(2);
addPrimitiveSet(bottomface);
//left face
DrawElementsUInt* leftface = new DrawElementsUInt(PrimitiveSet::QUADS, 0);
leftface->push_back(0);
leftface->push_back(5);
leftface->push_back(4);
leftface->push_back(1);
addPrimitiveSet(leftface);
//right face
DrawElementsUInt* rightface = new DrawElementsUInt(PrimitiveSet::QUADS, 0);
rightface->push_back(3);
rightface->push_back(2);
rightface->push_back(7);
rightface->push_back(6);
addPrimitiveSet(rightface);
//.........这里部分代码省略.........
示例13: resize
/***************************************************************
* Function: resize()
***************************************************************/
void CAVEGeodeSnapWireframeLine::resize(osg::Vec3 &gridVect)
{
/*
Material* material = new Material;
material->setAmbient(Material::FRONT_AND_BACK, Vec4(0.0, 1.0, 0.0, 1.0));
material->setDiffuse(Material::FRONT_AND_BACK, Vec4(1.0, 1.0, 0.0, 1.0));
material->setSpecular(Material::FRONT_AND_BACK, osg::Vec4( 1.f, 1.f, 1.f, 1.0f));
material->setAlpha(Material::FRONT_AND_BACK, 1.f);
StateSet* stateset = new StateSet();
stateset->setAttributeAndModes(material, StateAttribute::OVERRIDE | StateAttribute::ON);
setStateSet(stateset);
*/
// calculate grid vector
float snapUnitX, snapUnitY, snapUnitZ;
snapUnitX = snapUnitY = snapUnitZ = mSnappingUnitDist;
if (mScaleVect.x() < 0)
snapUnitX = -mSnappingUnitDist;
if (mScaleVect.y() < 0)
snapUnitY = -mSnappingUnitDist;
if (mScaleVect.z() < 0)
snapUnitZ = -mSnappingUnitDist;
int xSeg = (int)(abs((int)((mScaleVect.x() + 0.5 * snapUnitX) / mSnappingUnitDist)));
int ySeg = (int)(abs((int)((mScaleVect.y() + 0.5 * snapUnitY) / mSnappingUnitDist)));
int zSeg = (int)(abs((int)((mScaleVect.z() + 0.5 * snapUnitZ) / mSnappingUnitDist)));
Vec3 roundedVect;
roundedVect.x() = xSeg * snapUnitX; gridVect.x() = roundedVect.x() / mSnappingUnitDist;
roundedVect.y() = ySeg * snapUnitY; gridVect.y() = roundedVect.y() / mSnappingUnitDist;
roundedVect.z() = zSeg * snapUnitZ; gridVect.z() = roundedVect.z() / mSnappingUnitDist;
mDiagonalVect = roundedVect;
// update box corners in 'mBaseGeometry'
float xMin, yMin, zMin, xMax, yMax, zMax;
xMin = mInitPosition.x(); xMax = xMin + roundedVect.x();
yMin = mInitPosition.y(); yMax = yMin + roundedVect.y();
zMin = mInitPosition.z(); zMax = zMin + roundedVect.z();
Array* baseVertArray = mBaseGeometry->getVertexArray();
if (baseVertArray->getType() == Array::Vec3ArrayType)
{
Vec3* vertexArrayDataPtr = (Vec3*) (baseVertArray->getDataPointer());
vertexArrayDataPtr[0] = Vec3(xMax, yMax, zMax);
vertexArrayDataPtr[1] = Vec3(xMin, yMax, zMax);
vertexArrayDataPtr[2] = Vec3(xMin, yMin, zMax);
vertexArrayDataPtr[3] = Vec3(xMax, yMin, zMax);
vertexArrayDataPtr[4] = Vec3(xMax, yMax, zMin);
vertexArrayDataPtr[5] = Vec3(xMin, yMax, zMin);
vertexArrayDataPtr[6] = Vec3(xMin, yMin, zMin);
vertexArrayDataPtr[7] = Vec3(xMax, yMin, zMin);
}
mBaseGeometry->dirtyDisplayList();
mBaseGeometry->dirtyBound();
// update snapping wire geometry
if (mSnapwireGeometry)
removeDrawable(mSnapwireGeometry);
mSnapwireGeometry = new Geometry();
Vec3Array* snapvertices = new Vec3Array;
int vertoffset = 0;
if (xSeg > 1) // (xSeg - 1) * 4 vertices
{
for (int i = 1; i <= xSeg - 1; i++)
{
snapvertices->push_back(Vec3(xMin + i * snapUnitX, yMin, zMin));
snapvertices->push_back(Vec3(xMin + i * snapUnitX, yMax, zMin));
snapvertices->push_back(Vec3(xMin + i * snapUnitX, yMax, zMax));
snapvertices->push_back(Vec3(xMin + i * snapUnitX, yMin, zMax));
DrawElementsUInt* edges = new DrawElementsUInt(PrimitiveSet::LINE_STRIP, 0);
edges->push_back(vertoffset + (i-1)*4);
edges->push_back(vertoffset + (i-1)*4 + 1);
edges->push_back(vertoffset + (i-1)*4 + 2);
edges->push_back(vertoffset + (i-1)*4 + 3);
edges->push_back(vertoffset + (i-1)*4);
mSnapwireGeometry->addPrimitiveSet(edges);
}
vertoffset += (xSeg - 1) * 4;
}
if (ySeg > 1) // (ySeg - 1) * 4 vertices
{
for (int i = 1; i <= ySeg - 1; i++)
{
snapvertices->push_back(Vec3(xMin, yMin + i * snapUnitY, zMin));
snapvertices->push_back(Vec3(xMax, yMin + i * snapUnitY, zMin));
snapvertices->push_back(Vec3(xMax, yMin + i * snapUnitY, zMax));
snapvertices->push_back(Vec3(xMin, yMin + i * snapUnitY, zMax));
DrawElementsUInt* edges = new DrawElementsUInt(PrimitiveSet::LINE_STRIP, 0);
edges->push_back(vertoffset + (i-1)*4);
edges->push_back(vertoffset + (i-1)*4 + 1);
edges->push_back(vertoffset + (i-1)*4 + 2);
edges->push_back(vertoffset + (i-1)*4 + 3);
edges->push_back(vertoffset + (i-1)*4);
mSnapwireGeometry->addPrimitiveSet(edges);
//.........这里部分代码省略.........