本文整理汇总了C++中DrawElementsUInt类的典型用法代码示例。如果您正苦于以下问题:C++ DrawElementsUInt类的具体用法?C++ DrawElementsUInt怎么用?C++ DrawElementsUInt使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DrawElementsUInt类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
示例2: cos
/***************************************************************
* 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);
}
示例3: 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 );
}
}
示例4: updateVertexMaskingVector
/***************************************************************
* Function: updateVertexMaskingVector()
*
* 'updateVertexMaskingVector' without input value: checks all
* 'CAVEGeometry' objects and mark vertices of selected geometries
* in 'mVertexMaskingVector', and vertices clusters of them.
*
***************************************************************/
void CAVEGeodeShape::updateVertexMaskingVector()
{
mVertexMaskingVector.clear();
mVertexMaskingVector.resize(mNumVertices, false);
if (mGeometryVector.size() <= 0) return;
for (int i = 0; i < mGeometryVector.size(); i++)
{
if (mGeometryVector[i]->mDOCollectorIndex >= 0)
{
/* mark single indices contained in mGeometryVector[i] */
unsigned int nPrimitiveSets = mGeometryVector[i]->getNumPrimitiveSets();
if (nPrimitiveSets > 0)
{
for (int j = 0; j < nPrimitiveSets; j++)
{
PrimitiveSet *primSetRef = mGeometryVector[i]->getPrimitiveSet(j);
/* 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();
if (nIdices > 0)
{
for (int k = 0; k < nIdices; k++)
{
const int index = drawElementUIntRef->index(k);
mVertexMaskingVector[index] = true;
}
}
}
}
}
/* mark clustered indices contained in 'mIndexClusterVector' */
const int numClusters = mGeometryVector[i]->mIndexClusterVector.size();
for (int j = 0; j < numClusters; j++)
{
CAVEGeometry::IndexClusterBase *clusterPtr = mGeometryVector[i]->mIndexClusterVector[j];
for (int k = 0; k < clusterPtr->mNumIndices; k++)
{
const int index = clusterPtr->mIndexVector[k];
mVertexMaskingVector[index] = true;
}
}
}
}
}
示例5: getNumPrimitiveSets
/***************************************************************
* Function: setPrimitiveSetModes()
***************************************************************/
void CAVEGeometry::setPrimitiveSetModes(const GLenum &mode)
{
unsigned int nPrimitiveSets = getNumPrimitiveSets();
if (nPrimitiveSets > 0)
{
for (int i = 0; i < nPrimitiveSets; i++)
{
PrimitiveSet* primset = getPrimitiveSet(i);
/* support primitive set 'DrawElementsUInt', add more types of primitive sets here if needed */
DrawElementsUInt* drawElementUIntRef = dynamic_cast <DrawElementsUInt*> (primset);
if (drawElementUIntRef) drawElementUIntRef->setMode(mode);
}
}
}
示例6: 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);
}
示例7: 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);
}
}
}
示例8: 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;
//.........这里部分代码省略.........
示例9: Vec3Array
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;
}
示例10: Primitive_readLocalData
//.........这里部分代码省略.........
unsigned int i;
if (fr[0].getUInt(i))
{
prim->push_back(i);
++fr;
}
}
++fr;
geom.addPrimitiveSet(prim);
iteratorAdvanced = true;
}
else if ((firstMatched = fr.matchSequence("DrawElementsUShort %w %i %i {")) ||
fr.matchSequence("DrawElementsUShort %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;
}
DrawElementsUShort* prim = new DrawElementsUShort;
prim->setMode(mode);
prim->setNumInstances(numInstances);
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("DrawElementsUInt %w %i %i {")) ||
fr.matchSequence("DrawElementsUInt %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;
}
DrawElementsUInt* prim = new DrawElementsUInt;
prim->setMode(mode);
prim->setNumInstances(numInstances);
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;
}
return iteratorAdvanced;
}
示例11: sqrt
/***************************************************************
* Function: resize()
***************************************************************/
void CAVEGeodeSnapWireframeCone::resize(osg::Vec3 &gridVect)
{
// calculate rounded vector
float height = mScaleVect.z(),
rad = sqrt(mScaleVect.x() * mScaleVect.x() + mScaleVect.y() * mScaleVect.y());
int hSeg, radSeg, fanSeg, hDir = 1;
if (height < 0)
{
height = -height;
hDir = -1;
}
hSeg = (int)(abs((int)(height / mSnappingUnitDist)) + 0.5);
radSeg = (int)(abs((int)(rad / mSnappingUnitDist)) + 0.5);
fanSeg = (int)(abs((int)(rad * M_PI * 2 / mSnappingUnitDist)) + 0.5);
if (fanSeg < gMinFanSegments)
fanSeg = gMinFanSegments;
float intvl = M_PI * 2 / fanSeg;
height = hSeg * mSnappingUnitDist;
rad = radSeg * mSnappingUnitDist;
gridVect = Vec3(radSeg, 0, hSeg * hDir);
mDiagonalVect = Vec3(rad, rad, height * hDir);
gCurFanSegments = 10;//fanSeg; // update number of fan segment, this parameter is passed to 'CAVEGeodeShape'
// update 'mSnapwireGeometry' geometry, do not use 'mBaseGeometry' anymore
if (mBaseGeometry)
{
removeDrawable(mBaseGeometry);
mBaseGeometry = NULL;
}
if (mSnapwireGeometry)
removeDrawable(mSnapwireGeometry);
mSnapwireGeometry = new Geometry();
Vec3Array* snapvertices = new Vec3Array;
int vertoffset = 0;
// create vertical edges, cap radiating edges and ring strips on side surface
for (int i = 0; i <= hSeg; i++)
{
for (int j = 0; j < fanSeg; j++)
{
float theta = j * intvl;
snapvertices->push_back(mInitPosition + Vec3(rad * cos(theta), rad * sin(theta), i * mSnappingUnitDist * hDir));
}
}
snapvertices->push_back(mInitPosition);
snapvertices->push_back(mInitPosition + Vec3(0, 0, height * hDir));
for (int i = 0; i <= hSeg; i++)
{
DrawElementsUInt* sideRingStrip = new DrawElementsUInt(PrimitiveSet::LINE_STRIP, 0);
for (int j = 0; j < fanSeg; j++)
{
sideRingStrip->push_back(vertoffset + i * fanSeg + j);
}
sideRingStrip->push_back(vertoffset + i * fanSeg);
mSnapwireGeometry->addPrimitiveSet(sideRingStrip);
}
DrawElementsUInt* sideVerticalEdges = new DrawElementsUInt(PrimitiveSet::LINES, 0);
DrawElementsUInt* capRadiatingEdges = new DrawElementsUInt(PrimitiveSet::LINES, 0);
for (int j = 0; j < fanSeg; j++)
{
sideVerticalEdges->push_back(vertoffset + j);
sideVerticalEdges->push_back(vertoffset + j + fanSeg * hSeg);
capRadiatingEdges->push_back((hSeg + 1) * fanSeg);
capRadiatingEdges->push_back(vertoffset + j);
capRadiatingEdges->push_back((hSeg + 1) * fanSeg + 1);
capRadiatingEdges->push_back(vertoffset + j + fanSeg * hSeg);
}
mSnapwireGeometry->addPrimitiveSet(sideVerticalEdges);
mSnapwireGeometry->addPrimitiveSet(capRadiatingEdges);
vertoffset += (hSeg + 1) * fanSeg + 2;
// create ring strips on two caps
for (int i = 1; i < radSeg; i++)
{
float r = i * mSnappingUnitDist;
for (int j = 0; j < fanSeg; j++)
{
float theta = j * intvl;
snapvertices->push_back(mInitPosition + Vec3(r * cos(theta), r * sin(theta), height * hDir));
snapvertices->push_back(mInitPosition + Vec3(r * cos(theta), r * sin(theta), 0));
}
}
for (int i = 1; i < radSeg; i++)
{
DrawElementsUInt* topRingStrip = new DrawElementsUInt(PrimitiveSet::LINE_STRIP, 0);
DrawElementsUInt* bottomRingStrip = new DrawElementsUInt(PrimitiveSet::LINE_STRIP, 0);
//.........这里部分代码省略.........
示例12: Vec2Array
/***************************************************************
* 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);
}
}
示例13: Vec3
/***************************************************************
* 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);
}
}
示例14: Vec4
/***************************************************************
* 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);
//.........这里部分代码省略.........
示例15: DrawElementsUInt
/***************************************************************
* Function: initBaseGeometry()
***************************************************************/
void CAVEGeodeSnapWireframeBox::initBaseGeometry()
{
float xMin, yMin, zMin, xMax, yMax, zMax;
xMin = 0.0; xMax = 1.0;
yMin = 0.0; yMax = 1.0;
zMin = 0.0; zMax = 1.0;
Vec3Array* vertices = new Vec3Array;
vertices->push_back(Vec3(xMax, yMax, zMax));
vertices->push_back(Vec3(xMin, yMax, zMax));
vertices->push_back(Vec3(xMin, yMin, zMax));
vertices->push_back(Vec3(xMax, yMin, zMax));
vertices->push_back(Vec3(xMax, yMax, zMin));
vertices->push_back(Vec3(xMin, yMax, zMin));
vertices->push_back(Vec3(xMin, yMin, zMin));
vertices->push_back(Vec3(xMax, yMin, zMin));
mBaseGeometry->setVertexArray(vertices);
DrawElementsUInt* topEdges = new DrawElementsUInt(PrimitiveSet::LINE_STRIP, 0);
DrawElementsUInt* bottomEdges = new DrawElementsUInt(PrimitiveSet::LINE_STRIP, 0);
topEdges->push_back(0); bottomEdges->push_back(4);
topEdges->push_back(1); bottomEdges->push_back(5);
topEdges->push_back(2); bottomEdges->push_back(6);
topEdges->push_back(3); bottomEdges->push_back(7);
topEdges->push_back(0); bottomEdges->push_back(4);
DrawElementsUInt* sideEdges = new DrawElementsUInt(PrimitiveSet::LINES, 0);
sideEdges->push_back(0); sideEdges->push_back(4);
sideEdges->push_back(1); sideEdges->push_back(5);
sideEdges->push_back(2); sideEdges->push_back(6);
sideEdges->push_back(3); sideEdges->push_back(7);
mBaseGeometry->addPrimitiveSet(topEdges);
mBaseGeometry->addPrimitiveSet(bottomEdges);
mBaseGeometry->addPrimitiveSet(sideEdges);
}