//----------------------------------------------------------------------------
bool SEWindowApplication3::OnInitialize()
{
    if( !SEWindowApplication::OnInitialize() )
    {
        return false;
    }

    m_spCamera = SE_NEW SECamera;
    m_pRenderer->SetCamera(m_spCamera);
    m_spMotionObject = 0;

    SEAttributes tempAttr;
    tempAttr.SetPositionChannels(3);
    tempAttr.SetColorChannels(0, 3);
    SEVertexBuffer* pVBuffer = SE_NEW SEVertexBuffer(tempAttr, 6);
    (*(SEVector3f*)pVBuffer->PositionTuple(0)) = m_Origin;
    (*(SEColorRGB*)pVBuffer->ColorTuple(0, 0)) = SEColorRGB::SE_RGB_RED;
    (*(SEVector3f*)pVBuffer->PositionTuple(1)) = m_XEnd;
    (*(SEColorRGB*)pVBuffer->ColorTuple(0, 1)) = SEColorRGB::SE_RGB_RED;
    (*(SEVector3f*)pVBuffer->PositionTuple(2)) = m_Origin;
    (*(SEColorRGB*)pVBuffer->ColorTuple(0, 2)) = SEColorRGB::SE_RGB_GREEN;  
    (*(SEVector3f*)pVBuffer->PositionTuple(3)) = m_YEnd;
    (*(SEColorRGB*)pVBuffer->ColorTuple(0, 3)) = SEColorRGB::SE_RGB_GREEN;
    (*(SEVector3f*)pVBuffer->PositionTuple(4)) = m_Origin;
    (*(SEColorRGB*)pVBuffer->ColorTuple(0, 4)) = SEColorRGB::SE_RGB_BLUE;
    (*(SEVector3f*)pVBuffer->PositionTuple(5)) = m_ZEnd;
    (*(SEColorRGB*)pVBuffer->ColorTuple(0, 5)) = SEColorRGB::SE_RGB_BLUE;
    m_spWorldAxis = SE_NEW SEPolyline(pVBuffer, false, false);

    SEVertexColor3Effect* pEffect = SE_NEW SEVertexColor3Effect;
    m_spWorldAxis->AttachEffect(pEffect);

    return true;
}
Example #2
0
//----------------------------------------------------------------------------
SENode* SEWidget::AABBFrame(const SEVector3f& rMin, const SEVector3f& rMax, 
    const SEColorRGB& rColor)
{
    SENode* pNode = SE_NEW SENode;

    SEAttributes tempAttr;
    tempAttr.SetPositionChannels(3);
    tempAttr.SetColorChannels(0, 3);

    SEVector3f vec3fV0(rMin);
    SEVector3f vec3fV1(rMin.X, rMin.Y, rMax.Z);
    SEVector3f vec3fV2(rMax.X, rMin.Y, rMax.Z);
    SEVector3f vec3fV3(rMax.X, rMin.Y, rMin.Z);
    SEVector3f vec3fV4(rMax.X, rMax.Y, rMin.Z);
    SEVector3f vec3fV5(rMin.X, rMax.Y, rMin.Z);
    SEVector3f vec3fV6(rMin.X, rMax.Y, rMax.Z);
    SEVector3f vec3fV7(rMax);

    // AABBFrame has 12 edges, 24 ending points.
    SEVertexBuffer* pVBuffer = SE_NEW SEVertexBuffer(tempAttr, 24);
    pVBuffer->Position3(0 ) = vec3fV0;
    pVBuffer->Position3(1 ) = vec3fV1;
    pVBuffer->Position3(2 ) = vec3fV1;
    pVBuffer->Position3(3 ) = vec3fV2;
    pVBuffer->Position3(4 ) = vec3fV2;
    pVBuffer->Position3(5 ) = vec3fV3;
    pVBuffer->Position3(6 ) = vec3fV3;
    pVBuffer->Position3(7 ) = vec3fV0;
    pVBuffer->Position3(8 ) = vec3fV5;
    pVBuffer->Position3(9 ) = vec3fV6;
    pVBuffer->Position3(10) = vec3fV6;
    pVBuffer->Position3(11) = vec3fV7;
    pVBuffer->Position3(12) = vec3fV7;
    pVBuffer->Position3(13) = vec3fV4;
    pVBuffer->Position3(14) = vec3fV4;
    pVBuffer->Position3(15) = vec3fV5;
    pVBuffer->Position3(16) = vec3fV0;
    pVBuffer->Position3(17) = vec3fV5;
    pVBuffer->Position3(18) = vec3fV1;
    pVBuffer->Position3(19) = vec3fV6;
    pVBuffer->Position3(20) = vec3fV2;
    pVBuffer->Position3(21) = vec3fV7;
    pVBuffer->Position3(22) = vec3fV3;
    pVBuffer->Position3(23) = vec3fV4;
    for( int i = 0; i < 24; i++ )
    {
        pVBuffer->Color3(0, i) = rColor;
    }
    SEPolyline* pAABBFrame = SE_NEW SEPolyline(pVBuffer, false, false);
    pAABBFrame->SetName("AABBFrame");

    SEVertexColor3Effect* pEffect = SE_NEW SEVertexColor3Effect;
    pAABBFrame->AttachEffect(pEffect);

    pNode->AttachChild(pAABBFrame);
    pNode->UpdateGS();

    return pNode;
}
Example #3
0
//----------------------------------------------------------------------------
void DynamicShader::CreateScene()
{
    m_spScene = SE_NEW SENode;
    m_spWireframe = SE_NEW SEWireframeState;
    m_spScene->AttachGlobalState(m_spWireframe);

    // 创建一个场景中的矩形.
    SEAttributes tempAttr;
    tempAttr.SetPositionChannels(3);
    tempAttr.SetTCoordChannels(0, 2);

    SEVertexBuffer* pVBuffer = SE_NEW SEVertexBuffer(tempAttr, 4);
    (*(SEVector3f*)pVBuffer->PositionTuple(0)).X = -1.0f;
    (*(SEVector3f*)pVBuffer->PositionTuple(0)).Y = -1.0f;
    (*(SEVector3f*)pVBuffer->PositionTuple(0)).Z = 0.0f;
    (*(SEVector2f*)pVBuffer->TCoordTuple(0, 0)).X = 0.0f;
    (*(SEVector2f*)pVBuffer->TCoordTuple(0, 0)).Y = 1.0f;
    (*(SEVector3f*)pVBuffer->PositionTuple(1)).X = 1.0f;
    (*(SEVector3f*)pVBuffer->PositionTuple(1)).Y = -1.0f;
    (*(SEVector3f*)pVBuffer->PositionTuple(1)).Z = 0.0f;
    (*(SEVector2f*)pVBuffer->TCoordTuple(0, 1)).X = 1.0f;
    (*(SEVector2f*)pVBuffer->TCoordTuple(0, 1)).Y = 1.0f;
    (*(SEVector3f*)pVBuffer->PositionTuple(2)).X = 1.0f;
    (*(SEVector3f*)pVBuffer->PositionTuple(2)).Y = 1.0f;
    (*(SEVector3f*)pVBuffer->PositionTuple(2)).Z = 0.0f;
    (*(SEVector2f*)pVBuffer->TCoordTuple(0, 2)).X = 1.0f;
    (*(SEVector2f*)pVBuffer->TCoordTuple(0, 2)).Y = 0.0f;
    (*(SEVector3f*)pVBuffer->PositionTuple(3)).X = -1.0f;
    (*(SEVector3f*)pVBuffer->PositionTuple(3)).Y = 1.0f;
    (*(SEVector3f*)pVBuffer->PositionTuple(3)).Z = 0.0f;
    (*(SEVector2f*)pVBuffer->TCoordTuple(0, 3)).X = 0.0f;
    (*(SEVector2f*)pVBuffer->TCoordTuple(0, 3)).Y = 0.0f;
    SEIndexBuffer* pIBuffer = SE_NEW SEIndexBuffer(6);
    int* pIBufferData = pIBuffer->GetData();
    pIBufferData[0] = 0;
    pIBufferData[1] = 3;
    pIBufferData[2] = 1;
    pIBufferData[3] = 1;
    pIBufferData[4] = 3;
    pIBufferData[5] = 2;

    m_spMesh = SE_NEW SETriMesh(pVBuffer, pIBuffer);
    m_spScene->AttachChild(m_spMesh);

    m_spEffect = SE_NEW DynamicMultiTextureEffect(1);
    m_spMesh->AttachEffect(m_spEffect);
    m_spEffect->SetImageName(0, m_ImageNames[0]);
    m_spEffect->SetTextureTypeName(0, "ImageTexture");
    m_spEffect->Configure();

    ConstantColorController* pController = SE_NEW ConstantColorController;
    m_spEffect->AttachController(pController);
    m_spController = pController;
    pController->Frequency = 5.0;
    pController->MinTime = 0.0;
    pController->MaxTime = 4.0;
    pController->Repeat = SEController::RT_CYCLE;
}
Example #4
0
//----------------------------------------------------------------------------
void Lighting::CreateLights()
{
    // Create light0(point light).
    m_spLight0 = SE_NEW SELight(SELight::LT_POINT);
    m_spLight0->Ambient = m_Light0Color*0.5f;
    m_spLight0->Diffuse = m_Light0Color;
    m_spLight0->Specular = m_Light0Color*0.5f;
    m_spLight0->Linear = 0.02f;
    m_spLight0->Quadratic = 0.02f;

    // Create light0's node.
    m_spLight0Node = SE_NEW SELightNode(m_spLight0);
    m_spLight0Node->Local.SetTranslate(SEVector3f(0.0f, m_fLight0Height, 
        0.0f));

    // Create a sphere to represent the light0's source.
    SEAttributes tempAttr;
    tempAttr.SetPositionChannels(3);
    tempAttr.SetColorChannels(0, 3);
    float fRadius = 0.2f;
    SETriMesh* pPLightSphere = SEStandardMesh(tempAttr).Sphere(8, 8, fRadius);
    m_spLight0Node->AttachChild(pPLightSphere);
    SEVertexBuffer* pVBuffer = pPLightSphere->VBuffer;
    int iVCount = pVBuffer->GetVertexCount();
    for( int i = 0; i < iVCount; i++ )
    {
        pVBuffer->Color3(0, i) = m_Light0Color;
    }
    SEVertexColor3Effect* pLightSphereEffect = SE_NEW SEVertexColor3Effect;
    pPLightSphere->AttachEffect(pLightSphereEffect);

    // Create light1(point light).
    m_spLight1 = SE_NEW SELight(SELight::LT_POINT);
    m_spLight1->Ambient = m_Light1Color*0.5f;
    m_spLight1->Diffuse = m_Light1Color;
    m_spLight1->Specular = m_Light1Color*0.5f;
    m_spLight1->Linear = 0.02f;
    m_spLight1->Quadratic = 0.02f;

    // Create light1's node.
    m_spLight1Node = SE_NEW SELightNode(m_spLight1);
    m_spLight1Node->Local.SetTranslate(SEVector3f(0.0f, m_fLight1Height, 
        0.0f));

    // Create a sphere to represent the light1's source.
    pPLightSphere = SEStandardMesh(tempAttr).Sphere(8, 8, fRadius);
    m_spLight1Node->AttachChild(pPLightSphere);
    pVBuffer = pPLightSphere->VBuffer;
    iVCount = pVBuffer->GetVertexCount();
    for( int i = 0; i < iVCount; i++ )
    {
        pVBuffer->Color3(0, i) = m_Light1Color;
    }
    pPLightSphere->AttachEffect(pLightSphereEffect);
}
Example #5
0
//----------------------------------------------------------------------------
void DefaultShader::CreateScene()
{
    m_spScene = SE_NEW SENode;
	
    SEAttributes tempAttr;
    tempAttr.SetPositionChannels(3);
    SEStandardMesh tempSM(tempAttr);
    m_spMesh = tempSM.Box(1.0f, 1.0f, 1.0f);
    m_spScene->AttachChild(m_spMesh);
	
    SEDefaultShaderEffect* pEffect = SE_NEW SEDefaultShaderEffect;
    m_spMesh->AttachEffect(pEffect);
}
Example #6
0
//----------------------------------------------------------------------------
void HelloiPhone::CreateScene()
{
    // 创建纹理资源.
    SEImage* pImage = SEImageCatalog::GetActive()->Find("rock");
    SETexture* pTextureDiffuse = SE_NEW SETexture(pImage);

    pImage = SEImageCatalog::GetActive()->Find("kate");
    SETexture* pTextureGirl = SE_NEW SETexture(pImage);

    m_spScene = SE_NEW SENode;

    // 创建一个box.
    SEAttributes tempAttr;
    tempAttr.SetPositionChannels(3);
	tempAttr.SetNormalChannels(3);
    //tempAttr.SetColorChannels(0, 3);
    tempAttr.SetTCoordChannels(0, 2);
    tempAttr.SetTCoordChannels(1, 2);
    SEStandardMesh tempSM(tempAttr);
    m_spMesh = tempSM.Box(1.0f, 1.0f, 1.0f);
//    m_spMesh->VBuffer->ColorTuple(0, 0)[0] = 0.0f;
//    m_spMesh->VBuffer->ColorTuple(0, 0)[1] = 0.0f;
//    m_spMesh->VBuffer->ColorTuple(0, 0)[2] = 0.0f;
//    m_spMesh->VBuffer->ColorTuple(0, 1)[0] = 0.0f;
//    m_spMesh->VBuffer->ColorTuple(0, 1)[1] = 0.0f;
//    m_spMesh->VBuffer->ColorTuple(0, 1)[2] = 1.0f;
//    m_spMesh->VBuffer->ColorTuple(0, 2)[0] = 0.0f;
//    m_spMesh->VBuffer->ColorTuple(0, 2)[1] = 1.0f;
//    m_spMesh->VBuffer->ColorTuple(0, 2)[2] = 0.0f;
//    m_spMesh->VBuffer->ColorTuple(0, 3)[0] = 0.0f;
//    m_spMesh->VBuffer->ColorTuple(0, 3)[1] = 1.0f;
//    m_spMesh->VBuffer->ColorTuple(0, 3)[2] = 1.0f;
//    m_spMesh->VBuffer->ColorTuple(0, 4)[0] = 1.0f;
//    m_spMesh->VBuffer->ColorTuple(0, 4)[1] = 0.0f;
//    m_spMesh->VBuffer->ColorTuple(0, 4)[2] = 0.0f;
//    m_spMesh->VBuffer->ColorTuple(0, 5)[0] = 1.0f;
//    m_spMesh->VBuffer->ColorTuple(0, 5)[1] = 0.0f;
//    m_spMesh->VBuffer->ColorTuple(0, 5)[2] = 1.0f;
//    m_spMesh->VBuffer->ColorTuple(0, 6)[0] = 1.0f;
//    m_spMesh->VBuffer->ColorTuple(0, 6)[1] = 1.0f;
//    m_spMesh->VBuffer->ColorTuple(0, 6)[2] = 0.0f;
//    m_spMesh->VBuffer->ColorTuple(0, 7)[0] = 1.0f;
//    m_spMesh->VBuffer->ColorTuple(0, 7)[1] = 1.0f;
//    m_spMesh->VBuffer->ColorTuple(0, 7)[2] = 1.0f;

    SEOGLES1FixedEffect* pEffect = SE_NEW SEOGLES1FixedEffect(2, 0);
    pEffect->SetTexture(0, pTextureDiffuse);
    pEffect->SetTexture(1, pTextureGirl);
    m_spMesh->AttachEffect(pEffect);
    m_spScene->AttachChild(m_spMesh);
}
Example #7
0
//----------------------------------------------------------------------------
SEParticles::SEParticles(const SEAttributes& rAttr, SEVector3fArray* 
    pLocations, SEFloatArray* pSizes)
    :
    Locations(pLocations),
    Sizes(pSizes)
{
    // 分配模型空间顶点存储,每个粒子使用4个顶点构成一个quad广告牌.
    int iLCount = Locations->GetCount();
    int iVCount = 4*iLCount;
    VBuffer = SE_NEW SEVertexBuffer(rAttr, iVCount);

    // 为这些quad广告牌设置2D纹理坐标.
    int i, j;
    for( int iUnit = 0; iUnit < rAttr.GetMaxTCoords(); iUnit++ )
    {
        if( rAttr.HasTCoord(iUnit) && rAttr.GetTCoordChannels(iUnit) == 2 )
        {
            for( i = 0, j = 0; i < iLCount; i++ )
            {
                VBuffer->TCoord2(iUnit, j++) = SEVector2f(0.0f, 1.0f);
                VBuffer->TCoord2(iUnit, j++) = SEVector2f(0.0f, 0.0f);
                VBuffer->TCoord2(iUnit, j++) = SEVector2f(1.0f, 0.0f);
                VBuffer->TCoord2(iUnit, j++) = SEVector2f(1.0f, 1.0f);
            }
        }
    }

    // 为这些quad广告牌创建IB.
    int iICount = 6*iLCount;
    IBuffer = SE_NEW SEIndexBuffer(iICount);
    int* aiIndex = IBuffer->GetData();
    for( i = 0, j = 0; i < iLCount; i++ )
    {
        int iFI = 4*i, iFIp1 = iFI+1, iFIp2 = iFI+2, iFIp3 = iFI+3;
        aiIndex[j++] = iFI;
        aiIndex[j++] = iFIp1;
        aiIndex[j++] = iFIp3;
        aiIndex[j++] = iFIp1;
        aiIndex[j++] = iFIp2;
        aiIndex[j++] = iFIp3;
    }

    // 根据全部粒子的模型空间位置计算出一个包含这些位置的BV.
    ModelBound->ComputeFromData(Locations);

    SizeAdjust = 1.0f;
    m_iActiveCount = iLCount;
}
Example #8
0
//----------------------------------------------------------------------------
void DefaultShader::CreateScene()
{
    m_spScene = SE_NEW SENode;
    m_spWireframe = SE_NEW SEWireframeState;
    m_spScene->AttachGlobalState(m_spWireframe);

    SEAttributes tempAttr;
    tempAttr.SetPositionChannels(3);
    SEStandardMesh tempSM(tempAttr);
    float fExt = 1.0f;
    m_spMesh = tempSM.Box(fExt, fExt, fExt);
    m_spScene->AttachChild(m_spMesh);

    SEDefaultShaderEffect* pEffect = SE_NEW SEDefaultShaderEffect;
    m_spMesh->AttachEffect(pEffect);
}
//----------------------------------------------------------------------------
void ImageExporterApp::CreateScene()
{
    m_spScene = SE_NEW SENode;
    m_spWireframe = SE_NEW SEWireframeState;
    m_spWireframe->Enabled = false;
    m_spScene->AttachGlobalState(m_spWireframe);

	// 创建用于显示纹理图的矩形.
    SEAttributes tempAttr;
    tempAttr.SetPositionChannels(3);
    tempAttr.SetTCoordChannels(0, 2);
	SEVertexBuffer* pVB = SE_NEW SEVertexBuffer(tempAttr, 4);
	pVB->Position3(0) = SEVector3f(-1, 1, 0);
	pVB->Position3(1) = SEVector3f(1, 1, 0);
	pVB->Position3(2) = SEVector3f(1, -1, 0);
	pVB->Position3(3) = SEVector3f(-1, -1, 0);
	pVB->TCoord2(0, 0) = SEVector2f(0, 0);
	pVB->TCoord2(0, 1) = SEVector2f(1, 0);
	pVB->TCoord2(0, 2) = SEVector2f(1, 1);
	pVB->TCoord2(0, 3) = SEVector2f(0, 1);
	SEIndexBuffer* pIB = SE_NEW SEIndexBuffer(6);
	int* pIBData = pIB->GetData();
	*(pIBData    ) = 0;
	*(pIBData + 1) = 2;
	*(pIBData + 2) = 3;
	*(pIBData + 3) = 0;
	*(pIBData + 4) = 1;
	*(pIBData + 5) = 2;

	m_spMesh = SE_NEW SETriMesh(pVB, pIB);
	m_spScene->AttachChild(m_spMesh);

    m_spScene->UpdateGS();
    m_spScene->UpdateRS();

    m_Culler.SetCamera(m_spCamera);
    m_Culler.ComputeUnculledSet(m_spScene);
}
Example #10
0
//----------------------------------------------------------------------------
void Lighting::CreateModels()
{
    // polished gold.
    SEMaterialState* pGoldMaterial = SE_NEW SEMaterialState;
    pGoldMaterial->Ambient = SEColorRGB(0.24725f, 0.2245f, 0.0645f);
    pGoldMaterial->Diffuse = SEColorRGB(0.34615f, 0.3143f, 0.0903f);
    pGoldMaterial->Specular = SEColorRGB(0.797357f, 0.723991f, 0.208006f);
    pGoldMaterial->Shininess = 83.2f;

    // polished red.
    SEMaterialState* pRedMaterial = SE_NEW SEMaterialState;
    pRedMaterial->Ambient = SEColorRGB(0.8f, 0.0f, 0.0f);
    pRedMaterial->Diffuse = SEColorRGB(0.8f, 0.0f, 0.0f);
    pRedMaterial->Specular = SEColorRGB(1.0f, 1.0f, 1.0f);
    pRedMaterial->Shininess = 83.2f;

    // polished blue.
    SEMaterialState* pBlueMaterial = SE_NEW SEMaterialState;
    pBlueMaterial->Ambient = SEColorRGB(0.0f, 0.0f, 0.2f);
    pBlueMaterial->Diffuse = SEColorRGB(0.0f, 0.0f, 0.8f);
    pBlueMaterial->Specular = SEColorRGB(1.0f, 1.0f, 1.0f);
    pBlueMaterial->Shininess = 83.2f;

    // polished white.
    SEMaterialState* pWhiteMaterial = SE_NEW SEMaterialState;
    pWhiteMaterial->Ambient = SEColorRGB(0.2f, 0.2f, 0.2f);
    pWhiteMaterial->Diffuse = SEColorRGB(0.8f, 0.8f, 0.8f);
    pWhiteMaterial->Specular = SEColorRGB(1.0f, 1.0f, 1.0f);
    pWhiteMaterial->Shininess = 50.0f;

    // polished copper.
    SEMaterialState* pCopperMaterial = SE_NEW SEMaterialState;
    pCopperMaterial->Ambient = SEColorRGB(0.2295f, 0.08825f, 0.0275f);
    pCopperMaterial->Diffuse = SEColorRGB(0.5508f, 0.2118f, 0.066f);
    pCopperMaterial->Specular = SEColorRGB(0.580594f, 0.223257f, 0.0695701f);
    pCopperMaterial->Shininess = 51.2f;

    // We apply these texture effects as post-lighting effects,
    // so the src output fragments should be modulated with dst buffer pixels.
    SETextureEffect* pTextureRockEffect = SE_NEW SETextureEffect("rock");
    SEAlphaState* pAState = pTextureRockEffect->GetBlending(0);
    pAState->SrcBlend = SEAlphaState::SBF_DST_COLOR;
    pAState->DstBlend = SEAlphaState::DBF_ZERO;

    SETextureEffect* pTextureWoodEffect = SE_NEW SETextureEffect("wood512");
    pAState = pTextureWoodEffect->GetBlending(0);
    pAState->SrcBlend = SEAlphaState::SBF_DST_COLOR;
    pAState->DstBlend = SEAlphaState::DBF_ZERO;

    SENode* pRoot = SE_NEW SENode;

    SEAttributes tempAttr;
    tempAttr.SetPositionChannels(3);
    tempAttr.SetNormalChannels(3);
    tempAttr.SetTCoordChannels(0, 2);

#if defined(SE_USING_OES2)
    SEGeometry::GeometryLightingMode eLMode = SEGeometry::GLM_PIPELINE_VERTEX;
#else
    SEGeometry::GeometryLightingMode eLMode = SEGeometry::GLM_PIPELINE_PIXEL;
#endif

    float fExtend = 8.0f;
    SEStandardMesh tempSM(tempAttr);
    // floor.
    SETriMesh* pMesh = tempSM.Rectangle(4, 4, fExtend, fExtend);
    pMesh->LightingMode = eLMode;
    pMesh->AttachGlobalState(pWhiteMaterial);
    pMesh->AttachEffect(pTextureWoodEffect);
    pMesh->GenerateNormals();
    SEMatrix3f mat3fRot;
    mat3fRot.FromEulerAnglesXYZ(SEMathf::PI/2.0f, 0.0f, 0.0f);
    pMesh->Local.SetRotate(mat3fRot);
    pRoot->AttachChild(pMesh);

    // far wall.
    pMesh = SE_NEW SETriMesh(pMesh->VBuffer, pMesh->IBuffer);
    pMesh->LightingMode = eLMode;
    pMesh->AttachGlobalState(pWhiteMaterial);
    pMesh->AttachEffect(pTextureRockEffect);
    pMesh->GenerateNormals();
    pMesh->Local.SetTranslate(SEVector3f(0.0f, fExtend, fExtend));
    pRoot->AttachChild(pMesh);

    // left wall.
    pMesh = SE_NEW SETriMesh(pMesh->VBuffer, pMesh->IBuffer);
    pMesh->LightingMode = eLMode;
    pMesh->AttachGlobalState(pWhiteMaterial);
    pMesh->AttachEffect(pTextureRockEffect);
    pMesh->GenerateNormals();
    mat3fRot.FromEulerAnglesXYZ(0.0f, -SEMathf::PI/2.0f, 0.0f);
    pMesh->Local.SetRotate(mat3fRot);
    pMesh->Local.SetTranslate(SEVector3f(-fExtend, fExtend, 0.0f));
    pRoot->AttachChild(pMesh);

    // right wall.
    pMesh = SE_NEW SETriMesh(pMesh->VBuffer, pMesh->IBuffer);
    pMesh->LightingMode = eLMode;
    pMesh->AttachGlobalState(pWhiteMaterial);
    pMesh->AttachEffect(pTextureRockEffect);
    pMesh->GenerateNormals();
    mat3fRot.FromEulerAnglesXYZ(0.0f, SEMathf::PI/2.0f, 0.0f);
    pMesh->Local.SetRotate(mat3fRot);
    pMesh->Local.SetTranslate(SEVector3f(fExtend, fExtend, 0.0f));
    pRoot->AttachChild(pMesh);

    // sphere.
    pMesh = tempSM.Sphere(32, 32, 1.0f);
    pMesh->LightingMode = eLMode;
    pMesh->AttachGlobalState(pGoldMaterial);
    pMesh->GenerateNormals();
    pMesh->Local.SetTranslate(SEVector3f(0.0f, 1.0f, 0.0f));
    pRoot->AttachChild(pMesh);

    // cylinder.
    pMesh = tempSM.Cylinder(8, 32, 1.0f, 2.0f, false);
    pMesh->LightingMode = eLMode;
    pMesh->AttachGlobalState(pRedMaterial);
    pMesh->GenerateNormals();
    mat3fRot.FromEulerAnglesXYZ(SEMathf::PI/2.0f, 0.0f, 0.0f);
    pMesh->Local.SetRotate(mat3fRot);
    pMesh->Local.SetTranslate(SEVector3f(2.0f, 1.0f, 1.0f));
    pRoot->AttachChild(pMesh);

    // box.
    pMesh = tempSM.Box(0.6f, 0.6f, 0.6f);
    pMesh->LightingMode = eLMode;
    pMesh->AttachGlobalState(pBlueMaterial);
    pMesh->GenerateNormals();
    mat3fRot.FromEulerAnglesXYZ(0.0f, SEMathf::PI/3.0f, 0.0f);
    pMesh->Local.SetRotate(mat3fRot);
    pMesh->Local.SetTranslate(SEVector3f(-1.6f, 0.6f, -1.0f));
    pRoot->AttachChild(pMesh);

    // torus.
    pMesh = tempSM.Torus(32, 32, 1.0f, 0.2f);
    pMesh->LightingMode = eLMode;
    pMesh->AttachGlobalState(pCopperMaterial);
    pMesh->GenerateNormals();
    mat3fRot.FromEulerAnglesXYZ(SEMathf::PI/2.0f, 0.0f, 0.0f);
    pMesh->Local.SetRotate(mat3fRot);
    pMesh->Local.SetTranslate(SEVector3f(0.0f, 0.2f, 0.0f));
    pRoot->AttachChild(pMesh);

    // tetrahedron.
    pMesh = tempSM.Tetrahedron();
    pMesh->LightingMode = eLMode;
    pMesh->AttachGlobalState(pWhiteMaterial);
    pMesh->GenerateNormals();
    mat3fRot.FromEulerAnglesXYZ(-SEMathf::PI/2.0f, 0.0f, 0.0f);
    pMesh->Local.SetRotate(mat3fRot);
    pMesh->Local.SetTranslate(SEVector3f(1.8f, 1.0f/3.0f, -0.8f));
    pRoot->AttachChild(pMesh);

    m_spModelRoot = pRoot;
}
//----------------------------------------------------------------------------
SETriMesh* SEColladaUnimaterialMesh::ToTriMesh()
{
    // 创建所需Swing Engine VB.
    SEAttributes tempSEAttr;
    tempSEAttr.SetPositionChannels(3);
    if( m_aNormal )
    {
        tempSEAttr.SetNormalChannels(3);
    }
    if( m_aColor )
    {
        tempSEAttr.SetColorChannels(0, 3);
    }
    if( m_aTexture )
    {
        tempSEAttr.SetTCoordChannels(0, 2);
    }

    SEVertexBuffer* pSEVBuffer = SE_NEW SEVertexBuffer(tempSEAttr, m_iVCount);
    for( int i = 0; i < m_iVCount; i++ )
    {
        (*(SEVector3f*)pSEVBuffer->PositionTuple(i)) = m_aVertex[i];

        if( m_aNormal )
        {
            *(SEVector3f*)pSEVBuffer->NormalTuple(i) = m_aNormal[i];
        }
        if( m_aColor )
        {
            *(SEColorRGB*)pSEVBuffer->ColorTuple(0, i) = m_aColor[i];
        }
        if( m_aTexture )
        {
            *(SEVector2f*)pSEVBuffer->TCoordTuple(0, i) = m_aTexture[i];
        }
    }

    // 创建所需Swing Engine IB.
    SEIndexBuffer* pSEIBuffer = SE_NEW SEIndexBuffer(3 * m_iFCount);
    int* pSEIBufferData = pSEIBuffer->GetData();
    memcpy(pSEIBufferData, m_aiFace, 3*m_iFCount*sizeof(int));

    SETriMesh* pSEMesh = SE_NEW SETriMesh(pSEVBuffer, pSEIBuffer);

    SEEffect* pSEEffect = 0;

    // 根据Swing Engine网格所带材质和纹理,为其添加effect.
    // 目前导出器支持的材质和纹理effect是:
    // SEMaterialEffect,SEMaterialTextureEffect,SEDefaultShaderEffect.

    if( m_spSEMaterialState )
    {
        pSEMesh->AttachGlobalState(m_spSEMaterialState);

        if( m_spTState )
        {
            // 待实现.
            // 当拆分网格后如何处理多重纹理?
            SEImage* pImage = m_spTState->GetImage();
            SE_ASSERT( pImage );
            if( pImage )
            {
                std::string tempFName = pImage->GetName();
                // 减去".seif"长度.
                size_t uiLength = strlen(tempFName.c_str()) - 5;
                char tempBuffer[64];
                SESystem::SE_Strncpy(tempBuffer, 64, tempFName.c_str(), 
                    uiLength);
                tempBuffer[uiLength] = 0;
                pSEEffect = SE_NEW SEMaterialTextureEffect(tempBuffer);
            }
        }
        else
        {
            pSEEffect = SE_NEW SEDefaultShaderEffect;

            if( m_aTexture )
            {
                SE_DELETE[] m_aTexture;
            }
        }
    }

    // 理论上不可能出现这种情况.
    if( !m_spSEMaterialState && m_spTState )
    {
        SE_ASSERT( false );
    }

    if( !m_spSEMaterialState && !m_spTState )
    {
        pSEEffect = SE_NEW SEDefaultShaderEffect;
    }

    if( pSEEffect )
    {
        pSEMesh->AttachEffect(pSEEffect);
    }

    return pSEMesh;
}
Example #12
0
//----------------------------------------------------------------------------
void SEVertexBuffer::BuildCompatibleArray(const SEAttributes& rIAttributes,
    bool bPackARGB, int& rChannels, float*& rCompatible) const
{
    // 注意这里使用unsigned int来存储数据,
    // 从而允许同时存储float和32位ARGB格式的unsigned int数据,
    // 把float指针显示类型转换为unsigned int指针然后取*操作没有任何问题,
    // 但反过来把unsigned int指针显示类型转换为float指针并取*操作,
    // 则取出的数据可能为非法浮点数据,
    // 因此如果使用std::vector<float>将可能存在数据非正常转换的问题
    std::vector<unsigned int> tempCompatible;    
    const unsigned int* puiData;
    float fOne = 1.0f;
    unsigned int* puiOne = (unsigned int*)&fOne;
    int iUnit, iIChannels, iVBChannels;

    for( int i = 0, j; i < m_iVertexCount; i++ )
    {
        // 填充顶点
        if( rIAttributes.HasPosition() )
        {
            iIChannels = rIAttributes.GetPositionChannels();
            iVBChannels = m_Attributes.GetPositionChannels();
            puiData = (unsigned int*)PositionTuple(i);
            if( iVBChannels < iIChannels )
            {
                for( j = 0; j < iVBChannels; j++ )
                {
                    tempCompatible.push_back(*puiData++);
                }
                for( j = iVBChannels; j < iIChannels; j++ )
                {
                    // 将w分量填充为1.0,从而成为齐次空间顶点
                    tempCompatible.push_back(*puiOne);
                }
            }
            else
            {
                for( j = 0; j < iIChannels; j++ )
                {
                    tempCompatible.push_back(*puiData++);
                }
            }
        }

        // 填充法线
        if( rIAttributes.HasNormal() )
        {
            iIChannels = rIAttributes.GetNormalChannels();
            iVBChannels = m_Attributes.GetNormalChannels();
            puiData = (unsigned int*)NormalTuple(i);
            if( iVBChannels < iIChannels )
            {
                for( j = 0; j < iVBChannels; j++ )
                {
                    tempCompatible.push_back(*puiData++);
                }
                for( j = iVBChannels; j < iIChannels; j++ )
                {
                    // 将w分量填充为0.0,从而成为齐次空间向量
                    tempCompatible.push_back(0);
                }
            }
            else
            {
                for( j = 0; j < iIChannels; j++ )
                {
                    tempCompatible.push_back(*puiData++);
                }
            }
        }

        // 填充若干组颜色
        for( iUnit = 0; iUnit < (int)rIAttributes.GetMaxColors(); iUnit++ )
        {
            if( rIAttributes.HasColor(iUnit) )
            {
                unsigned int auiColor[4], uiPackColor, uiValue;
                float fValue;

                iIChannels = rIAttributes.GetColorChannels(iUnit);
                iVBChannels = m_Attributes.GetColorChannels(iUnit);
                puiData = (unsigned int*)ColorTuple(iUnit, i);
                if( iVBChannels < iIChannels )
                {
                    for( j = 0; j < iVBChannels; j++ )
                    {
                        tempCompatible.push_back(*puiData++);
                    }
                    for( j = iVBChannels; j < iIChannels; j++ )
                    {
                        // 将a分量填充为1.0,成为不透明颜色
                        tempCompatible.push_back(*puiOne);
                    }
                    if( bPackARGB )
                    {
                        for( j = iIChannels; j < 4; j++ )
                        {
                            // 将a分量填充为1.0,成为不透明颜色
                            tempCompatible.push_back(*puiOne);
                        }

                        // 从[0.0f, 1.0f]映射到[0,255]
                        for( j = 3; j >= 0; j-- )
                        {
                            uiValue = tempCompatible.back();
                            fValue = *(float*)&uiValue;
                            auiColor[j] = (unsigned int)(255.0f * fValue);
                            tempCompatible.pop_back();
                        }

                        uiPackColor =
                            (auiColor[2]      ) |  // blue
                            (auiColor[1] <<  8) |  // green
                            (auiColor[0] << 16) |  // red
                            (auiColor[3] << 24);   // alpha

                        tempCompatible.push_back(uiPackColor);
                    }
                }
                else
                {
                    for( j = 0; j < iIChannels; j++ )
                    {
                        tempCompatible.push_back(*puiData++);
                    }
                    if( bPackARGB )
                    {
                        for( j = iIChannels; j < 4; j++ )
                        {
                            // 将a分量填充为1.0,成为不透明颜色
                            tempCompatible.push_back(*puiOne);
                        }

                        // 从[0.0f, 1.0f]映射到[0,255]
                        for( j = 3; j >= 0; j-- )
                        {
                            uiValue = tempCompatible.back();
                            fValue = *(float*)&uiValue;
                            auiColor[j] = (unsigned int)(255.0f * fValue);
                            tempCompatible.pop_back();
                        }

                        uiPackColor =
                            (auiColor[2]      ) |  // blue
                            (auiColor[1] <<  8) |  // green
                            (auiColor[0] << 16) |  // red
                            (auiColor[3] << 24);   // alpha

                        tempCompatible.push_back(uiPackColor);
                    }
                }
            }
        }

        // 填充若干组纹理坐标
        for( iUnit = 0; iUnit < (int)rIAttributes.GetMaxTCoords(); iUnit++ )
        {
            if( rIAttributes.HasTCoord(iUnit) )
            {
                iIChannels = rIAttributes.GetTCoordChannels(iUnit);
                iVBChannels = m_Attributes.GetTCoordChannels(iUnit);
                puiData = (unsigned int*)TCoordTuple(iUnit, i);
                if( iVBChannels < iIChannels )
                {
                    for( j = 0; j < iVBChannels; j++ )
                    {
                        tempCompatible.push_back(*puiData++);
                    }
                    for( j = iVBChannels; j < iIChannels; j++ )
                    {
                        // 填充为0,从而高维纹理坐标兼容低维纹理坐标
                        tempCompatible.push_back(0);
                    }
                }
                else
                {
                    for( j = 0; j < iIChannels; j++ )
                    {
                        tempCompatible.push_back(*puiData++);
                    }
                }
            }
        }
    }

    rChannels = (int)tempCompatible.size();
    if( !rCompatible )
    {
        // 调用者有责任释放该内存
        rCompatible = SE_NEW float[rChannels];
    }
Example #13
0
//----------------------------------------------------------------------------
SENode* SEWidget::CoordinateFrame(float fLengthOfAxis)
{
    SE_ASSERT( fLengthOfAxis > 0 );

    SENode* pNode = SE_NEW SENode;

    SEAttributes tempAttr;
    tempAttr.SetPositionChannels(3);
    tempAttr.SetColorChannels(0, 3);
    SEStandardMesh tempSM(tempAttr);

    SEMatrix3f mat3fRot;
    float fAxisHeight = 0.667f*fLengthOfAxis;
    float fArrowRadius = 0.08f*fLengthOfAxis;
    float fArrowHeight = (1.0f - 0.667f)*fLengthOfAxis;

    // Create axis x.
    SEVertexBuffer* pVBuffer = SE_NEW SEVertexBuffer(tempAttr, 2);
    pVBuffer->Position3(0) = SEVector3f::ZERO;
    pVBuffer->Position3(1) = fAxisHeight*SEVector3f::UNIT_X;
    pVBuffer->Color3(0, 0) = SEColorRGB::SE_RGB_RED;
    pVBuffer->Color3(0, 1) = SEColorRGB::SE_RGB_RED;
    SEPolyline* pAxisX = SE_NEW SEPolyline(pVBuffer, false, false);
    pAxisX->SetName("AxisX");

    // Create axis x's ending arrow.
    SETriMesh* pArrowX = tempSM.Cone(16, fArrowRadius, fArrowHeight);
    for( int i = 0; i < pArrowX->VBuffer->GetVertexCount(); i++ )
    {
        pArrowX->VBuffer->Color3(0, i) = SEColorRGB::SE_RGB_RED;
    }
    mat3fRot.FromAxisAngle(SEVector3f::UNIT_Y, SEMathf::HALF_PI);
    pArrowX->Local.SetRotate(mat3fRot);
    pArrowX->Local.SetTranslate(fAxisHeight*SEVector3f::UNIT_X);
    pArrowX->SetName("ArrowX");

    // Create axis y.
    pVBuffer = SE_NEW SEVertexBuffer(tempAttr, 2);
    pVBuffer->Position3(0) = SEVector3f::ZERO;
    pVBuffer->Position3(1) = fAxisHeight*SEVector3f::UNIT_Y;
    pVBuffer->Color3(0, 0) = SEColorRGB::SE_RGB_GREEN;
    pVBuffer->Color3(0, 1) = SEColorRGB::SE_RGB_GREEN;
    SEPolyline* pAxisY = SE_NEW SEPolyline(pVBuffer, false, false);
    pAxisY->SetName("AxisY");

    // Create axis y's ending arrow.
    SETriMesh* pArrowY = tempSM.Cone(16, fArrowRadius, fArrowHeight);
    for( int i = 0; i < pArrowY->VBuffer->GetVertexCount(); i++ )
    {
        pArrowY->VBuffer->Color3(0, i) = SEColorRGB::SE_RGB_GREEN;
    }
    mat3fRot.FromAxisAngle(SEVector3f::UNIT_X, -SEMathf::HALF_PI);
    pArrowY->Local.SetRotate(mat3fRot);
    pArrowY->Local.SetTranslate(fAxisHeight*SEVector3f::UNIT_Y);
    pArrowY->SetName("ArrowY");

    // Create axis z.
    pVBuffer = SE_NEW SEVertexBuffer(tempAttr, 2);
    pVBuffer->Position3(0) = SEVector3f::ZERO;
    pVBuffer->Position3(1) = fAxisHeight*SEVector3f::UNIT_Z;
    pVBuffer->Color3(0, 0) = SEColorRGB::SE_RGB_BLUE;
    pVBuffer->Color3(0, 1) = SEColorRGB::SE_RGB_BLUE;
    SEPolyline* pAxisZ = SE_NEW SEPolyline(pVBuffer, false, false);
    pAxisZ->SetName("AxisZ");

    // Create axis z's ending arrow.
    SETriMesh* pArrowZ = tempSM.Cone(16, fArrowRadius, fArrowHeight);
    for( int i = 0; i < pArrowZ->VBuffer->GetVertexCount(); i++ )
    {
        pArrowZ->VBuffer->Color3(0, i) = SEColorRGB::SE_RGB_BLUE;
    }
    pArrowZ->Local.SetTranslate(fAxisHeight*SEVector3f::UNIT_Z);
    pArrowZ->SetName("ArrowZ");

    SEVertexColor3Effect* pEffect = SE_NEW SEVertexColor3Effect;
    pAxisX->AttachEffect(pEffect);
    pArrowX->AttachEffect(pEffect);
    pAxisY->AttachEffect(pEffect);
    pArrowY->AttachEffect(pEffect);
    pAxisZ->AttachEffect(pEffect);
    pArrowZ->AttachEffect(pEffect);

    pNode->AttachChild(pAxisX);
    pNode->AttachChild(pArrowX);
    pNode->AttachChild(pAxisY);
    pNode->AttachChild(pArrowY);
    pNode->AttachChild(pAxisZ);
    pNode->AttachChild(pArrowZ);
    pNode->UpdateGS();

    return pNode;
}