void LightRender () { CLight* l; if (!EntityReady ()) return; if (!angles_done) { for (int size = 0; size < MAX_SIZE; size++) { for (int i = 0 ; i < 360; i++) { angles[size][i].x = cosf ((float)i * DEGREES_TO_RADIANS) * ((float)size + 0.5f); angles[size][i].y = sinf ((float)i * DEGREES_TO_RADIANS) * ((float)size + 0.5f); } } } glDepthMask (false); glEnable (GL_BLEND); glDisable (GL_CULL_FACE); glBlendFunc (GL_ONE, GL_ONE); glBindTexture(GL_TEXTURE_2D, TextureId (TEXTURE_LIGHT)); glDisable (GL_CULL_FACE); glBegin (GL_QUADS); for (l = head; l; l = l->_next) l->Render (); glEnd (); glDepthMask (true); }
void CShader_Deferred::Render() { glEnable(GL_BLEND); glDisable(GL_CULL_FACE); glDisable(GL_DEPTH_TEST); // Set shader GetGame()->GetRenderSystem()->SetShader(GetGame()->GetRenderSystem()->GetShader("deferred")); // Enable positions glEnableVertexAttribArray(0); if (GetGame()->GetGLSLVersion() == GLSL_VERSION_130) { glBindAttribLocation(GetID(), 0, "vertexPos_MS"); glBindAttribLocation(GetID(), 1, "vertexTexCoords"); } glBindBuffer(GL_ARRAY_BUFFER, GetGame()->GetRenderSystem()->GetScreenQuad()); glVertexAttribPointer( 0, 2, GL_FLOAT, GL_FALSE, 0, (void*)0 ); // Enable UVs glEnableVertexAttribArray(1); glBindBuffer(GL_ARRAY_BUFFER, GetGame()->GetRenderSystem()->GetScreenUVs()); glVertexAttribPointer( 1, 2, GL_FLOAT, GL_FALSE, 0, (void*)0 ); for (unsigned int i = 0; i < GetGame()->GetSceneManager()->GetLightCount(); i++) { CLight* light = GetGame()->GetSceneManager()->GetLight(i); if (light->Enabled()) { GetGame()->GetRenderSystem()->SetCurLight(light); Update(); glDrawArrays(GL_TRIANGLES, 0, 8); } } // Clean up glDisableVertexAttribArray(0); glDisableVertexAttribArray(1); glEnable(GL_CULL_FACE); glEnable(GL_DEPTH_TEST); glDisable(GL_BLEND); }
void CDeco::CreateRadioTower (GLvector pos, float height) { CLight* l; float offset; GLvertex v; fan f; for(int i=0; i<6; i++) f.index_list.push_back(i); offset = height / 15.0f; _center = pos; _use_alpha = true; //Radio tower v.position = glVector (_center.x, _center.y + height, _center.z); v.uv = glVector (0,1); _mesh->VertexAdd (v); v.position = glVector (_center.x - offset, _center.y, _center.z - offset); v.uv = glVector (1,0); _mesh->VertexAdd (v); v.position = glVector (_center.x + offset, _center.y, _center.z - offset); v.uv = glVector (0,0); _mesh->VertexAdd (v); v.position = glVector (_center.x + offset, _center.y, _center.z + offset); v.uv = glVector (1,0); _mesh->VertexAdd (v); v.position = glVector (_center.x - offset, _center.y, _center.z + offset); v.uv = glVector (0,0); _mesh->VertexAdd (v); v.position = glVector (_center.x - offset, _center.y, _center.z - offset); v.uv = glVector (1,0); _mesh->VertexAdd (v); _mesh->FanAdd (f); l = new CLight (glVector (_center.x, _center.y + height + 1.0f, _center.z), glRgba (255,192,160), 1); l->Blink (); _texture = TextureId (TEXTURE_LATTICE); }
HRESULT CEditorScene::CreateLight() { m_vecLight.reserve(10); CLight* pLight = new CLight; D3DLIGHT9 tLight; memset(&tLight, 0, sizeof(D3DLIGHT9)); D3DCOLORVALUE tValue; tValue.b = tValue.g = tValue.r = tValue.a = 1.f; tLight.Ambient = tValue; tLight.Diffuse = tValue; tLight.Specular = tValue; tLight.Direction = D3DXVECTOR3(1.f, 0.f, 1.f); tLight.Type = D3DLIGHT_DIRECTIONAL; pLight->SetLightInfo(tLight); m_vecLight.push_back(pLight); return S_OK; }
// *************************************************************************** void CPointLight::computeAttenuationFactors() { // disable attenuation? if(_AttenuationBegin==0 && _AttenuationEnd==0) { // setup for attenuation disabled. _ConstantAttenuation= 1; _LinearAttenuation= 0; _QuadraticAttenuation= 0; } else { // precompute attenuation values, with help of CLight formula!! CLight dummyLight; dummyLight.setupAttenuation(_AttenuationBegin, _AttenuationEnd); _ConstantAttenuation= dummyLight.getConstantAttenuation(); _LinearAttenuation= dummyLight.getLinearAttenuation(); _QuadraticAttenuation= dummyLight.getQuadraticAttenuation(); // setup _OODeltaAttenuation _OODeltaAttenuation= _AttenuationEnd - _AttenuationBegin; if(_OODeltaAttenuation <=0 ) _OODeltaAttenuation= 0; else _OODeltaAttenuation= 1.0f / _OODeltaAttenuation; } }
//------------------------------------------------------------------------ // isRenderTerrainBuffer : true 이면 m_pTerrainSurf 버퍼에 지형을 출력한다. // isRenderDeptBuffer : true 이면 깊이버퍼에 깊이값을 저장한다. // [2011/2/28 jjuiddong] //------------------------------------------------------------------------ void CChunkManager::RenderChunks(BOOL isRenderTerrainBuffer, BOOL isRenderDeptBuffer) { LPDIRECT3DSURFACE9 pOldBackBuffer = NULL; LPDIRECT3DSURFACE9 pOldZBuffer = NULL; if (isRenderTerrainBuffer) { g_pDevice->GetRenderTarget(0, &pOldBackBuffer); //g_pDevice->GetDepthStencilSurface(&pOldZBuffer); g_pDevice->SetRenderTarget(0, m_pTerrainSurf); //g_pDevice->SetDepthStencilSurface(m_pZ); g_pDevice->Clear(0L, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffffffff, 1.0f, 0L); } m_pShader->Begin(); Matrix44 mWVP; g_Camera.GetViewProjMatrix(&mWVP); m_pShader->SetMatrix("mWVP", mWVP); Matrix44 mWVPB = mWVP * m_mScaleBias; m_pShader->SetMatrix("mWVPB", mWVPB); // 광원방향 CLight *pLight = m_pTerrain->GetLight(); Vector3 lightPos = pLight->GetDirection(); D3DXVECTOR4 v(lightPos.x, lightPos.y, lightPos.z, -0.3f); // -0.3f 환경광의 강도 m_pShader->SetVector( "vLightDir", v); // 시점 Vector3 eyePos = g_Camera.GetPosition(); m_pShader->SetVector( "vEyePos", eyePos); for (int i=0; i < m_ChunkSize; ++i) m_pChunk[ i].Render(m_pShader, 0); // g_pDevice->SetRenderTarget(0, m_pTerrainDepthSurf); // g_pDevice->Clear(0L, NULL, D3DCLEAR_TARGET, 0x00, 1.0f, 0L); m_pShader->End(); m_pWater->Render(); if (isRenderDeptBuffer) { // g_pDevice->SetRenderTarget(0, m_pTerrainDepthSurf); // g_pDevice->Clear(0L, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x00, 1.0f, 0L); // // for (int i=0; i < m_ChunkSize; ++i) // m_pChunk[ i].Render(m_pShader, 1); } if (isRenderTerrainBuffer) { g_pDevice->SetRenderTarget(0, pOldBackBuffer); //g_pDevice->SetDepthStencilSurface(pOldZBuffer); pOldBackBuffer->Release(); //pOldZBuffer->Release(); } }
bool ESceneLightTools::Validate(bool full_test) { if (!inherited::Validate(full_test)) return false; bool bRes = !m_Objects.empty(); for (ObjectIt it=m_Objects.begin(); it!=m_Objects.end(); it++){ CLight* L = dynamic_cast<CLight*>(*it); if (!L->GetLControlName()){ bRes=false; ELog.Msg(mtError,"%s: '%s' - Invalid light control.",ClassDesc(),L->Name); } } return bRes; }
CGuiLight* CGuiLight::Create(CGuiFrame* frame, CInputStream& in, bool flag) { CGuiWidgetParms parms = ReadWidgetHeader(frame, in, flag); ELightType tp = ELightType(in.readUint32Big()); float distC = in.readFloatBig(); float distL = in.readFloatBig(); float distQ = in.readFloatBig(); float angC = in.readFloatBig(); float angL = in.readFloatBig(); float angQ = in.readFloatBig(); u32 loadedIdx = in.readUint32Big(); CGuiLight* ret = nullptr; switch (tp) { case ELightType::Spot: { float cutoff = in.readFloatBig(); CLight lt = CLight::BuildSpot(zeus::CVector3f::skZero, zeus::CVector3f::skZero, parms.x10_color, cutoff); lt.SetAttenuation(distC, distL, distQ); lt.SetAngleAttenuation(angC, angL, angQ); lt.x40_loadedIdx = loadedIdx; ret = new CGuiLight(parms, lt); break; } case ELightType::Point: { CLight lt = CLight::BuildPoint(zeus::CVector3f::skZero, parms.x10_color); lt.SetAttenuation(distC, distL, distQ); lt.x40_loadedIdx = loadedIdx; ret = new CGuiLight(parms, lt); break; } case ELightType::Directional: { CLight lt = CLight::BuildDirectional(zeus::CVector3f::skZero, parms.x10_color); lt.x40_loadedIdx = loadedIdx; ret = new CGuiLight(parms, lt); break; } default: break; } ret->ParseBaseInfo(frame, in, parms); frame->AddLight(ret); return ret; }
void CTriangle::Render( uint32 i_iPass ) { switch( i_iPass ) { case ePass_Lighting: break; } CGraphics *pGraphics = m_pParent->pGetParent()->pGetGraphics(); CCamera *pCurCamera = pGraphics->pGetCurCamera(); matrix44 matWorld; matMatrix44Identity( matWorld ); pCurCamera->SetWorldMatrix( matWorld ); m_pVertexShader->SetMatrix( m3dsc_worldmatrix, pCurCamera->matGetWorldMatrix() ); m_pVertexShader->SetMatrix( m3dsc_viewmatrix, pCurCamera->matGetViewMatrix() ); m_pVertexShader->SetMatrix( m3dsc_projectionmatrix, pCurCamera->matGetProjectionMatrix() ); m_pVertexShader->SetMatrix( m3dsc_wvpmatrix, pCurCamera->matGetWorldMatrix() * pCurCamera->matGetViewMatrix() * pCurCamera->matGetProjectionMatrix() ); vector3 vCamPos = pCurCamera->vGetPosition(); m_pVertexShader->SetVector( 0, vector4( vCamPos.x, vCamPos.y, vCamPos.z, 0 ) ); CLight *pLight = m_pParent->pGetCurrentLight(); vector3 vLightPos = pLight->vGetPosition(); m_pVertexShader->SetVector( 1, vector4( vLightPos.x, vLightPos.y, vLightPos.z, 0 ) ); m_pPixelShader->SetVector( 0, pLight->vGetColor() ); pGraphics->SetVertexFormat( m_pVertexFormat ); pGraphics->SetVertexStream( 0, m_pVertexBuffer, 0, sizeof( vertexformat ) ); pGraphics->SetVertexShader( m_pVertexShader ); pGraphics->SetPixelShader( m_pPixelShader ); CResManager *pResManager = m_pParent->pGetParent()->pGetResManager(); CTexture *pTexture = (CTexture *)pResManager->pGetResource( m_hTexture ); pGraphics->SetTexture( 0, pTexture->pGetTexture() ); CTexture *pNormalmap = (CTexture *)pResManager->pGetResource( m_hNormalmap ); pGraphics->SetTexture( 1, pNormalmap->pGetTexture() ); for( uint32 i = 0; i < 2; ++i ) { pGraphics->SetTextureSamplerState( i, m3dtss_addressu, m3dta_clamp ); pGraphics->SetTextureSamplerState( i, m3dtss_addressv, m3dta_clamp ); } pGraphics->pGetM3DDevice()->DrawPrimitive( m3dpt_trianglelist, 0, 1 ); }
bool CEnvSphere::bCreateWorld() { m_pCamera = 0; m_hSphere = 0; m_hLight = 0; // Create and setup camera ------------------------------------------------ m_pCamera = new CMyCamera( pGetGraphics() ); if( !m_pCamera->bCreateRenderCamera( iGetWindowWidth(), iGetWindowHeight() ) ) return false; m_pCamera->CalculateProjection( M3D_PI * 0.5f, 10.0f, 0.1f ); m_pCamera->SetPosition( vector3( 0, 0, -2 ) ); m_pCamera->SetLookAt( vector3( 0, 0, 0 ), vector3( 0, 1, 0 ) ); m_pCamera->CalculateView(); // Register triangle-entity and create an instance ------------------------ pGetScene()->RegisterEntityType( "sphere", CSphere::pCreate ); m_hSphere = pGetScene()->hCreateEntity( "sphere" ); if( !m_hSphere ) return false; CSphere *pSphere = (CSphere *)pGetScene()->pGetEntity( m_hSphere ); if( !pSphere->bInitialize( 1.0f, 16, 16, "majestic.cube" ) ) return false; // Create the light ------------------------------------------------------- m_hLight = pGetScene()->hCreateLight(); if( !m_hLight ) return false; CLight *pLight = pGetScene()->pGetLight( m_hLight ); pLight->SetPosition( vector3( 1.5f, 0.25f, 0 ) ); pLight->SetColor( vector4( 1, 1, 0.75f, 1 ) ); // Demonstrating smooth-subdivision to get a round sphere // disable this and increase sphere-tesselation for better preformance (memory-usage will be higher!) pGetGraphics()->SetRenderState( m3drs_subdivisionmode, m3dsubdiv_smooth ); pGetGraphics()->SetRenderState( m3drs_subdivisionlevels, 1 ); pGetGraphics()->SetRenderState( m3drs_subdivisionpositionregister, 0 ); pGetGraphics()->SetRenderState( m3drs_subdivisionnormalregister, 0 ); // using vertex-positions as normals (unit-sphere at origin) return true; }
void ESceneLightTools::BeforeRender() { if (psDeviceFlags.is(rsLighting)){ int l_cnt = 0; // set scene lights for(ObjectIt _F = m_Objects.begin();_F!=m_Objects.end();_F++){ CLight* l = (CLight*)(*_F); l_cnt++; if (l->Visible()&&l->m_UseInD3D&&l->m_Flags.is_any(ELight::flAffectDynamic|ELight::flAffectStatic)) if (::Render->ViewBase.testSphere_dirty(l->PPosition,l->m_Range)) AppendFrameLight(l); } // set sun if (m_Flags.is(flShowSun)){ Flight L; Fvector C; if (psDeviceFlags.is(rsEnvironment)){ C = g_pGamePersistent->Environment().CurrentEnv.sun_color; }else{ C.set (1.f,1.f,1.f); } L.direction.setHP(m_SunShadowDir.y,m_SunShadowDir.x); L.diffuse.set (C.x,C.y,C.z,1.f); L.ambient.set (0.f,0.f,0.f,0.f); L.specular.set (C.x,C.y,C.z,1.f); L.type = D3DLIGHT_DIRECTIONAL; Device.SetLight (frame_light.size(),L); Device.LightEnable(frame_light.size(),TRUE); } // ambient if (psDeviceFlags.is(rsEnvironment)){ Fvector& V = g_pGamePersistent->Environment().CurrentEnv.ambient; Fcolor C; C.set(V.x,V.y,V.z,1.f); Device.SetRS (D3DRS_AMBIENT,C.get()); }else Device.SetRS(D3DRS_AMBIENT,0x00000000); Device.Statistic->dwTotalLight = l_cnt; Device.Statistic->dwLightInScene = frame_light.size(); } }
CLight CGuiLight::BuildLight() const { CLight ret = CLight::BuildLocalAmbient(zeus::CVector3f::skZero, zeus::CColor::skBlack); switch (xf8_type) { case ELightType::Spot: ret = CLight::BuildSpot(GetWorldPosition(), x34_worldXF.m_basis[1], xbc_color, xfc_spotCutoff); break; case ELightType::Point: ret = CLight::BuildPoint(GetWorldPosition(), xbc_color); break; case ELightType::Directional: ret = CLight::BuildDirectional(x34_worldXF.m_basis[1], xbc_color); break; default: break; } ret.SetAttenuation(x100_distC, x104_distL, x108_distQ); ret.SetAngleAttenuation(x10c_angleC, x110_angleL, x114_angleQ); return ret; }
void CRenderObjectsManager::ProcessLighting(CRenderObject* pobj,POLYGON& poly) { VERTICESLIST &pointlist = pobj->m_translateverticesList; int v_index1 = poly.v[0]; int v_index2 = poly.v[1]; int v_index3 = poly.v[2]; //Get the original r,g,b,a bool bHasTexture = poly.state & OBJECT_HAS_TEXTURE; UCHAR r_base = bHasTexture ?255:poly.color.r; UCHAR g_base = bHasTexture ? 255:poly.color.g; UCHAR b_base = bHasTexture?255: poly.color.b; UCHAR a_base = bHasTexture?0:poly.color.a;//to do.modify here int r_sum=0,g_sum = 0,b_sum = 0; int ilightsize = m_pLightingManager->GetLightsCount(); const LIGHTSLIST& lightslist = m_pLightingManager->GetLights(); CLight *light = NULL; //Get the normal direction Vector4D P0P1 = pointlist[v_index2].vertex - pointlist[v_index1].vertex; Vector4D P1P2 = pointlist[v_index3].vertex - pointlist[v_index1].vertex; Vector4D N = P0P1.CrossProduct(P1P2); N.Normalize(); for(int i = 0; i < ilightsize;++i) { light = lightslist[i]; if(!light->IsEnable()) continue; //Get the cos value of the angle between the light and normal Vector4D lightdir = light->m_lightdir; float coslight2normal = N.DotProduct(-1*lightdir); const CLight::LightType lighttype = light->GetLightType(); if(lighttype == CLight::kAmbientLight) { r_sum += ((light->m_amblient.r * r_base)/256); g_sum += ((light->m_amblient.g * g_base)/256); b_sum += ((light->m_amblient.b * b_base)/256); } if(lighttype == CLight::kInfiniteLigtht) { if(coslight2normal>0) { r_sum += ((light->m_diffuse.r * r_base *coslight2normal)/256); g_sum += ((light->m_diffuse.g * g_base*coslight2normal)/256); b_sum += ((light->m_diffuse.b * b_base*coslight2normal)/256); } } if(lighttype == CLight::kPointLight) { // c = c_diffuse * I/(kc+kl*d+kq*d^2); // Vector4D vertex2lightpos = Vector4D(light->m_lightpos- pointlist[v_index1].vertex); float d = vertex2lightpos.GetLength(); float l = vertex2lightpos.DotProduct(N); float cosv = N.DotProduct(vertex2lightpos); if(cosv >0) { cosv = cosv/d; float k = light->m_kconst + light->m_klinear * d + light->m_kquadratic*d*d; float fDiv = k*256;//k*256 r_sum += ((light->m_diffuse.r * r_base *cosv)/fDiv); g_sum += ((light->m_diffuse.g * g_base*cosv)/fDiv); b_sum += ((light->m_diffuse.b * b_base*cosv)/fDiv); } } if(lighttype == CLight::kSpotLight) { //use this model // c = c_diffuse * I*MAX(COSa,0)^pf/(kc+kl*d+kq*d^2) float l = N.DotProduct(-1*lightdir); if(l >0) { Vector4D vertex2lightpos = Vector4D(light->m_lightpos-pointlist[v_index1].vertex ); float d = vertex2lightpos.GetLength(); //calculate the cos value of light direction and vertext->lightpos float l = N.DotProduct(vertex2lightpos); if(l > 0) { float cosv = l/d; float dl = cosv; for(int i = 1; i < light->m_pf;++i) dl *= cosv; float k = light->m_kconst + light->m_klinear * d + light->m_kquadratic*d*d; float fDiv = k*256;//k*256 r_sum += ((light->m_diffuse.r * r_base *dl)/fDiv); g_sum += ((light->m_diffuse.g * g_base*dl)/fDiv); b_sum += ((light->m_diffuse.b * b_base*dl)/fDiv); } } } } if(r_sum >255) r_sum = 255; if(g_sum > 255) g_sum = 255; if(b_sum > 255) b_sum = 255; poly.ret_color = RGBA(r_sum,g_sum,b_sum,0.0); }
//----------------------------------------------------------------------------------------- TestAnimation::TestAnimation() { // On crée une camera m_pCamera = getSceneManager()->createCamera(); m_pCamera->setEyePosition(QVector3D(2., 1., 2.)); m_pCamera->setCenter(QVector3D(0., 0., 0.)); #ifdef SOFTWARE_RENDERING m_pView = createSoftwareView3D(m_pCamera); #else m_pView = createWidget3D(m_pCamera); #endif m_pCamera->setAspectRatio((real)m_pView->width() / (real)m_pView->height()); // On charge le modéle CSceneNode* pRootNode = m_pSceneManager->getRootNode(); CSceneNode* pModelNode = pRootNode->createChild("dwarf"); // anim_test.x // rotatingcube.3ds // dwarf.x if (!CAssimpImporter::mergeScene("://dwarf.x", m_pSceneManager, true, pModelNode).isEmpty()) { // On récupére la bounding box CBox3D bbox = pRootNode->getGlobalAxisAlignedBoundingBox(); real sizeX = bbox.getMaximum().x() - bbox.getMinimum().x(); real sizeY = bbox.getMaximum().y() - bbox.getMinimum().y(); real sizeZ = bbox.getMaximum().z() - bbox.getMinimum().z(); real maxSize = sizeX; if (sizeY > maxSize) maxSize = sizeY; if (sizeZ > maxSize) maxSize = sizeZ; // On redimensionne la scene de façon à ce qu'elle tienne dans une boite de 1x1x1 pModelNode->scale(1. / maxSize); CBox3D scaledBbox = pModelNode->getGlobalAxisAlignedBoundingBox(); // On la centre pModelNode->translate(-scaledBbox.getCenter()); CSceneNode* pLightNode = pRootNode->createChild("LightNode", QVector3D(8.0, 12.0, 0)); // On crée une lumiére diffuse blanche CLight* pLight = m_pSceneManager->createLight("Light"); pLight->setDiffuseColor(0.8f, 0.8f, 0.8f); pLight->setAmbientColor(0.6f, 0.6f, 0.6f); pLight->setSpecularColor(0.4f, 0.4f, 0.4f); pLight->setDirection(QVector3D(-1, -1, 0)); // On l'associe au noeud pLightNode->addItem(pLight); pRootNode->dumpNodeTree(); //m_pSceneManager->setSceneGraphVisible(true); QList<CAnimation*> anims = m_pSceneManager->getAnimations(); m_pView->setGeometry(QRect(100, 100, 400, 300)); m_pView->getRenderer()->run(); getAnimationManager()->run(); if (anims.size() > 0) { QList<CSceneNodeAnimation*> nodeAnimations = anims[0]->getNodeAnimations(); foreach (CSceneNodeAnimation* pNodeAnim, nodeAnimations) { pNodeAnim->setAnimationBehavior(eAnimationBehaviourRepeat); }
void Render() { Matrix mat,mat1,mat2; Bulid_XYZ_RotationMatrix(mat1,0.0,0.0,g_roty); BuildTranslateMatrix(mat2,0.0,0.0,g_tranz); static bool bDrawNonTextureCube=false; if(KEY_DOWN(VK_F1)) { //Draw the color cube. don't use texture bDrawNonTextureCube = !bDrawNonTextureCube; } int icount = g_RenderManager.RenderObjectSize(); for(int i = 0; i < icount;++i) { CRenderObject *pobj = g_RenderManager[i]; POLYGONLIST &polygonlist = pobj->m_PolyGonList; int polygonsize = polygonlist.size(); for( int j = 0; j < polygonsize;++j) { POLYGON &polygon = polygonlist[j]; if(bDrawNonTextureCube) polygon.state &= ~OBJECT_HAS_TEXTURE; else polygon.state |= OBJECT_HAS_TEXTURE; } pobj->Transform(mat1);//transform local pobj->world_pos *= mat2; } //local->world,world->camera,camera->screen static bool bEnableLighting = false; static bool bEableBackfaceRemove =false; static bool bEnableInvZBuffer = false; if(KEY_DOWN(VK_HOME)) { //user press p for(int i=0; i< g_lights.GetLightsCount();++i) { CLight* pLight = g_lights.GetLight(i); pLight->EnableLight(); /* if(pLight->GetLightType() == CLight::kAmbientLight) { pLight->EnableLight(); break; }*/ } bEnableLighting = true; } else if(KEY_DOWN(VK_END)) { bEnableLighting = false; } else if(KEY_DOWN(VK_F2)) { bEableBackfaceRemove = true; } else if(KEY_DOWN(VK_F3)) { bEableBackfaceRemove = false; } else if(KEY_DOWN(VK_F4)) { bEnableInvZBuffer = true; } else if(KEY_DOWN(VK_F5)) { bEnableInvZBuffer = false; } if(bEnableInvZBuffer) ZBuffer::GetInstance()->Clear(0); else ZBuffer::GetInstance()->Clear((1<<30)-1); g_RenderManager.Render(bEnableLighting,bEableBackfaceRemove,!bEnableInvZBuffer); g_fps++; }
void Init() { // ::SetTimer(g_hwnd,100,1000,NULL); bool bret = LoadBitmapFile(&bitmap,"wall.bmp"); int bitmapwidth = bitmap.bitmapinfoheader.biWidth; int bitmapheight = bitmap.bitmapinfoheader.biHeight; CRenderObject *pobj = new CRenderObject; std::vector<Vertex> pointlist; pointlist.push_back(Vertex(POINT3D(10,10,10) )); pointlist.push_back(Vertex(POINT3D(10,10,-10))); pointlist.push_back(Vertex(POINT3D(-10,10,-10))); pointlist.push_back(Vertex(POINT3D(-10,10,10))); pointlist.push_back(Vertex(POINT3D(10,-10,10))); pointlist.push_back(Vertex(POINT3D(-10,-10,10))); pointlist.push_back(Vertex(POINT3D(-10,-10,-10))); pointlist.push_back(Vertex(POINT3D(10,-10,-10))); pobj->m_translateverticesList = pointlist; pobj->m_verticesList = pointlist; //Set texture pointlist std::vector<POINT2D> texturelist; texturelist.push_back(POINT2D(0,0)); texturelist.push_back(POINT2D(bitmapwidth-1,0)); texturelist.push_back(POINT2D(bitmapwidth-1,bitmapheight-1)); texturelist.push_back(POINT2D(0,bitmapheight-1)); pobj->m_texturecoordinatesList = texturelist; int tempindices[36]= { 0,1,2, 0,2,3, 0,7,1, 0,4,7, 1,7,6, 1,6,2, 2,6,5, 2,3,5, 0,5,4, 0,3,5, 5,6,7, 4,5,7 }; int textindices[36] = { 2,1,0, 2,0,3, 2,0,1, 2,3,0, 1,0,3, 1,3,0, 0,1,2, 2,3,0, 2,0,1, 2,3,0, 2,1,0, 3,2,0 }; for(int i =0; i <12;++i) { POLYGON temp ; temp.v[0] = tempindices[i*3+0]; temp.v[1] = tempindices[i*3+1]; temp.v[2] = tempindices[i*3 +2]; temp.text[0] = textindices[i*3+0]; temp.text[1] = textindices[i*3+1]; temp.text[2] = textindices[i*3+2]; temp.state |= OBJECT_HAS_TEXTURE|SHADE_MODEL_CONSTANT; temp.color = RGBA(RGB(128,123,140)); temp.texture = &bitmap; temp.pointlist = &pobj->m_verticesList; temp.texturecoordinatelist = &pobj->m_texturecoordinatesList; pobj->m_PolyGonList.push_back(temp); } pobj->world_pos = POINT3D(-10,0,50); CRenderObject *pobj2 = new CRenderObject(*pobj); pobj2->world_pos = POINT3D(15,0,50); CRenderObject* pobj3 =new CRenderObject(*pobj); pobj3->world_pos = POINT3D(0,10,80); CRenderObject *pobj4 = new CRenderObject(*pobj); pobj4->world_pos = POINT3D(20,-10,100); g_RenderManager.Add(pobj); g_RenderManager.Add(pobj2); g_RenderManager.Add(pobj3); g_RenderManager.Add(pobj4); //Set lights CLight *pLight = new CLight; pLight->InitLight(CLight::kAmbientLight,RGBA(RGB(255,0,0)),Black_Color,Black_Color); g_lights.AddLight(pLight); CLight *pLight2 = new CLight; pLight2->InitLight(CLight::kInfiniteLigtht,Black_Color,RGBA(255,0,0),Black_Color,ZeroVector, Vector4D(-1.0,0.0,1.0)); g_lights.AddLight(pLight2); CLight *pLight3 = new CLight; pLight3->InitLight(CLight::kPointLight,Black_Color,RGBA(0,255,0),Black_Color,Vector4D(0,10,0), ZeroVector,1.0,2.0,4.0); g_lights.AddLight(pLight3); CLight *pLight4 = new CLight; pLight4->InitLight(CLight::kSpotLight,Black_Color,RGBA(255,255,255),Black_Color,Vector4D(0,20,10), Vector4D(0.0,0.0,1.0),0.0,0.01,0.0,30.0,60.0,1.0); g_lights.AddLight(pLight4); g_RenderManager.SetCamera(&g_cam); g_RenderManager.SetLightManager(&g_lights); }
//------------------------- // FX_AddLight //------------------------- CLight *FX_AddLight( vec3_t org, float size1, float size2, float sizeParm, vec3_t rgb1, vec3_t rgb2, float rgbParm, int killTime, int flags = 0 ) { if ( theFxHelper.mFrameTime < 1 ) { // disallow adding effects when the system is paused return 0; } CLight *fx = new CLight; if ( fx ) { fx->SetOrigin1( org ); // RGB---------------- fx->SetRGBStart( rgb1 ); fx->SetRGBEnd( rgb2 ); if (( flags & FX_RGB_PARM_MASK ) == FX_RGB_WAVE ) { fx->SetRGBParm( rgbParm * PI * 0.001f ); } else if ( flags & FX_RGB_PARM_MASK ) { // rgbParm should be a value from 0-100.. fx->SetRGBParm( rgbParm * 0.01f * killTime + theFxHelper.mTime ); } // Size---------------- fx->SetSizeStart( size1 ); fx->SetSizeEnd( size2 ); if (( flags & FX_SIZE_PARM_MASK ) == FX_SIZE_WAVE ) { fx->SetSizeParm( sizeParm * PI * 0.001f ); } else if ( flags & FX_SIZE_PARM_MASK ) { fx->SetSizeParm( sizeParm * 0.01f * killTime + theFxHelper.mTime ); } fx->SetFlags( flags ); FX_AddPrimitive( (CEffect**)&fx, killTime ); // in the editor, fx may now be NULL } return fx; }
//============================================================================= // 初期化 //============================================================================= HRESULT CRenderer :: Init(HWND hWnd,BOOL bWindow) { //ライト CLight* pLight; D3DPRESENT_PARAMETERS d3dpp; D3DDISPLAYMODE d3ddm; // Direct3Dオブジェクトの生成 m_pD3D = Direct3DCreate9(D3D_SDK_VERSION); if(m_pD3D == NULL) { return E_FAIL; } // 現在のディスプレイモードを取得 if(FAILED(m_pD3D->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &d3ddm))) { return E_FAIL; } // デバイスのプレゼンテーションパラメータの設定 ZeroMemory(&d3dpp, sizeof(d3dpp)); // ワークをゼロクリア d3dpp.BackBufferCount = 1; // バックバッファの数 d3dpp.BackBufferWidth = SCREEN_WIDTH; // ゲーム画面サイズ(幅) d3dpp.BackBufferHeight = SCREEN_HEIGHT; // ゲーム画面サイズ(高さ) d3dpp.BackBufferFormat = D3DFMT_UNKNOWN; // バックバッファのフォーマットは現在設定されているものを使う d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; // 映像信号に同期してフリップする d3dpp.Windowed = bWindow; // ウィンドウモード d3dpp.EnableAutoDepthStencil = TRUE; // デプスバッファ(Zバッファ)とステンシルバッファを作成 d3dpp.AutoDepthStencilFormat = D3DFMT_D24S8; // デプスバッファとして16bitを使う if(bWindow) {// ウィンドウモード d3dpp.BackBufferFormat = D3DFMT_UNKNOWN; // バックバッファ d3dpp.FullScreen_RefreshRateInHz = 0; // リフレッシュレート d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE; // インターバル } else {// フルスクリーンモード d3dpp.BackBufferFormat = D3DFMT_R5G6B5; // バックバッファ d3dpp.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT; // リフレッシュレート d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_DEFAULT; // インターバル } // デバイスオブジェクトの生成 // [デバイス作成制御]<描画>と<頂点処理>をハードウェアで行なう if(FAILED(m_pD3D->CreateDevice(D3DADAPTER_DEFAULT, // ディスプレイアダプタ D3DDEVTYPE_HAL, // ディスプレイタイプ hWnd, // フォーカスするウインドウへのハンドル D3DCREATE_HARDWARE_VERTEXPROCESSING, // デバイス作成制御の組み合わせ &d3dpp, // デバイスのプレゼンテーションパラメータ &m_pD3DDevice))) // デバイスインターフェースへのポインタ { // 上記の設定が失敗したら // [デバイス作成制御]<描画>をハードウェアで行い、<頂点処理>はCPUで行なう if(FAILED(m_pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &m_pD3DDevice))) { // 上記の設定が失敗したら // [デバイス作成制御]<描画>と<頂点処理>をCPUで行なう if(FAILED(m_pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_REF, hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &m_pD3DDevice))) { // 初期化失敗 return E_FAIL; } } } //様々なオブジェクトの初期化処理 //レンダーステートパラメータの設定 m_pD3DDevice->SetRenderState(D3DRS_CULLMODE,D3DCULL_CCW); m_pD3DDevice->SetRenderState(D3DRS_ZENABLE,TRUE); m_pD3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE,TRUE); m_pD3DDevice->SetRenderState(D3DRS_SRCBLEND,D3DBLEND_SRCALPHA); m_pD3DDevice->SetRenderState(D3DRS_DESTBLEND,D3DBLEND_INVSRCALPHA); // サンプラーステートパラメータの設定 m_pD3DDevice->SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_WRAP); // テクスチャアドレッシング方法(U値)を設定 m_pD3DDevice->SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_WRAP); // テクスチャアドレッシング方法(V値)を設定 m_pD3DDevice->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR); // テクスチャ縮小フィルタモードを設定 m_pD3DDevice->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR); // テクスチャ拡大フィルタモードを設定 // テクスチャステージステートの設定 m_pD3DDevice->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE); // アルファブレンディング処理 m_pD3DDevice->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE); // 最初のアルファ引数 m_pD3DDevice->SetTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_CURRENT); // 2番目のアルファ引数 m_nCountform=0; pLight=new CLight; pLight->Init(m_pD3DDevice); m_pCamera= new CCamera; m_pCamera->Init(); if(pLight!=NULL) { delete pLight; pLight=NULL; } m_bWirerFlag=false; return S_OK; }
void CShader_Deferred::Update() { CLight* light = GetGame()->GetRenderSystem()->GetCurLight(); // Pass light data to shader GLuint lightTypeID = glGetUniformLocation(GetGame()->GetRenderSystem()->GetCurShader()->GetID(), "lightType"); if (lightTypeID != -1) glUniform1i(lightTypeID, light->GetType()); GLuint lightDiffuseID = glGetUniformLocation(GetGame()->GetRenderSystem()->GetCurShader()->GetID(), "lightDiffuse"); if (lightDiffuseID != -1) glUniform3f(lightDiffuseID, light->GetDiffuse().x, light->GetDiffuse().y, light->GetDiffuse().z); GLuint lightAmbientID = glGetUniformLocation(GetGame()->GetRenderSystem()->GetCurShader()->GetID(), "lightAmbient"); if (lightAmbientID != -1) glUniform3f(lightAmbientID, light->GetAmbient().x, light->GetAmbient().y, light->GetAmbient().z); GLuint lightSpecularID = glGetUniformLocation(GetGame()->GetRenderSystem()->GetCurShader()->GetID(), "lightSpecular"); if (lightSpecularID != -1) glUniform3f(lightSpecularID, light->GetSpecular().x, light->GetSpecular().y, light->GetSpecular().z); GLuint lightPowerID = glGetUniformLocation(GetGame()->GetRenderSystem()->GetCurShader()->GetID(), "lightPower"); if (lightPowerID != -1) glUniform1f(lightPowerID, light->GetPower()); GLuint lightPosID = glGetUniformLocation(GetGame()->GetRenderSystem()->GetCurShader()->GetID(), "lightPos"); if (lightPosID != -1) glUniform3f(lightPosID, light->GetViewSpacePos().x, light->GetViewSpacePos().y, light->GetViewSpacePos().z); GLuint lightAngleID = glGetUniformLocation(GetGame()->GetRenderSystem()->GetCurShader()->GetID(), "lightAngle"); if (lightAngleID != -1) glUniform3f(lightAngleID, light->GetViewSpaceAngles().x, light->GetViewSpaceAngles().y, light->GetViewSpaceAngles().z); // Point light data GLuint cAttID = glGetUniformLocation(GetGame()->GetRenderSystem()->GetCurShader()->GetID(), "constAtt"); if (cAttID != -1) glUniform1f(cAttID, light->GetConstantAtt()); GLuint lAttID = glGetUniformLocation(GetGame()->GetRenderSystem()->GetCurShader()->GetID(), "linAtt"); if (lAttID != -1) glUniform1f(lAttID, light->GetLinearAtt()); GLuint qAttID = glGetUniformLocation(GetGame()->GetRenderSystem()->GetCurShader()->GetID(), "quadAtt"); if (qAttID != -1) glUniform1f(qAttID, light->GetQuadraticAtt()); GLuint spotCutoffID = glGetUniformLocation(GetGame()->GetRenderSystem()->GetCurShader()->GetID(), "spotCosCutoff"); if (qAttID != -1) glUniform1f(spotCutoffID, light->GetSpotCutoff()); GLuint spotExpID = glGetUniformLocation(GetGame()->GetRenderSystem()->GetCurShader()->GetID(), "spotExp"); if (qAttID != -1) glUniform1f(spotExpID, light->GetSpotExponent()); }
//----------------------------------------------------------------------------------------- TestTransformation::TestTransformation() : m_bPressed(false) , m_bTouch(false) , m_StartPan(-1, -1) , m_LastPan(-1, -1) { // On cr�e une camera CCamera* pCamera = m_pSceneManager->createCamera(); m_vNewEyePosition = QVector3D(8., 8., 4.); pCamera->setEyePosition(m_vNewEyePosition); pCamera->setCenter(QVector3D(0., 0., 0.)); qDebug() << "Create View"; m_pView = createWidget3D(pCamera); m_pView->setAttribute(Qt::WA_AcceptTouchEvents); qDebug() << "End create View"; // On cr�e un noeud afin d'y placer une lumi�re CSceneNode* pRootNode = getSceneManager()->getRootNode(); // On cr�e une lumi�re diffuse bleue CLight* pLight = getSceneManager()->createLight(); pLight->setDiffuseColor(1.0, 1.0, 1.0); pLight->setAmbientColor(1.0, 1.0, 1.0); pLight->setDirection(QVector3D(-1, 0, 0)); pLight->setSpecularColor(1.0f, 1.0f, 1.0f); // On l'associe au noeud pRootNode->addItem(pLight); // SkyBox CSkyBox* pSkyBoxMesh = CMeshManager::getInstance().createCustomMesh<CSkyBox>("CSkyBox", "SkyBoxMesh"); CMeshInstance* pSkyBox = getSceneManager()->createMeshInstance(pSkyBoxMesh, "SkyBox"); pSkyBox->setSelectable(false); CSceneNode* pSkyBoxNode = pRootNode->createChild("SkyBoxNode"); pSkyBoxNode->scale(400.); pSkyBoxNode->addItem(pSkyBox); CMaterial* pSkyBoxMat = CMaterialManager::getInstance().createMaterial("SkyBoxMaterial"); pSkyBox->setMaterialName(pSkyBoxMat->getName()); QStringList fileNames; fileNames << "://Resources/xpos.png" << "://Resources/xneg.png" << "://Resources/ypos.png" << "://Resources/yneg.png" << "://Resources/zpos.png" << "://Resources/zneg.png"; ATexture* pSkyBoxTexture = CTextureManager::getInstance().createTextureCube("SkyBoxTexCube", fileNames); pSkyBoxMat->addTexture(pSkyBoxTexture, eDiffuse); #ifdef EMBEDDED_TARGET CShader* pShader = CShaderManager::getInstance().createShader( "SkyBoxShader", "://Resources/skyboxES.vertex.glsl", "", "://Resources/skyboxES.fragment.glsl"); #else CShader* pShader = CShaderManager::getInstance().createShader( "SkyBoxShader", "://Resources/skybox.vertex.glsl", "", "://Resources/skybox.fragment.glsl"); #endif pSkyBoxMat->getRenderPass(0)->setShaderName(pShader->getName()); pSkyBoxMat->getRenderPass(0)->renderStates().setFaceCulling(CFaceCulling(false)); // Particules CBillboard* pBillboard = getSceneManager()->createBillboard(); QVector<QVector3D> pos; for (int i = 0; i < 1000; ++i) pos << QVector3D( Math::randDouble(-200., +200.), Math::randDouble(-200., +200.), Math::randDouble(-200., +200.)); pBillboard->addPositions(pos); CMaterial* pBillboardMat = CMaterialManager::getInstance().createMaterial("BillboardMaterial"); pBillboardMat->getRenderPass(0)->renderStates().setFaceCulling(CFaceCulling(false)); CBlending blending; blending.setEnabled(true); blending.setBlendEquation(eAdd, eAdd); blending.setBlendSeparateFunction(Source::eSourceAlpha, Destination::eOneMinusSourceAlpha, Source::eOne, Destination::eZero); pBillboardMat->getRenderPass(0)->renderStates().setBlending(blending); ATexture* pBillboardTexture = CTextureManager::getInstance().createTexture2D("BillBoardTex", "://Resources/particle.png"); pBillboardMat->addTexture(pBillboardTexture, eDiffuse); CShader* pBillboardShader = CShaderManager::getInstance().createShader("BillboardShader", "://Resources/billboard.vertex.glsl", "://Resources/billboard.geometry.glsl", "://Resources/billboard.fragment.glsl"); pBillboardMat->getRenderPass(0)->setShaderName(pBillboardShader->getName()); pBillboard->setMaterialName(pBillboardMat->getName()); pBillboardShader->setUniformValue("halfSize", 1.); CSceneNode* pBillboardNode = pRootNode->createChild("BillboardNode"); pBillboardNode->addItem(pBillboard); // Orbites CPolyLine* pPolyLine = CMeshManager::getInstance().createCustomMesh<CPolyLine>("CPolyLine", "CPolyLine"); QList<QVector3D> pts; for (int i = 0; i <= 360; ++i) { pts << QVector3D(cos(Math::degToRad((real)i)), 0., sin(Math::degToRad((real)i))); } pPolyLine->addPoints(pts); CSphereMesh* pSphereMesh = CMeshManager::getInstance().createCustomMesh<CSphereMesh>("CSphereMesh", "SphereMesh"); CMeshInstance* pSun = getSceneManager()->createMeshInstance(pSphereMesh, "Sun"); CMaterial* pSunMat = CMaterialManager::getInstance().createMaterial("SunMat"); pSunMat->setAmbientColor(1., 1., 1.); CTexture2D* pSunTexture = CTextureManager::getInstance().createTexture2D("SunTex", ":/Resources/sun.png"); pSunMat->addTexture(pSunTexture, eDiffuse); pSun->setMaterialName(pSunMat->getName()); CMeshInstance* pEarth = getSceneManager()->createMeshInstance(pSphereMesh, "Earth"); CMaterial* pEarthMat = CMaterialManager::getInstance().createMaterial("EarthMat"); CTexture2D* pEarthTexture = CTextureManager::getInstance().createTexture2D("EarthTex", ":/Resources/earth.png"); pEarthMat->addTexture(pEarthTexture, eDiffuse); pEarthMat->setAmbientColor(0.1, 0.1, 0.1); pEarthMat->setDiffuseColor(1.0, 1.0, 1.0); pEarthMat->setShininessFactor(10); pEarth->setMaterialName(pEarthMat->getName()); CMeshInstance* pJupiter = getSceneManager()->createMeshInstance(pSphereMesh, "Jupiter"); CMaterial* pJupiterMat = CMaterialManager::getInstance().createMaterial("JupiterMat"); pJupiterMat->setAmbientColor(0.4, 0.4, 0.4); CTexture2D* pJupiterTexture = CTextureManager::getInstance().createTexture2D("JupiterTex", ":/Resources/jupiter.png"); pJupiterMat->addTexture(pJupiterTexture, eDiffuse); pJupiter->setMaterialName(pJupiterMat->getName()); CMeshInstance* pMoon = getSceneManager()->createMeshInstance(pSphereMesh, "Moon"); CMaterial* pMoonMat = CMaterialManager::getInstance().createMaterial("MoonMat"); CTexture2D* pMoonTexture = CTextureManager::getInstance().createTexture2D("MoonTex", ":/Resources/moon.png"); pMoonMat->addTexture(pMoonTexture, eDiffuse); pMoon->setMaterialName(pMoonMat->getName()); CCoordinateSystem* pCoordinateSystemMesh = CMeshManager::getInstance().createCustomMesh<CCoordinateSystem>("CCoordinateSystem", "CCoordinateSystem"); CMeshInstance* pCoordinateSystem = getSceneManager()->createMeshInstance(pCoordinateSystemMesh, "CoordinateSystem"); pRootNode->addItem(pCoordinateSystem); pRootNode->addItem(pSkyBox); m_pSolarSystemNode = pRootNode->createChild(QVector3D(0., 0., 0.)); m_pSunNode = m_pSolarSystemNode->createChild(QVector3D(0., 0., 0.)); m_pSunNode->scale(4.0); m_pSunNode->addItem(pSun); m_pSunToEarthNode = m_pSolarSystemNode->createChild(); m_pSunToJupiterNode = m_pSolarSystemNode->createChild(); CMeshInstance* pSunToEarthPLine = getSceneManager()->createMeshInstance(pPolyLine, "SunToEarth"); pSunToEarthPLine->setMaterialName(CMaterialManager::getInstance().getMaterialNameByColor(Color::eWhite)); m_pSunToEarthNode->addItem(pSunToEarthPLine); m_pSunToEarthNode->scale(10.0); m_pEarthNode = m_pSolarSystemNode->createChild(QVector3D(10.0, 0., 0.)); m_pEarthNode->scale(1.0); m_pEarthNode->addItem(pEarth); CMeshInstance* pSunToJupiterPLine = getSceneManager()->createMeshInstance(pPolyLine, "SunToJupiter"); pSunToJupiterPLine->setMaterialName(CMaterialManager::getInstance().getMaterialNameByColor(Color::eWhite)); m_pSunToJupiterNode->addItem(pSunToJupiterPLine); m_pSunToJupiterNode->scale(20); m_pJupiterNode = m_pSolarSystemNode->createChild(QVector3D(20.0, 0., 0.)); m_pJupiterNode->scale(4.0); m_pJupiterNode->addItem(pJupiter); m_pEarthToMoonNode = m_pEarthNode->createChild(); CMeshInstance* pEarthToMoonPLine = getSceneManager()->createMeshInstance(pPolyLine, "EarthToMoon"); pEarthToMoonPLine->setMaterialName(CMaterialManager::getInstance().getMaterialNameByColor(Color::eWhite)); m_pEarthToMoonNode->addItem(pEarthToMoonPLine); m_pEarthToMoonNode->scale(2.0); m_pEarthToMoonNode->rotate(QVector3D(1.0, 0.0, 0.0), 30); m_pMoonNode = m_pEarthToMoonNode->createChild(QVector3D(1.0, 0.0, 0.)); m_pMoonNode->scale(0.2); m_pMoonNode->addItem(pMoon); QTimer* pTimer = new QTimer(this); connect(pTimer, SIGNAL(timeout()), this, SLOT(onTimeout())); pTimer->start(5); connect(m_pView, SIGNAL(mouseMoved()), this, SLOT(onMouseMoved())); connect(m_pView, SIGNAL(mouseReleased()), this, SLOT(onMouseReleased())); connect(m_pView, SIGNAL(mousePressed()), this, SLOT(onMousePressed())); connect(m_pView, SIGNAL(touchScaleStarted()), this, SLOT(onTouchScaleStarted())); connect(m_pView, SIGNAL(touchScaleChanged(real)), this, SLOT(onTouchScaleChanged(real))); connect(m_pView, SIGNAL(touchScaleEnded()), this, SLOT(onTouchScaleEnded())); //m_pView->setGeometry(QRect(1920, 100, 400, 300)); m_GlobalTime.start(); }
//------------------------- // FX_AddLight //------------------------- CLight *FX_AddLight( vec3_t org, float size1, float size2, float sizeParm, vec3_t rgb1, vec3_t rgb2, float rgbParm, int killTime, int flags = 0, EMatImpactEffect matImpactFX /*MATIMPACTFX_NONE*/, int fxParm /*-1*/, int iGhoul2/*0*/, int entNum/*-1*/, int modelNum/*-1*/, int boltNum/*-1*/) { if ( theFxHelper.mFrameTime < 0 ) { // disallow adding effects when the system is paused return 0; } CLight *fx = new CLight; if ( fx ) { if (flags&FX_RELATIVE && iGhoul2>0) { fx->SetOrigin1( NULL ); fx->SetOrgOffset( org );//offset fx->SetBoltinfo( iGhoul2, entNum, modelNum, boltNum ); } else { fx->SetOrigin1( org ); } fx->SetMatImpactFX(matImpactFX); fx->SetMatImpactParm(fxParm); // RGB---------------- fx->SetRGBStart( rgb1 ); fx->SetRGBEnd( rgb2 ); if (( flags & FX_RGB_PARM_MASK ) == FX_RGB_WAVE ) { fx->SetRGBParm( rgbParm * PI * 0.001f ); } else if ( flags & FX_RGB_PARM_MASK ) { // rgbParm should be a value from 0-100.. fx->SetRGBParm(rgbParm * 0.01f * killTime + theFxHelper.mTime + theFxHelper.mTimeFraction); } // Size---------------- fx->SetSizeStart( size1 ); fx->SetSizeEnd( size2 ); if (( flags & FX_SIZE_PARM_MASK ) == FX_SIZE_WAVE ) { fx->SetSizeParm( sizeParm * PI * 0.001f ); } else if ( flags & FX_SIZE_PARM_MASK ) { fx->SetSizeParm(sizeParm * 0.01f * killTime + theFxHelper.mTime + theFxHelper.mTimeFraction); } fx->SetFlags( flags ); FX_AddPrimitive( (CEffect**)&fx, killTime ); } return fx; }
void Moose::Graphics::UniformLights::SetData(int index, CLight & l, COglRenderer & r ) { enabled[index].SetData(l.IsEnabled()); diffuse[index].SetData(&l.GetDiffuseColor()); ambient[index].SetData(&l.GetAmbientColor()); specular[index].SetData(&l.GetSpecularColor()); position[index].SetData(&l.GetPosition()); direction[index].SetData(&l.GetDirection()); halfVector[index].SetData((r.GetCurrentCamera()->GetPosition()-l.GetPosition()).GetNormalized()); spotAngle[index].SetData(l.GetSpotAngle()); spotExponent[index].SetData(l.GetSpotExponent()); constantAttenuation[index].SetData(l.GetConstantAttenuation()); linearAttenuation[index].SetData(l.GetLinearAttenuation()); quadraticAttenuation[index].SetData(l.GetQuadraticAttenuation()); }