/***************************************************************
* Function: acceptCAVEGeodeShape()
*
* Compared with original coordinates data in 'CAVEGeodeShape', 
* generated coordinates in 'CAVEGeodeIconSurface' is eaxctly the
* the same as those appeared in 'CAVEGeodeShape'. The scaling and
* translation to 'gIconCenter' effects are impletemented by its
* acendent 'PositionAltitudeTransform' object.
* 
***************************************************************/
void CAVEGroupIconSurface::acceptCAVEGeodeShape(CAVEGeodeShape *shapeGeode, CAVEGeodeShape *shapeGeodeRef)
{
    mCAVEGeodeShapeOriginPtr = shapeGeode;

    CAVEGeometryVector &orgGeomVector = shapeGeode->getCAVEGeometryVector();
    CAVEGeometryVector &refGeomVector = shapeGeodeRef->getCAVEGeometryVector();
    int nGeoms = orgGeomVector.size();
    if (nGeoms <= 0) return;

    /* re-generate vertex coordinate list, keep normal and texcoords the same from 'CAGEGeodeShape' */
    mSurfVertexArray = new Vec3Array;
    mSurfNormalArray = new Vec3Array;
    mSurfUDirArray = new Vec3Array;
    mSurfVDirArray = new Vec3Array;
    mSurfTexcoordArray = new Vec2Array;

    Vec3Array* geodeVertexArray = shapeGeode->mVertexArray;
    Vec3Array* geodeNormalArray = shapeGeode->mNormalArray;
    Vec3Array* geodeUDirArray = shapeGeode->mUDirArray;
    Vec3Array* geodeVDirArray = shapeGeode->mVDirArray;
    Vec2Array* geodeTexcoordArray = shapeGeode->mTexcoordArray;

    Vec3 *geodeVertexDataPtr, *geodeNormalDataPtr, *geodeUDirDataPtr, *geodeVDirDataPtr;
    Vec2 *geodeTexcoordDataPtr;

    /* check the valid status of all data field from 'CAVEGeodeShape' */
    if (geodeVertexArray->getType() == Array::Vec3ArrayType)
        geodeVertexDataPtr = (Vec3*) (geodeVertexArray->getDataPointer());
    else return;

    if (geodeNormalArray->getType() == Array::Vec3ArrayType)
        geodeNormalDataPtr = (Vec3*) (geodeNormalArray->getDataPointer());
    else return;

    if (geodeUDirArray->getType() == Array::Vec3ArrayType)
        geodeUDirDataPtr = (Vec3*) (geodeUDirArray->getDataPointer());
    else return;

    if (geodeVDirArray->getType() == Array::Vec3ArrayType)
        geodeVDirDataPtr = (Vec3*) (geodeVDirArray->getDataPointer());
    else return;

    if (geodeTexcoordArray->getType() == Array::Vec2ArrayType)
        geodeTexcoordDataPtr = (Vec2*) (geodeTexcoordArray->getDataPointer());
    else return;

    /* convert vertex coordinates from CAVEGeodeShape space to CAVEGeodeIcon space */
    int nVerts = shapeGeode->mNumVertices;
    for (int i = 0; i < nVerts; i++) mSurfVertexArray->push_back(geodeVertexDataPtr[i]);

    /* preserve the same normals and texture coordinates */
    int nNormals = shapeGeode->mNumNormals;
    for (int i = 0; i < nNormals; i++)
    {
	mSurfNormalArray->push_back(geodeNormalDataPtr[i]);
	mSurfUDirArray->push_back(geodeUDirDataPtr[i]);
	mSurfVDirArray->push_back(geodeVDirDataPtr[i]);
    }

    int nTexcoords = shapeGeode->mNumTexcoords;
    for (int i = 0; i < nTexcoords; i++) mSurfTexcoordArray->push_back(geodeTexcoordDataPtr[i]);

    /* apply offset from 'gShapeCenter' to Vec3(0, 0, 0) on root level */
    Matrixf transMat;
    transMat.makeTranslate(-gShapeCenter);
    mRootTrans->setMatrix(transMat);

    /* copy CAVEGeometry objects into separate 'CAVEGeodeIconSurface' */
    for (int i = 0; i < nGeoms; i++)
    {
	CAVEGeodeIconSurface *iconSurface = new CAVEGeodeIconSurface(&mSurfVertexArray, &mSurfNormalArray,
					&mSurfTexcoordArray, &(orgGeomVector[i]), &(refGeomVector[i]));

	/* 1) take record of 'iconSurface' in mCAVEGeodeIconVector; 2) add it to 'this' group */
	mCAVEGeodeIconVector.push_back(iconSurface);
	mRootTrans->addChild(iconSurface);
    }
}
Пример #2
0
/***************************************************************
* Constructor: CAVEGeodeShape()
*
* 'mDOCollectorIndex' will not be copied unless the shape is
*  selected by 'DOGeometryCollecotr'
*
***************************************************************/
CAVEGeodeShape::CAVEGeodeShape(CAVEGeodeShape *geodeShapeRef): mDOCollectorIndex(-1)
{
    mVertexArray = new Vec3Array;
    mNormalArray = new Vec3Array;
    mUDirArray = new Vec3Array;
    mVDirArray = new Vec3Array;
    mTexcoordArray = new Vec2Array;

    Vec3Array* geodeVertexArray = geodeShapeRef->mVertexArray;
    Vec3Array* geodeNormalArray = geodeShapeRef->mNormalArray;
    Vec3Array* geodeUDirArray = geodeShapeRef->mUDirArray;
    Vec3Array* geodeVDirArray = geodeShapeRef->mVDirArray;
    Vec2Array* geodeTexcoordArray = geodeShapeRef->mTexcoordArray;

    Vec3 *geodeVertexDataPtr, *geodeNormalDataPtr, *geodeUDirDataPtr, *geodeVDirDataPtr;
    Vec2 *geodeTexcoordDataPtr;

    /* check the valid status of all data field from 'CAVEGeodeShape' */
    if (geodeVertexArray->getType() == Array::Vec3ArrayType)
        geodeVertexDataPtr = (Vec3*) (geodeVertexArray->getDataPointer());
    else return;

    if (geodeNormalArray->getType() == Array::Vec3ArrayType)
        geodeNormalDataPtr = (Vec3*) (geodeNormalArray->getDataPointer());
    else return;

    if (geodeUDirArray->getType() == Array::Vec3ArrayType)
        geodeUDirDataPtr = (Vec3*) (geodeUDirArray->getDataPointer());
    else return;

    if (geodeVDirArray->getType() == Array::Vec3ArrayType)
        geodeVDirDataPtr = (Vec3*) (geodeVDirArray->getDataPointer());
    else return;

    if (geodeTexcoordArray->getType() == Array::Vec2ArrayType)
        geodeTexcoordDataPtr = (Vec2*) (geodeTexcoordArray->getDataPointer());
    else return;

    mNumVertices = geodeShapeRef->mNumVertices;
    for (int i = 0; i < mNumVertices; i++) mVertexArray->push_back(geodeVertexDataPtr[i]);

    mNumNormals = geodeShapeRef->mNumNormals;
    for (int i = 0; i < mNumNormals; i++)
    {
	mNormalArray->push_back(geodeNormalDataPtr[i]);
	mUDirArray->push_back(geodeUDirDataPtr[i]);
	mVDirArray->push_back(geodeVDirDataPtr[i]);
    }

    mNumTexcoords = geodeShapeRef->mNumTexcoords;
    for (int i = 0; i < mNumTexcoords; i++) mTexcoordArray->push_back(geodeTexcoordDataPtr[i]);

    /* make deep copy of 'CAVEGeometry' objects into this 'CAVEGeodeShape' */
    CAVEGeometryVector &geomVector = geodeShapeRef->getCAVEGeometryVector();
    const int nGeoms = geomVector.size();
    if (nGeoms > 0)
    {
	for (int i = 0; i < nGeoms; i++)
	{
	    CAVEGeometry *geometry = new CAVEGeometry(geomVector[i]);
	    geometry->setVertexArray(mVertexArray);
	    geometry->setNormalArray(mNormalArray);
	    geometry->setTexCoordArray(0, mTexcoordArray);
	    geometry->setNormalBinding(Geometry::BIND_PER_VERTEX);

	    mGeometryVector.push_back(geometry);
	    addDrawable(geometry);
	}
    }

    /* copy the same center vector from 'geodeShapeRef', vertex masking vector is with all false values */
    mCenterVect = geodeShapeRef->mCenterVect;
    mVertexMaskingVector.resize(mNumVertices, false);

    /* apply color texture to virtual surface */
    applyColorTexture(geodeShapeRef->mDiffuse, geodeShapeRef->mSpecular, geodeShapeRef->mAlpha,
			geodeShapeRef->mTexFilename);
}