void InitLightExam() { ZFXCOLOR color(0, 0, 1, 1); g_pDevice->SetShadeMode(RS_SHADE_SOLID, 1.0f, &color); ZFXVector vU(0, 1, 0); ZFXVIEWPORT vp = { 0, 0, 800, 600 }; g_pDevice->InitStage(60, &vp, 0); g_pDevice->SetClippingPlanes(0.1f, 1000.0f); g_pDevice->SetMode(EMD_PERSPECTIVE, 0); IShaderManager* sm = g_pDevice->GetShaderManager(); if (g_vshader) sm->BindShader(g_vshader); if (g_fshader) sm->BindShader(g_fshader); if (g_vshader || g_fshader) sm->EnableShader(true); light.Type = LGT_SPOT; light.cAmbient.rgba(0.2, 0.2, 0.2, 1); light.cDiffuse.rgba(0, 0, 1, 1); light.cSpecular.rgba(1, 0, 0, 1); light.fAttenuation0 = 1.0f; light.fAttenuation1 = 0.0f; light.fTheta = 30; light.fPhi = 60; light.fRange = 50; light.vcDirection = ZFXVector(0, 0, 0); }
void InitTriangleExam() { ZFXCOLOR color(0, 0, 1, 1); g_pDevice->SetShadeMode(RS_SHADE_SOLID, 1.0f, &color); ZFXVector vU(0, 1, 0); ZFXVIEWPORT vp = { 0, 0, 800, 600 }; g_pDevice->InitStage(60, &vp, 0); g_pDevice->SetClippingPlanes(0.1f, 1000.0f); g_pDevice->SetMode(EMD_ORTHOGONAL, 0); IShaderManager* sm = g_pDevice->GetShaderManager(); if (g_vshader) sm->BindShader(g_vshader); if (g_fshader) sm->BindShader(g_fshader); if (g_vshader || g_fshader) sm->EnableShader(true); sm->EnableShader(false); }
void CLightningFX::PreRender( float tmFrameTime ) { LTVector vPulse; LTVector vF(0.0f, 0.0f, 1.0f); LTVector vU(0.0f, 1.0f, 0.0f); LTVector vR(1.0f, 0.0f, 0.0f); // Transform the bolt LTMatrix mCam; if( m_bReallyClose ) { mCam.Identity(); } else { mCam = GetCamTransform(m_pLTClient, m_hCamera); } CLightningBolt *pBolt = LTNULL; LightningBolts::iterator iter; for( iter = m_lstBolts.begin(); iter != m_lstBolts.end(); ++iter ) { pBolt = *iter; // Skip this bolt if there are not enough segments... if( pBolt->m_collPathPts.GetSize() < 2 || !pBolt->m_bActive ) continue; CLinkListNode<PT_TRAIL_SECTION> *pNode = pBolt->m_collPathPts.GetHead(); //as long as some amount of time has passed, apply a pulse onto the bolt to make //it jitter if(tmFrameTime > 0.001f) { while (pNode) { vPulse = pNode->m_Data.m_vPos; vPulse += (vF * GetRandom( -GetProps()->m_fPulse, GetProps()->m_fPulse )); vPulse += (vU * GetRandom( -GetProps()->m_fPulse, GetProps()->m_fPulse )); vPulse += (vR * GetRandom( -GetProps()->m_fPulse, GetProps()->m_fPulse )); if( pNode == pBolt->m_collPathPts.GetHead() || !pNode->m_pNext ) { MatVMul(&pNode->m_Data.m_vTran, &mCam, &pNode->m_Data.m_vPos); } else { MatVMul(&pNode->m_Data.m_vTran, &mCam, &vPulse); } pNode = pNode->m_pNext; } } // Do some precalculations float fScale; CalcScale( pBolt->m_tmElapsed, pBolt->m_fLifetime, &fScale ); float fWidth = pBolt->m_fWidth * fScale; // Setup the colour float r, g, b, a; CalcColour( pBolt->m_tmElapsed, pBolt->m_fLifetime, &r, &g, &b, &a ); int ir = Clamp( (int)(r * 255.0f), 0, 255 ); int ig = Clamp( (int)(g * 255.0f), 0, 255 ); int ib = Clamp( (int)(b * 255.0f), 0, 255 ); int ia = Clamp( (int)(a * 255.0f), 0, 255 ); LTVector vStart, vEnd, vPrev, vBisector; vBisector.z = 0.0f; pNode = pBolt->m_collPathPts.GetHead(); while( pNode ) { if( GetProps()->m_eAllignment == ePTA_Camera ) { // Compute the midpoint vectors if( pNode == pBolt->m_collPathPts.GetHead() ) { vStart = pNode->m_Data.m_vTran; vEnd = pNode->m_pNext->m_Data.m_vTran; vBisector.x = vEnd.y - vStart.y; vBisector.y = -(vEnd.x - vStart.x); } else if( pNode == pBolt->m_collPathPts.GetTail() ) { vEnd = pNode->m_Data.m_vTran; vStart = pNode->m_pPrev->m_Data.m_vTran; vBisector.x = vEnd.y - vStart.y; vBisector.y = -(vEnd.x - vStart.x); } else { vPrev = pNode->m_pPrev->m_Data.m_vTran; vStart = pNode->m_Data.m_vTran; vEnd = pNode->m_pNext->m_Data.m_vTran; float x1 = vEnd.y - vStart.y; float y1 = -(vEnd.x - vStart.x); float z1 = vStart.z - vEnd.z; float x2 = vStart.y - vPrev.y; float y2 = -(vStart.x - vPrev.x); float z2 = vPrev.z - vEnd.z; vBisector.x = (x1 + x2) / 2.0f; vBisector.y = (y1 + y2) / 2.0f; } pNode->m_Data.m_vBisector = vBisector; } // Set the width for this section... pNode->m_Data.m_vBisector.Norm( fWidth ); // Set the color for this section... pNode->m_Data.m_red = ir; pNode->m_Data.m_green = ig; pNode->m_Data.m_blue = ib; pNode->m_Data.m_alpha = ia; pNode = pNode->m_pNext; } } }
bool CLTBModelFX::Update(float tmFrameTime) { //Ok, what we are going to do is see if we are supposed to be sync'd to the //animation. If so, we are going to flat out ignore tmCur, and instead generate //our own. This way we can match the model exactly. if(GetProps()->m_bSyncToModelAnim) { //we need to find out where in the animation the model currently is ILTModel *pLTModel = m_pLTClient->GetModelLT(); ANIMTRACKERID nTracker; if(pLTModel->GetMainTracker( m_hObject, nTracker ) == LT_OK) { //we have the main tracker, see where in its timeline it is uint32 nCurrTime; uint32 nAnimTime; pLTModel->GetCurAnimTime(m_hObject, nTracker, nCurrTime); pLTModel->GetCurAnimLength(m_hObject, nTracker, nAnimTime); if(nAnimTime) { //handle wrapping nCurrTime %= nAnimTime; //ok, now convert cur time to a valid time m_tmElapsed = (nCurrTime * GetProps()->m_tmLifespan) / (float)nAnimTime; } else { //zero length animation? m_tmElapsed = 0.0f; } } } else if(GetProps()->m_bSyncToKey) { //we need to find out where in the key we currently are ILTModel *pLTModel = m_pLTClient->GetModelLT(); ANIMTRACKERID nTracker; if(pLTModel->GetMainTracker( m_hObject, nTracker ) == LT_OK) { //we have the main tracker, see where in its timeline it is uint32 nAnimLength; m_pLTClient->GetModelLT()->ResetAnim( m_hObject, nTracker ); pLTModel->GetCurAnimLength(m_hObject, nTracker, nAnimLength); if(nAnimLength > 0) nAnimLength--; float tmWrappedTime = fmodf(m_tmElapsed / GetProps()->m_tmLifespan, 1.0f); uint32 nAnimTime = (uint32)(tmWrappedTime * nAnimLength); pLTModel->SetCurAnimTime(m_hObject, nTracker, nAnimTime); } } // Base class update first if (!CBaseFX::Update(tmFrameTime)) return false; //see if we should reset our model animation if(!GetProps()->m_bSyncToKey && IsFinishedShuttingDown()) { //Reset the animation ANIMTRACKERID nTracker; m_pLTClient->GetModelLT()->GetMainTracker( m_hObject, nTracker ); m_pLTClient->GetModelLT()->ResetAnim( m_hObject, nTracker ); if(GetProps()->m_bOverrideAniLength) m_pLTClient->GetModelLT()->SetAnimRate( m_hObject, nTracker, m_fAniRate); } // Align if neccessary, to the rotation of our parent if ((m_hParent) && (GetProps()->m_nFacing == FACE_PARENTALIGN)) { LTRotation rParentRot; m_pLTClient->GetObjectRotation(m_hParent, &rParentRot); rParentRot = (GetProps()->m_bRotate ? rParentRot : rParentRot * m_rNormalRot); m_pLTClient->SetObjectRotation(m_hObject, &rParentRot); } // If we want to add a rotation, make sure we are facing the correct way... if( GetProps()->m_bRotate ) { LTFLOAT tmFrame = tmFrameTime; LTVector vR( m_rRot.Right() ); LTVector vU( m_rRot.Up() ); LTVector vF( m_rRot.Forward() ); LTRotation rRotation; if( m_hCamera && (GetProps()->m_nFacing == FACE_CAMERAFACING)) { m_pLTClient->GetObjectRotation( m_hCamera, &rRotation ); } else { m_pLTClient->GetObjectRotation( m_hObject, &rRotation ); } m_rRot.Rotate( vR, MATH_DEGREES_TO_RADIANS( GetProps()->m_vRotAdd.x * tmFrame )); m_rRot.Rotate( vU, MATH_DEGREES_TO_RADIANS( GetProps()->m_vRotAdd.y * tmFrame )); m_rRot.Rotate( vF, MATH_DEGREES_TO_RADIANS( GetProps()->m_vRotAdd.z * tmFrame )); rRotation = rRotation * m_rRot; m_pLTClient->SetObjectRotation( m_hObject, &(rRotation * m_rNormalRot)); } else if( GetProps()->m_nFacing == FACE_CAMERAFACING ) { LTRotation rCamRot; m_pLTClient->GetObjectRotation( m_hCamera, &rCamRot ); m_pLTClient->SetObjectRotation( m_hObject, &(rCamRot * m_rNormalRot) ); } // Success !! return true; }
void DrawLightExam() { // compute camera g_pos.y = distance * sin(yAngle); g_pos.x = distance * cos(yAngle) * sin(-xAngle); g_pos.z = distance * cos(yAngle) * cos(-xAngle); g_lightPos.y = LightDistantce * sin(yLightAngle); g_lightPos.x = LightDistantce * cos(yLightAngle) * sin(-xLightAngle); g_lightPos.z = LightDistantce * cos(yLightAngle) * cos(-xLightAngle); light.vcPosition = g_lightPos; light.vcDirection = -g_lightPos; light.vcDirection.w = 0; light.fPhi = g_cutoff; light.fExponent = g_exponent; g_pDevice->UseWindow(0); ZFXVector vU(0, 1, 0); g_pDevice->SetViewLookAt(g_pos, ZFXVector(0, 0, 0), vU); IShaderManager *sm = g_pDevice->GetShaderManager(); sm->SetNamedConstant("camera_position", DAT_FVEC4, 1, g_pos.v); GLfloat f[16] = { 0.0 }; glGetFloatv(GL_MODELVIEW_MATRIX, f); glGetFloatv(GL_PROJECTION_MATRIX, f); ZFXMatrix mWorld; mWorld.Identity(); g_pDevice->SetWorldTransform(&mWorld); //sm->EnableShader(false); g_pDevice->SetAmbientLight(0.1, 0.1, 0.1); g_pDevice->SetLight(&light, 0); float v[4]; glGetMaterialfv(GL_FRONT, GL_AMBIENT, v); glGetMaterialfv(GL_FRONT, GL_DIFFUSE, v); glGetMaterialfv(GL_FRONT, GL_SPECULAR, v); glGetMaterialfv(GL_FRONT, GL_EMISSION, v); DrawOBJModel(); GLenum error = glGetError(); if (error != GL_NO_ERROR) { int i = 0; } glGetMaterialfv(GL_FRONT, GL_AMBIENT, v); glGetMaterialfv(GL_FRONT, GL_DIFFUSE, v); glGetMaterialfv(GL_FRONT, GL_SPECULAR, v); glGetMaterialfv(GL_FRONT, GL_EMISSION, v); glGetLightfv(GL_LIGHT0, GL_AMBIENT, v); glGetLightfv(GL_LIGHT0, GL_DIFFUSE, v); glGetLightfv(GL_LIGHT0, GL_SPECULAR, v); error = glGetError(); if (error != GL_NO_ERROR) { int i = 0; } }