void CommandSystem::Draw() { if (!mCommandMode) return; int nHeight = GetApp()->getHeight() * 0.7f; GetApp()->text_->SetInsertionPos(50, nHeight); GetApp()->text_->SetForegroundColor(D3DXCOLOR(0.0f, 0.0f, 0.0f, 1.0f)); GetApp()->text_->DrawFormattedTextLine(mStatusLine.c_str()); idStr displayString = "edit"; GetApp()->text_->SetInsertionPos(50, nHeight+10); displayString += "> "; displayString += mCommand.c_str(); if (timeGetTime() & 0x200) { displayString += "_"; } GetApp()->text_->DrawFormattedTextLine(displayString.c_str()); }
GameObject::GameObject(int textureIndex, float scale, float posX, float posY, float posZ, float dur, PositionType tPos) : // myMesh(NULL), //position(&v.Position), //color(&v.Color), tObject(SPRITE), tPosition(tPos), velocity(0,0,0), lookDirection(1,0,0), mMeshOirentation(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1), duration(dur), parent(NULL) { myVertex.TextureIndex = textureIndex; myVertex.AnimationSize = 0; myVertex.AnimationProgress = 0; myVertex.Opacity = 1.f; SetColor(D3DXCOLOR(0,0,0,0)); ScaleTo(scale); TranslateTo(posX,posY,posZ); RotateTo(0,0,0); }
GameObject::GameObject(Mesh* m, float& posX, float& posY, float& posZ, float& scale, float& rotX, float& rotY, float& rotZ, float dur,PositionType tPos) : //position(NULL), //color(&myMesh.Color), tObject(MESH), tPosition(tPos), velocity(0,0,0), lookDirection(1,0,0), mMeshOirentation(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1), duration(dur), parent(NULL) { myMesh.MeshToRender = m; myMesh.Position = D3DXVECTOR3(posX, posY, posZ);; //position = &myMesh.Position; myMesh.Color = D3DXCOLOR(0,0,0,0); //color = &myMesh.Color; myMesh.Scale = D3DXVECTOR3(scale, scale, scale); calcScale(); calcTranslation(); RotateTo(rotX, rotY, rotZ); }
Sprite::Sprite(ID3D10Device* p_d3dDevice, float p_x, float p_y, float p_width, float p_height, char* p_fileName, D3D10_VIEWPORT* p_viewPort) { m_d3dDevice = p_d3dDevice; m_viewPort = p_viewPort; // Set the sprite's shader resource view m_imageSprite.pTexture = createTex(p_fileName); m_x = p_x; m_y = p_y; m_posX = m_x; m_posY = m_y; m_height = p_height; m_width = p_width; // top-left location in U,V coords m_imageSprite.TexCoord.x = 0; m_imageSprite.TexCoord.y = 0; // Determine the texture size in U,V coords m_imageSprite.TexSize.x = 1.0f; m_imageSprite.TexSize.y = 1.0f; // Set the texture index. Single textures will use 0 m_imageSprite.TextureIndex = 0; m_imageSprite.ColorModulate = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f); D3DXMatrixIdentity(&m_matTranslate); D3DXMatrixIdentity(&m_matScale); D3DXMatrixScaling(&m_matScale, m_width, m_height, 1.0f); m_anchorPoint = NORMAL; m_centerX = false; }
KG3DSFXBillboard::KG3DSFXBillboard(KG3DSFX *pSFX) { ASSERT(pSFX); m_pSFX = pSFX; m_pTexture = NULL; m_dwCuttingNum = 1; m_pTexture2 = NULL; m_dwCuttingNum2 = 1; m_fCurrentFrame = -1; //m_bLockAxis = FALSE; //m_bRotation = FALSE; m_bBindToBone = FALSE; m_strBoneName = ""; m_vPositionLine.InsertKeyFrame(0, D3DXVECTOR3(0, 0, 0)); m_fWidthTimeLine.InsertKeyFrame(0, 50); m_fHeightTimeLine.InsertKeyFrame(0, 50); m_DiffuseTimeLine.InsertKeyFrame(0, D3DXCOLOR(1, 1, 1, 1)); m_nTextureFrameIndex.InsertKeyFrame(0, 0); m_nTexture2FrameIndex.InsertKeyFrame(0, 0); m_vUVTimeLine.InsertKeyFrame(0, D3DXVECTOR2(0, 0)); m_fRotationTimeLine.InsertKeyFrame(0, 0.f); m_dwBindTrackIndex = SFX_NOT_BIND_TO_TRACK; m_Rotation = 0.f; m_Translation = D3DXVECTOR3(0, 0, 0); m_eBlendMode = SFX_BM_SRCALPHA_INVSRCALPHA; m_dwRenderTargetTexFlag = 0; m_dwBillBoradType = BILLBOARE_TYPE_NORMAL; m_pVB = NULL; m_fHeight = 0.f; m_fWidth = 0.f; }
void MakeStackIcon::onRender(uint flags) { if (!enabled) return; #ifdef DXRENDER D3DMATERIAL9 stackIconMaterial = dxr->textureMaterial; stackIconMaterial.Diffuse = D3DXCOLOR(1, 1, 1, ease(alpha)); dxr->device->SetMaterial(&stackIconMaterial); Mat33 orientation(NxQuat(90, Vec3(1,0,0))); dxr->renderSideLessBox(Vec3(position.x, 10, position.z), orientation, Vec3(size / 2.0f, -size / 2.0f, 1), texMgr->getGLTextureId("widget.vertStack")); dxr->device->SetMaterial(&dxr->textureMaterial); #else glPushAttribToken token(GL_ENABLE_BIT); //glColor4f(72.0f/255., 149.0f/255., 234.0f/255., 1.0); if (alpha == 1.0) glColor4d(1, 1, 1, 1); else glColor4d(1, 1, 1, ease(alpha)); glDisable(GL_DEPTH_TEST); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, texMgr->getGLTextureId("widget.vertStack")); glEnable(GL_BLEND); glPushMatrix(); glTranslated(position.x, 0, position.z); glScalef(size / 2.0f, 0.2f, size / 2.0f); glBegin(GL_TRIANGLE_FAN); { glNormal3f(0,1,0); glTexCoord2f(1,1); glVertex3f(-1,1,1); glTexCoord2f(0,1); glVertex3f(1,1,1); glTexCoord2f(0,0); glVertex3f(1,1,-1); glTexCoord2f(1,0); glVertex3f(-1,1,-1); } glEnd(); glPopMatrix(); #endif }
PyObject * textTailAttachTitle(PyObject * poSelf, PyObject * poArgs) { int iVirtualID; if (!PyTuple_GetInteger(poArgs, 0, &iVirtualID)) return Py_BuildException(); char * szName; if (!PyTuple_GetString(poArgs, 1, &szName)) return Py_BuildException(); float fr; if (!PyTuple_GetFloat(poArgs, 2, &fr)) return Py_BuildException(); float fg; if (!PyTuple_GetFloat(poArgs, 3, &fg)) return Py_BuildException(); float fb; if (!PyTuple_GetFloat(poArgs, 4, &fb)) return Py_BuildException(); CPythonTextTail::Instance().AttachTitle(iVirtualID, szName, D3DXCOLOR(fr, fg, fb, 1.0f)); return Py_BuildNone(); }
static void CALLBACK OnFrameRender(IDirect3DDevice9* pDev, double time, float elapsedTime, void* userContext) { pDev->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DXCOLOR(0.1f, 0.3f, 0.6f, 0.0f), 1.0f, 0); if (SUCCEEDED(pDev->BeginScene())) { #if 0 pDev->SetTransform(D3DTS_WORLD, &g_matrixWorld); pDev->SetTransform(D3DTS_VIEW, &g_matrixView); pDev->SetTransform(D3DTS_PROJECTION, &g_matrixProjection); pDev->SetLight(0, &g_light); pDev->LightEnable(0, TRUE); pDev->SetMaterial(&g_material); //pDev->SetRenderState(D3DRS_FILLMODE, D3DFILL_WIREFRAME); pDev->SetRenderState(D3DRS_SPECULARENABLE,TRUE); #else cgD3D9BindProgram(g_cgVertexProgram); checkForCgError("binding vertex program"); #endif cgSetParameterValuefc(g_cgWorldMatrix, 16, g_matrixWorld.m[0]); cgSetParameterValuefc(g_cgWorldViewProjMatrix, 16, g_matrixWorldViewProj.m[0]); cgSetParameterValuefc(g_cgAmbient, 3, (float*)&g_light.Ambient); cgSetParameterValuefc(g_cgLightColor, 3, (float*)&g_light.Diffuse); cgSetParameterValuefc(g_cgLightPos, 3, (float*)&g_light.Position); cgSetParameterValuefc(g_cgEyePos, 3, (float*)&g_eyePos); cgSetParameterValuefc(g_cgKe, 3, (float*)&g_material.Emissive); cgSetParameterValuefc(g_cgKa, 3, (float*)&g_material.Ambient); cgSetParameterValuefc(g_cgKd, 3, (float*)&g_material.Diffuse); cgSetParameterValuefc(g_cgKs, 3, (float*)&g_material.Specular); cgSetParameterValuefc(g_cgShininess, 3, &g_material.Power); g_pMeshSphere->DrawSubset(0); pDev->EndScene(); } }
//-------------------------------------------------------------------------------------- // Render the scene using the D3D11 device //-------------------------------------------------------------------------------------- void CALLBACK OnD3D11FrameRender( ID3D11Device* pd3dDevice, ID3D11DeviceContext* pd3dImmediateContext, double fTime, float fElapsedTime, void* pUserContext ) { // Clear render target and the depth stencil float ClearColor[4] = { 0.176f, 0.196f, 0.667f, 0.0f }; ID3D11RenderTargetView* pRTV = DXUTGetD3D11RenderTargetView(); ID3D11DepthStencilView* pDSV = DXUTGetD3D11DepthStencilView(); pd3dImmediateContext->ClearRenderTargetView( pRTV, ClearColor ); pd3dImmediateContext->ClearDepthStencilView( pDSV, D3D11_CLEAR_DEPTH, 1.0, 0 ); vegetationRendering->draw(pd3dDevice, GameTime(fElapsedTime, fTime)); std::wstringstream ws; ws << DXUTGetFPS(); textHelper.Begin(); textHelper.SetInsertionPos(5, 5); textHelper.SetForegroundColor(vegetationRendering->isInCaptureMode() ? D3DXCOLOR(1,0,0,1) : D3DXCOLOR(1, 1, 0, 1)); textHelper.DrawTextLine(ws.str().c_str()); textHelper.End(); }
EFFECT_LENSFLARE::EFFECT_LENSFLARE(IDirect3DDevice9 *Dev, int _type, D3DXVECTOR3 _position) : EFFECT(Dev) { m_position = _position; m_type = _type; m_mainAlpha = 0.0f; m_inScreen = false; //Add Flares if(m_type == 0) //Standard flare { m_flares.push_back(FLARE(D3DXCOLOR(1.0f, 1.0f, 0.5f, 1.0f), 0.5f, 0.7f, 0)); m_flares.push_back(FLARE(D3DXCOLOR(0.0f, 1.0f, 0.5f, 1.0f), 1.0f, 1.0f, 1)); m_flares.push_back(FLARE(D3DXCOLOR(1.0f, 0.5f, 0.5f, 1.0f), 1.5f, 1.3f, 2)); m_flares.push_back(FLARE(D3DXCOLOR(1.0f, 1.0f, 0.5f, 1.0f), -0.5f, 0.8f, 3)); m_flares.push_back(FLARE(D3DXCOLOR(0.0f, 1.0f, 0.5f, 1.0f), 0.4f, 1.0f, 4)); m_flares.push_back(FLARE(D3DXCOLOR(1.0f, 1.0f, 0.5f, 1.0f), 0.75f, 1.0f, 5)); m_flares.push_back(FLARE(D3DXCOLOR(0.0f, 0.0f, 1.0f, 1.0f), 1.8f, 1.2f, 6)); m_flares.push_back(FLARE(D3DXCOLOR(1.0f, 1.0f, 0.5f, 1.0f), 2.1f, 0.5f, 4)); } else if(m_type == 1) //Some other flare etc... { //setup your own flare here... } }
void HippoUI_RenderD3D9::DrawSprite(HippoUI_Rect& rect,HippoUI_TextureProxy* pTexProxy,HippoUi_Color& color) { //return; IDirect3DTexture9* pTex=(IDirect3DTexture9*)(pTexProxy->GetHardwareTexturePtr()); //calc scale D3DXMATRIXA16 matTransform; D3DXMatrixIdentity(&matTransform); float scale_x=( float )rect.GetWidth()/pTexProxy->GetRect().GetWidth(); float scale_y=( float )rect.GetHeight()/pTexProxy->GetRect().GetHeight(); D3DXMatrixScaling( &matTransform, scale_x, scale_y, 1.0f ); m_pSprite->SetTransform(&matTransform); D3DXVECTOR3 vPos( ( float )rect.left, ( float )rect.top, 0.0f ); vPos.x /= scale_x; vPos.y /= scale_y; HRESULT res=m_pSprite->Draw(pTex,pTexProxy->GetRect().GetRECT(),0,&vPos,D3DXCOLOR( color.r, color.g, color.b, color.a )); if(FAILED(res)) { ReportErr("sprite draw failed"); } }
// render a single frame void render_frame(void) { // clear the render target (this should be the back buffer) to a deep blue g_dev_context_ptr->ClearRenderTargetView(g_render_target_ptr, D3DXCOLOR(0.0f, 0.2f, 0.4f, 1.0f)); // do 3D render to the render target (this should be the back buffer) // select which vertex buffer to display (we only have one, so this is simple) UINT stride = sizeof(MY_VERTEX); UINT offset = 0; g_dev_context_ptr->IASetVertexBuffers(0, 1, &g_vertex_buffer_ptr, &stride, &offset); // select the drawing routine for the primitives that will be drawn g_dev_context_ptr->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST); // draw the vertex buffer to the render target g_dev_context_ptr->Draw(3, 0); // switch the back buffer and the front buffer g_swap_chain_ptr->Present(0, 0); }
GameSprite::GameSprite(int width, int height) { originalSize.x = (float)width; originalSize.y = (float)height; frameSize.x = (float)Stats::getTilesize(); frameSize.y = (float)Stats::getTilesize(); position.x = 0; position.y = 0; position.z = 0; scale.x = 1; scale.y = 1; velocity = D3DXVECTOR2(0,0); texCoord = D3DXVECTOR2(0,0); color = D3DXCOLOR(1, 1, 1, 1); hasAnimation = false; animationPos = 0; numFrames = width / Stats::getTilesize(); timePerFrame = 200; animationRow = 0; sprite = new D3DX10_SPRITE(); }
// the entry point for any Windows program int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { EngineConfig config; // TODO: // Load this from a file. ZeroMemory(&config, sizeof(EngineConfig)); config.screen_width = 800; config.screen_height = 600; config.min_world_coords = D3DXVECTOR3(-5000.0f, -5000.0f, -5000.0f); config.max_world_coords = D3DXVECTOR3(5000.0f, 5000.0f, 5000.0f); config.num_octree_levels = 4; config.near_clip = 0.1f; config.far_clip = 5000.0f; config.fov = 45.0f; config.ambient_color = D3DXVECTOR3(0.1f, 0.1f, 0.1f); config.background_color = D3DXCOLOR(0.0f, 0.0f, 0.0f, 0.0f); config.camera_speed = 0.06f; config.mouse_sensitivity = 0.01f; config.hInstance = hInstance; config.hPrevInstance = hPrevInstance; config.lpCmdLine = lpCmdLine; config.nCmdShow = nCmdShow; config.draw_debug_objects = false; config.window_class_name = "GameWindow"; config.window_caption = "Hi, this is 3D, coming to you in 2D(where available)"; g_engine = new Engine(config); InitObjects(); WPARAM main_loop_result = Engine::instance->MainLoop(); return main_loop_result; }
void CGrannyMaterial::__ApplySpecularRenderState() { if (TRUE == STATEMANAGER.GetRenderState(D3DRS_ALPHABLENDENABLE)) { __ApplyDiffuseRenderState(); return; } CGraphicTexture* pkTexture=ms_akSphereMapInstance[m_bSphereMapIndex].GetTexturePointer(); STATEMANAGER.SetTexture(0, GetD3DTexture(0)); if (pkTexture) STATEMANAGER.SetTexture(1, pkTexture->GetD3DTexture()); else STATEMANAGER.SetTexture(1, NULL); STATEMANAGER.SetRenderState(D3DRS_TEXTUREFACTOR, D3DXCOLOR(g_fSpecularColor.r, g_fSpecularColor.g, g_fSpecularColor.b, __GetSpecularPower())); STATEMANAGER.SaveTextureStageState(1, D3DTSS_TEXCOORDINDEX, D3DTSS_TCI_CAMERASPACEREFLECTIONVECTOR); STATEMANAGER.SaveTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE); STATEMANAGER.SaveTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE); STATEMANAGER.SaveTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE); STATEMANAGER.SaveTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE); STATEMANAGER.SaveTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_TFACTOR); STATEMANAGER.SaveTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE); STATEMANAGER.SetTextureStageState(1, D3DTSS_COLORARG1, D3DTA_CURRENT); STATEMANAGER.SetTextureStageState(1, D3DTSS_COLORARG2, D3DTA_TEXTURE); STATEMANAGER.SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_MODULATEALPHA_ADDCOLOR); STATEMANAGER.SetTextureStageState(1, D3DTSS_ALPHAARG1, D3DTA_CURRENT); STATEMANAGER.SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1); STATEMANAGER.SetTransform(D3DTS_TEXTURE1, &ms_matSpecular); STATEMANAGER.SaveTextureStageState(1, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT2); STATEMANAGER.SaveTextureStageState(1, D3DTSS_ADDRESSU, D3DTADDRESS_WRAP); STATEMANAGER.SaveTextureStageState(1, D3DTSS_ADDRESSV, D3DTADDRESS_WRAP); }
bool XModel::load(std::string filename, std::string texturedir) { LPD3DXBUFFER materialBuffer; HRESULT res; res = D3DXLoadMeshFromX(filename.c_str(), D3DXMESH_SYSTEMMEM, mamain->d3ddev, NULL, &materialBuffer, NULL, &materialCount, &mesh); if (FAILED(res)) { ErrorHandleCritical(mamain->err, mamain->errCrit, ErrorD3D9, res, "D3DXLoadMeshFromX"); return false; } D3DXMATERIAL* xMaterials = (D3DXMATERIAL* )materialBuffer->GetBufferPointer(); materials = new D3DMATERIAL9[materialCount]; textures = new LPDIRECT3DTEXTURE9[materialCount]; memset(materials, 0, materialCount * sizeof(D3DMATERIAL9)); memset(textures, 0, materialCount * sizeof(LPDIRECT3DTEXTURE9)); for (uint i = 0; i < materialCount; ++i) { materials[i] = xMaterials[i].MatD3D; materials[i].Ambient = D3DXCOLOR(0.0, 0.0, 0.0, 0.0); textures[i] = NULL; if (xMaterials[i].pTextureFilename != NULL && lstrlen(xMaterials[i].pTextureFilename) > 0) { std::string file = texturedir + '/' + xMaterials[i].pTextureFilename; res = D3DXCreateTextureFromFile(mamain->d3ddev, file.c_str(), &textures[i]); if (FAILED(res)) ErrorHandleCritical(mamain->err, mamain->errCrit, ErrorCreateTexFromFile, res, file); } } materialBuffer->Release(); return true; }
//-------------------------------------------------------------------------------------- void CDXUTTextHelper::Init( ID3DXFont* pFont9, ID3DXSprite* pSprite9, ID3DX10Font* pFont10, ID3DX10Sprite* pSprite10, int nLineHeight ) { m_pFont9 = pFont9; m_pSprite9 = pSprite9; m_pFont10 = pFont10; m_pSprite10 = pSprite10; m_clr = D3DXCOLOR( 1, 1, 1, 1 ); m_pt.x = 0; m_pt.y = 0; m_nLineHeight = nLineHeight; m_pFontBlendState10 = NULL; // Create a blend state if a sprite is passed in if( pSprite10 ) { ID3D10Device* pDev = NULL; pSprite10->GetDevice( &pDev ); if( pDev ) { D3D10_BLEND_DESC StateDesc; ZeroMemory( &StateDesc, sizeof( D3D10_BLEND_DESC ) ); StateDesc.AlphaToCoverageEnable = FALSE; StateDesc.BlendEnable[0] = TRUE; StateDesc.SrcBlend = D3D10_BLEND_SRC_ALPHA; StateDesc.DestBlend = D3D10_BLEND_INV_SRC_ALPHA; StateDesc.BlendOp = D3D10_BLEND_OP_ADD; StateDesc.SrcBlendAlpha = D3D10_BLEND_ZERO; StateDesc.DestBlendAlpha = D3D10_BLEND_ZERO; StateDesc.BlendOpAlpha = D3D10_BLEND_OP_ADD; StateDesc.RenderTargetWriteMask[0] = 0xf; pDev->CreateBlendState( &StateDesc, &m_pFontBlendState10 ); pDev->Release(); } } }
void D3DSample::SceneInit() { //GCTTest::RegisterTemplate(); //gctVisualSphere::RegisterTemplate(); GOTemplate* got = new GOTemplate("Test"); got->addGCTemplate(new gctVisualSphere); got->addGCTemplate(new GCTTest); GOTManager::getInstance()->registerTemplate(got); GOComponent* goc = new gocCamera(); GameObject* go = GOTManager::getInstance()->createGO("Test"); go->setGOComponent(goc); go->setPosition(vector3df(1.0f, 0.0f, 1.0f)); objects.push_back(go); //go = GOTManager::getInstance()->createGO("Test"); //objects.push_back(go); Graphics()->AddLight(D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f), vector3df(0.0f, 10.0f, 0.0f)); //Graphics()->AddLight(D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f), vector3df(1.0f, 0.0f, 0.0f).toD3DXVECTOR3()); }
HRESULT creditScene::Scene_Init() { _credit = new cBaseObject(); _credit->SetMesh(RESOURCE_STATICXMESH->GetResource("../Resources/OurModel/Credit/Credit.X")); _credit->SetActive(true); _credit->pTransform->SetScale({ 0.1f, 0.1f, 0.1f }); _credit->pTransform->SetLocalPosition(-2, 2, 5); m_pDirLight = new cLight_Direction(); m_pDirLight->pTransform->LookDirection(D3DXVECTOR3(1, 0, 1)); m_pDirLight->Color = D3DXCOLOR(1, 1, 1, 1); m_pDirLight->Intensity = 0.3f; lights.push_back(m_pDirLight); _fog = new titleFog(); _fog->Init(); _user = new cBaseObject(); _user->SetMesh(RESOURCE_STATICXMESH->GetResource("../Resources/OurModel/Credit/User.X")); _user->SetActive(true); _user->pTransform->SetScale({ 0.1f, 0.1f, 0.1f }); _user->pTransform->SetLocalPosition(2, -4, 5); return S_OK; }
void cParticlesFire::Update(float fDelta){ for (size_t i = 0; i < m_vecVertex.size(); i++){ m_vecVertex[i].p = m_vecVertex[i].p + (m_vecMoveInfo[i]._direction * m_vecMoveInfo[i]._speed * fDelta); float alpha = 1.0f - (m_vecMoveInfo[i]._currentTime / m_vecMoveInfo[i]._lifeSpan); if (alpha < 0.0f){ alpha = 0.0f; } m_vecVertex[i].c = D3DXCOLOR(128 / 255.0f, 80 / 255.0f, 13 / 255.0f, alpha); m_vecMoveInfo[i]._currentTime += fDelta; if (m_vecMoveInfo[i]._currentTime > m_vecMoveInfo[i]._lifeSpan){ m_vecMoveInfo[i]._currentTime = 0.0f; m_vecVertex[i].p = m_vecMoveInfo[i]._vInitialPos; m_vecMoveInfo[i]._lifeSpan = (rand() % 400) / 200.0f; m_vecMoveInfo[i]._currentTime = 0.0f; m_vecMoveInfo[i]._speed = (rand() % 200) / 200.0f; D3DXMATRIXA16 rot, rotX, rotY, rotZ; D3DXMatrixRotationX(&rotX, D3DXToRadian(0)); D3DXMatrixRotationY(&rotY, D3DXToRadian(0)); D3DXMatrixRotationZ(&rotZ, D3DXToRadian(0)); rot = rotX*rotY*rotZ; D3DXVECTOR3 vDirection(0, 1, 0); D3DXMATRIXA16 localMat; localMat = rot; D3DXVECTOR3 vDir; D3DXVec3TransformNormal(&vDir, &vDirection, &localMat); m_vecMoveInfo[i]._direction = vDir; } } }
HRESULT Title_Scene::Scene_Init() { _Img = RESOURCE_TEXTURE->GetResource("../Resources/OurModel/Texture/title.png"); _rc = { 0, 0, 512, 256 }; _x = 0; _y = 0; _obj = new cBaseObject(); _obj->SetMesh(RESOURCE_STATICXMESH->GetResource("../Resources/OurModel/Player/weapon/sword2.X")); _obj->SetActive(true); _obj->pTransform->SetScale({ 0.1f, 0.1f, 0.1f }); _obj->pTransform->SetLocalPosition({ 3.5f, -2, 5 }); m_pDirLight = new cLight_Direction(); m_pDirLight->pTransform->LookDirection(D3DXVECTOR3(1, 0, 1)); m_pDirLight->Color = D3DXCOLOR(1, 1, 1, 1); m_pDirLight->Intensity = 0.3f; lights.push_back(m_pDirLight); _fog = new titleFog(); _fog->Init(); SOUNDMANAGER->play("title", 0.5f); _btStart = RESOURCE_TEXTURE->GetResource("../Resources/OurModel/Texture/btStart.png"); _rcStart = { 0, 0, 256, 64 }; _btCredit = RESOURCE_TEXTURE->GetResource("../Resources/OurModel/Texture/btCredit.png"); _rcCredit = { 0, 0, 256, 64 }; _btQuit = RESOURCE_TEXTURE->GetResource("../Resources/OurModel/Texture/btQuit.png"); _rcQuit = { 0, 0, 256, 64 }; return S_OK; }
D3DApp::D3DApp(HINSTANCE hInstance) { mhAppInst = hInstance; mhMainWnd = 0; mAppPaused = false; mMinimized = false; mMaximized = false; mResizing = false; mFrameStats = L""; md3dDevice = 0; mSwapChain = 0; mDepthStencilBuffer = 0; mRenderTargetView = 0; mDepthStencilView = 0; mFont = 0; mMainWndCaption = L"D3D10 Application"; md3dDriverType = D3D10_DRIVER_TYPE_HARDWARE; mClearColor = D3DXCOLOR(0.0f, 0.0f, 1.0f, 1.0f); mClientWidth = 800; mClientHeight = 600; }
void Battle::addText(Pokemon a_user, Move a_move) { D3DXCOLOR tempcolor = D3DXCOLOR(0.0f,0.0f,0.0f,1.0f); battletext[curtextincrement].text = a_user.getName();// User's name battletext[curtextincrement].rec.top = 375; battletext[curtextincrement].rec.bottom = 450; battletext[curtextincrement].rec.left = 300; battletext[curtextincrement].rec.right = 500; battletext[curtextincrement].textColor = tempcolor; ++curtextincrement; battletext[curtextincrement].text = L"used";// Used battletext[curtextincrement].rec.top = 375; battletext[curtextincrement].rec.bottom = 450; battletext[curtextincrement].rec.left = 425; battletext[curtextincrement].rec.right = 625; battletext[curtextincrement].textColor = tempcolor; ++curtextincrement; battletext[curtextincrement].text = a_move.getName();// User's move's name battletext[curtextincrement].rec.top = 375; battletext[curtextincrement].rec.bottom = 450; battletext[curtextincrement].rec.left = 575; battletext[curtextincrement].rec.right = 775; battletext[curtextincrement].textColor = tempcolor; ++curtextincrement; }
GraphicsHandler::GraphicsHandler(HWND _hWnd, ConfigFile* _configFile) { this->m_deviceHandler = new DeviceHandler(_hWnd, _configFile->getWindowed(), _configFile->getScreenSize()); this->m_world = new World(this->m_deviceHandler, _hWnd, _configFile->getWindowed()); this->m_resourceHolder = new ResourceHolder(this->m_deviceHandler->getDevice()); this->m_windowed = _configFile->getWindowed(); this->m_configScreenSize = _configFile->getScreenSize(); // If we run in windowed, set the real screen size to be config screen size or the bars and crap outside of the window are counted in if(_configFile->getWindowed()) { this->m_realScreenSize = _configFile->getScreenSize(); } // Else get the real screen size else { RECT rc; GetWindowRect(_hWnd, &rc); this->m_realScreenSize = INT2(rc.right-rc.left, rc.bottom-rc.top); } this->m_fpsText = this->createText("", INT2(300, 300), 40, D3DXCOLOR(1.0f, 0.2f, 0.2f, 1.0f)); }
void DrawText() { g_pTxtHelper->Begin(); g_pTxtHelper->SetInsertionPos(5, 5); g_pTxtHelper->SetForegroundColor(D3DXCOLOR(0.f, 0.f, 0.f, 1.f)); g_pTxtHelper->DrawTextLine(DXUTGetDeviceStats()); g_pTxtHelper->DrawFormattedTextLine(L"FPS: %.1f, VSync: %s" , DXUTGetFPS(), !DXUTIsVsyncEnabled() ? L"On" : L"Off"); g_pTxtHelper->DrawFormattedTextLine(L"AO Resolution: %d x %d", g_BackBufferWidth, g_BackBufferHeight); g_pTxtHelper->DrawFormattedTextLine(L"Allocated Video Memory: %d MB\n", g_AORenderer.GetAllocatedVideoMemoryBytes() / (1024*1024)); g_pTxtHelper->DrawFormattedTextLine(L"GPU Times Per Frame (ms):"); g_pTxtHelper->DrawFormattedTextLine(L" RenderAO: %.2f", g_AORenderer.GetGPUTimeInMS(GPU_TIME_TOTAL)); g_pTxtHelper->DrawFormattedTextLine(L" LinearZ: %.2f", g_AORenderer.GetGPUTimeInMS(GPU_TIME_LINEAR_Z)); g_pTxtHelper->DrawFormattedTextLine(L" DeinterleaveZ: %.2f", g_AORenderer.GetGPUTimeInMS(GPU_TIME_DEINTERLEAVE_Z)); g_pTxtHelper->DrawFormattedTextLine(L" ReconstructN: %.2f", g_AORenderer.GetGPUTimeInMS(GPU_TIME_RECONSTRUCT_NORMAL)); g_pTxtHelper->DrawFormattedTextLine(L" GenerateAO: %.2f", g_AORenderer.GetGPUTimeInMS(GPU_TIME_GENERATE_AO)); g_pTxtHelper->DrawFormattedTextLine(L" ReinterleaveAO: %.2f", g_AORenderer.GetGPUTimeInMS(GPU_TIME_REINTERLEAVE_AO)); g_pTxtHelper->DrawFormattedTextLine(L" BlurX: %.2f", g_AORenderer.GetGPUTimeInMS(GPU_TIME_BLURX)); g_pTxtHelper->DrawFormattedTextLine(L" BlurY: %.2f", g_AORenderer.GetGPUTimeInMS(GPU_TIME_BLURY)); g_pTxtHelper->End(); }
PyObject * chrtestSetAddRenderModeRGB(PyObject* poSelf, PyObject* poArgs) { int iVirtualID; if (!PyTuple_GetInteger(poArgs, 0, &iVirtualID)) return Py_BuildException(); float fr; if (!PyTuple_GetFloat(poArgs, 1, &fr)) return Py_BuildException(); float fg; if (!PyTuple_GetFloat(poArgs, 2, &fg)) return Py_BuildException(); float fb; if (!PyTuple_GetFloat(poArgs, 3, &fb)) return Py_BuildException(); CInstanceBase * pkInst = CPythonCharacterManager::Instance().GetInstancePtr(iVirtualID); if (pkInst) { pkInst->SetAddRenderMode(); pkInst->SetAddColor(D3DXCOLOR(fr, fg, fb, 1.0f)); } return Py_BuildNone(); }
BOOL jcd3d::jcd3d_setup() { cube = new Cube(lpd3dd); D3DLIGHT9 light; ZeroMemory(&light, sizeof(D3DLIGHT9)); light.Type = D3DLIGHT_DIRECTIONAL; light.Ambient = D3DXCOLOR(0.8f, 0.8f, 0.8f, 1.0f); light.Diffuse = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f); light.Specular = D3DXCOLOR(0.2f, 0.2f, 0.2f, 1.0f); light.Direction = D3DXVECTOR3(1.0f, -1.0f, 0.0f); lpd3dd->SetLight(0, &light); lpd3dd->LightEnable(0, TRUE); lpmtrl = new D3DMATERIAL9(); lpmtrl->Ambient = D3DXCOLOR(D3DCOLOR_XRGB(255, 255, 255)); lpmtrl->Diffuse = D3DXCOLOR(D3DCOLOR_XRGB(255, 255, 255)); lpmtrl->Specular = D3DXCOLOR(D3DCOLOR_XRGB(255, 255, 255)); lpmtrl->Emissive = D3DXCOLOR(D3DCOLOR_XRGB(0, 0, 0)); lpmtrl->Power = 2.0f; lpd3dd->SetRenderState(D3DRS_NORMALIZENORMALS, TRUE); //lpd3dd->SetRenderState(D3DRS_SPECULARENABLE, TRUE); //lpd3dd->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE); D3DXCreateTextureFromFile(lpd3dd, L"cube.jpg", &lptex); lpd3dd->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR); lpd3dd->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR); lpd3dd->SetSamplerState(0, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR); D3DXMATRIX proj; D3DXMatrixPerspectiveLH( &proj, D3DX_PI * 0.5f, (FLOAT)WIN_WIDTH / (FLOAT)WIN_HEIGHT, 1.0f, 1000.0f ); lpd3dd->SetTransform(D3DTS_PROJECTION, &proj); return TRUE; }
MultiTexDemo::MultiTexDemo(HINSTANCE hInstance, std::string winCaption, D3DDEVTYPE devType, DWORD requestedVP) : D3DApp(hInstance, winCaption, devType, requestedVP) { if(!checkDeviceCaps()) { MessageBox(0, "checkDeviceCaps() Failed", 0, 0); PostQuitMessage(0); } mGfxStats = new GfxStats(); mCameraRadius = 6.0f; mCameraRotationY = 1.2 * D3DX_PI; mCameraHeight = 3.0f; mLightVecW = D3DXVECTOR3(0.0, 0.707f, -0.707f); mDiffuseMtrl = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f); mDiffuseLight = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f); mAmbientMtrl = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f); mAmbientLight = D3DXCOLOR(0.6f, 0.6f, 0.6f, 1.0f); mSpecularMtrl = D3DXCOLOR(0.4f, 0.4f, 0.4f, 1.0f); mSpecularLight = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f); mSpecularPower = 8.0f; D3DXMatrixIdentity(&mWorld); // Load textures from file. HR(D3DXCreateTextureFromFile(gd3dDevice, "grass0.dds", &mTex0)); HR(D3DXCreateTextureFromFile(gd3dDevice, "stone2.dds", &mTex1)); HR(D3DXCreateTextureFromFile(gd3dDevice, "ground0.dds", &mTex2)); HR(D3DXCreateTextureFromFile(gd3dDevice, "blendmap.jpg", &mBlendMap)); buildGridGeometry(); mGfxStats->addVertices(mNumGridVertices); mGfxStats->addTriangles(mNumGridTriangles); buildFX(); onResetDevice(); InitAllVertexDeclarations(); }
void Gizmo::Build() { /*axisX.Build(Vector3::Zero, Vector3(1, 0, 0), D3DXCOLOR(1, 0, 0, 1), 4.0f); axisY.Build(Vector3::Zero, Vector3(0, 1, 0), D3DXCOLOR(0, 1, 0, 1), 4.0f); axisZ.Build(Vector3::Zero, Vector3(0, 0, 1), D3DXCOLOR(0, 0, 1, 1), 4.0f);*/ axisX = Cylinder(0.02f, 0.02f, 1.0f, 12, 8, D3DXCOLOR(1, 0, 0, 1)); axisX.CalculateNormals(); axisX.Build(XYZ_N); axisX.rotation = Quaternion(0, 0, -PI/2); axisY = Cylinder(0.02f, 0.02f, 1.0f, 12, 8, D3DXCOLOR(0, 1, 0, 1)); axisY.CalculateNormals(); axisY.Build(XYZ_N); axisZ = Cylinder(0.02f, 0.02f, 1.0f, 12, 8, D3DXCOLOR(0, 0, 1, 1)); axisZ.CalculateNormals(); axisZ.Build(XYZ_N); axisZ.rotation = Quaternion(PI/2, 0, 0); coneX = Cylinder(0.0f, 0.08f, 0.2f, 12, 8, D3DXCOLOR(1, 0, 0, 1)); coneX.CalculateNormals(); coneX.Build(XYZ_N); coneX.position = Vector3(1, 0, 0); coneX.rotation = Quaternion(0, 0, -PI/2); coneY = Cylinder(0.0f, 0.08f, 0.2f, 12, 8, D3DXCOLOR(0, 1, 0, 1)); coneY.CalculateNormals(); coneY.Build(XYZ_N); coneY.position = Vector3(0, 1, 0); coneZ = Cylinder(0.0f, 0.08f, 0.2f, 12, 8, D3DXCOLOR(0, 0, 1, 0)); coneZ.CalculateNormals(); coneZ.Build(XYZ_N); coneZ.position = Vector3(0, 0, 1); coneZ.rotation = Quaternion(PI/2, 0, 0); }
int WINAPI WinMain(HINSTANCE hist,HINSTANCE phist,LPSTR cmd,int show) { srand((unsigned int)time(0)); WinInfo info; if (!initWindow(800,600,false,"my game",hist,&info)) { return -1; } DxParam param = {info.isFullScreen,info.width,info.height,info.hwnd}; DxFw df; if (!df.initDx(param)) { MessageBox(0,"f**k","",MB_OK); } if (!df.initInput(info.hwnd,info.hist,false)) { MessageBox(0,"input failed","",MB_OK); } registAllDefaultAffectos(); df.getRenderer()->setAsPerspectiveProjection(PI_OVER_2,800.0f / 600.0f,1.0f,1000.0f); SceneNodeContainer c; SceneNode* n = c.createNode("test"); XModel x; x.mXmodel = df.getResourceManager()->loadXModel(DEFAULT_GROUP_NAME,"ship.x"); n->attach(&x); MSG msg; D3DLIGHT9 light; ::ZeroMemory(&light, sizeof(light)); light.Type = D3DLIGHT_DIRECTIONAL; light.Ambient = D3DXCOLOR(0.8f, 0.8f, 0.8f, 1.0f); light.Diffuse = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f); light.Specular = D3DXCOLOR(0.2f, 0.2f, 0.2f, 1.0f); light.Direction = D3DXVECTOR3(1.0f, -1.0f, 0.0f); IDirect3DDevice9* device = df.getDevice(); device->SetSamplerState(0,D3DSAMP_MAGFILTER,D3DTEXF_LINEAR); device->SetSamplerState(0,D3DSAMP_MINFILTER,D3DTEXF_LINEAR); device->SetSamplerState(0,D3DSAMP_MIPFILTER,D3DTEXF_POINT); df.getRenderer()->setLight(0,&light); Node camera; camera.setPosition(0.0f,100.0f,0.0f); camera.lookAt(Vector3(0.0f,0.0f,0.0f)); n->yaw(PI); //Device->SetRenderState(D3DRS_NORMALIZENORMALS, true); //Device->SetRenderState(D3DRS_SPECULARENABLE, true); GUISystem* guisys = GUISystem::getSingletonPtr(); guisys->initOnce(df); //Route r(new LinearPathRel(Vector3(10.0f,0.0f,10.0f),0.5),true); //r.addPath(new LinearPathRel(Vector3(-10.0f,0.0f,10.0f),0.5)); //TranslateToAction action(n,Vector3(10.0f,0.0f,0.0f),1.0,Node::TS_PARENT); //guisys->load("media/gui/dx.xml"); //GUIButton* btn = (GUIButton*) guisys->getLayout(0)->getControlById(0); //btn->setClickListener(f**k); //GUIImage* img = layout->createImage(0,0,800,600,2); //img->setImage("menu/mainMenu.jpg"); GUILayout* layout = guisys->createLayout(0); DxFont* font = guisys->createFont("",15,false,15,0); GUILabel* label = layout->createLabel(0,0,800,600,0,0); label->setColor(0xffff0000); guisys->changeCurrentLayout(0); loggingInit(label); DxParticleSystem ps; loadParticleSystem(&ps,&df,"media/particle/particl_1.lua"); //ps.init(&df,5012,"media/tex/smoke000.tga"); /* DxParticleEmitter* em = new DxParticleEmitter; DxColorValue e = {0.7f,0.7f,0.8f,0.7f}; DxColorValue b = {0.7f,0.7f,0.8f,0.7f}; em->colorBegine = b; em->colorEnd = e; em->angle = 0.0f; em->up = Vector3::UNIT_Y; em->direction = Vector3::UNIT_Z; em->duration = 0.0f; em->emitRate = 1000.0f; em->maxPosition = Vector3(1.0f,10.0f,2.0f); em->minPosition = Vector3(-1.0f,0.0f,-1.0f); em->minVelocity = 50.0f; em->maxVelocity = 80.0f; em->maxTimeLL = 0.5f; em->minTimeLL = 0.1f; em->size = 1.5f; em->repeatDelay = 2.5f; em->currentTime = em->duration; em->repeatTimeRemain = em->repeatDelay; ps.setEmitter(em); ps.addAffector(new LinearForceAffector(0.0f,0.0f,-100.0f,LinearForceAffector::FT_ADD)); ps.addAffector(new ColorFaderAffector(0.0f,2.0f,-2.0f,-3.0f)); */ n->attach(&ps); //logToScreen("p","f**k"); /* SceneNode* nps = c.createNode("testps"); nps->attach(&ps); nps->yaw(PI); nps->translate(0.0f,0.0f,-11.0f); */ while (true) { DxRenderer* renderer = df.getRenderer(); renderer->clear(true,true,true,0xff000000); Matrix4x4 v; camera.generateParentToLocalMatrix(&v); renderer->setViewMatrix(v); renderer->render(&c); guisys->render(); //n->yaw(getTimeSinceLastFrame() * 1.0f); float timeDelta = getTimeSinceLastFrame(); Vector3 walk = Vector3::ZERO; float speed = 60.0f; float hspeed = speed; float vspeed = speed * 0.7f; IInputSystem* isys = df.getInputSystem(); if (isys->keyDown(DIK_W)) { walk.z += vspeed * timeDelta; } if (isys->keyDown(DIK_A)) { walk.x -= hspeed * timeDelta; } if (isys->keyDown(DIK_D)) { walk.x += hspeed * timeDelta; } if (isys->keyDown(DIK_S)) { walk.z -= vspeed * timeDelta; } if (isys->keyDown(DIK_F5)) { df.saveScreenshot(); } //Vector3 ani; //r.calcPosition(timeDelta,&ani); //n->translate(ani,Node::TS_PARENT); //if (action.act(timeDelta)) //{ //} n->translate(walk,Node::TS_PARENT); isys->capture(); Point p = isys->getMouseClientPosition(); guisys->processGUI(p.x,p.y,isys->mouseButtonDown(0)); ps.update(timeDelta); //logToScreen("particle num:","%d",ps.size()); renderer->present(); messagePump(&msg); if (msg.message == WM_QUIT) { break; } } guisys->release(); df.release(); UnregisterClass(info.className,info.hist); return 0; }