Пример #1
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);
}
Пример #2
0
//----------------------------------------------------------------------------
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);
}
//----------------------------------------------------------------------------
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;
}
//----------------------------------------------------------------------------
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;
}
Пример #5
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;
}
Пример #6
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;
}
Пример #7
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;
}