예제 #1
0
//-------------------------------------------------------------------------------
// @ Player::CreatePlane()
//-------------------------------------------------------------------------------
// Create vertex arrays for a plane centered around the origin
//-------------------------------------------------------------------------------
void 
Player::CreatePlane()                                    
{
    mPlaneVerts = IvRenderer::mRenderer->GetResourceManager()->CreateVertexBuffer(
        kTCPFormat, 4, nullptr, kDefaultUsage);

    IvTCPVertex* tempVerts = (IvTCPVertex*)(mPlaneVerts->BeginLoadData());

    tempVerts->position = IvVector3(0.0f, -5.0f, -5.0f);
    tempVerts->texturecoord = IvVector2(1.0f, 0.0f);
    tempVerts->color.mAlpha = 
    tempVerts->color.mRed = 
    tempVerts->color.mGreen = 
    tempVerts->color.mBlue = 255; 

    tempVerts++;

    tempVerts->position = IvVector3(0.0f, -5.0f, 5.0f);
    tempVerts->texturecoord = IvVector2(1.0f, 1.0f);
    tempVerts->color.mAlpha = 
    tempVerts->color.mRed = 
    tempVerts->color.mGreen = 
    tempVerts->color.mBlue = 255; 

    tempVerts++;

    tempVerts->position = IvVector3(0.0f, 5.0f, -5.0f);
    tempVerts->texturecoord = IvVector2(0.0f, 0.0f);
    tempVerts->color.mAlpha = 
    tempVerts->color.mRed = 
    tempVerts->color.mGreen = 
    tempVerts->color.mBlue = 255; 

    tempVerts++;

    tempVerts->position = IvVector3(0.0f, 5.0f, 5.0f);
    tempVerts->texturecoord = IvVector2(0.0f, 1.0f);
    tempVerts->color.mAlpha = 
    tempVerts->color.mRed = 
    tempVerts->color.mGreen = 
    tempVerts->color.mBlue = 255; 

    mPlaneVerts->EndLoadData();

    mPlaneIndices = IvRenderer::mRenderer->GetResourceManager()->CreateIndexBuffer(4, nullptr, kDefaultUsage);

    unsigned int* tempIndices = (unsigned int*)mPlaneIndices->BeginLoadData();

    unsigned int i;
    for (i = 0; i < 4; i++)
        tempIndices[i] = i;

    mPlaneIndices->EndLoadData();

}   // End of Player::CreatePlane()
예제 #2
0
//-------------------------------------------------------------------------------
// @ Player::CreateCylinder()
//-------------------------------------------------------------------------------
// Create vertex arrays for a cylinder centered around the origin
//-------------------------------------------------------------------------------
void 
Player::CreateCylinder()                                    
{
    // Creates a grid of points, shaped into a cylinder.  In order to avoid a
    // texturing anomaly, we cannot simply share the vertical seam edge vertices
    // They must be duplicated; one copy must have a U-coord of 0.0, the other a
    // U-coord of 1.0f
    const unsigned int steps = 32;
    mCylinderVerts = IvRenderer::mRenderer->GetResourceManager()->CreateVertexBuffer(
        kTCPFormat, (steps + 1) * steps, nullptr, kDefaultUsage);

    IvTCPVertex* tempVerts0 = (IvTCPVertex*)(mCylinderVerts->BeginLoadData());

    // temporary pointers that can be stepped along the arrays
    const float phiIncrement = kPI / (steps - 1);
    const float thetaIncrement = kTwoPI / steps;
    unsigned int i,j;

    // A double loop, walking around and down the cylinder
    for (j = 0; j <= steps; j++)
    {
        float theta = thetaIncrement * j;
        float u = j / (float)steps;

        float sinTheta, cosTheta;
        IvSinCos(theta, sinTheta, cosTheta);

        for (i = 0; i < steps; i++)
        {
            float phi = -kHalfPI + phiIncrement * i;
            float v = i / (float)(steps - 1);

            if (i == 0)
            {
                tempVerts0->position = IvVector3(0.0f, 0.0f, -mRadius);
            }
            else if (i == (steps - 1))
            {
                tempVerts0->position = IvVector3(0.0f, 0.0f, mRadius);
            }
            else
            {
                tempVerts0->position = IvVector3(mRadius * cosTheta, mRadius * sinTheta, mRadius * IvSin(phi));
            }

            tempVerts0->texturecoord = IvVector2(u, v);

            tempVerts0->color.mAlpha = 
            tempVerts0->color.mRed = 
            tempVerts0->color.mGreen = 
            tempVerts0->color.mBlue = 255; 

            tempVerts0++;
        }
    }

    mCylinderVerts->EndLoadData();

    // Create index arrays - just a 32x31-quad mesh of triangles
    // Each of the 32 strips has 31 * 2 triangles plus two dummy indices
    // This means that there are 31 * 2 + 2 + 2 (two extra to start the
    // strip, and two extra to end the previous strip) indices in each
    // strip, although we can avoid two indices in the first strip, as
    // there is no previous strip to be ended in that case.  Thus,
    // 64 + 66 * 31 indices for the entire cylinder
    unsigned int cylinderIndexCount = steps * 2 + (steps - 1) * (steps * 2 + 2);

    mCylinderIndices = IvRenderer::mRenderer->GetResourceManager()->CreateIndexBuffer(
        cylinderIndexCount, nullptr, kDefaultUsage);

    UInt32* tempIndices = (UInt32*)mCylinderIndices->BeginLoadData();

    for (j = 0; j < steps; j++)
    {
        UInt32 baseIndex0 = steps * j;
        UInt32 baseIndex1 = steps * (j + 1);

        // restart the strip by doubling the last and next indices
        if (j != 0)
        {
            *(tempIndices++) = tempIndices[-1];
            *(tempIndices++) = baseIndex0;
        }

        unsigned int i;
        for (i = 0; i < steps; i++)
        {
            *(tempIndices++) = baseIndex0;
            *(tempIndices++) = baseIndex1;

            baseIndex0++;
            baseIndex1++;
        }
    }

    mCylinderIndices->EndLoadData();

}   // End of Player::CreateCylinder()