bool cViewer::OnInit() { DragAcceptFiles(m_hWnd, TRUE); m_filePath = "../media/data.dat"; m_model = new graphic::cModel(); m_model->Create( m_filePath ); m_texture.Create("../media/001 copy.jpg"); //m_texture.Create("../media/강소라.jpg"); m_mtrl.InitWhite(); Vector4 color(1,1,1,1); m_light.Init( graphic::cLight::LIGHT_DIRECTIONAL, color * 0.4f, color, color * 0.6f, Vector3(0,-1,0)); m_light.Bind(0); m_camPos = Vector3(100,100,-500); m_lookAtPos = Vector3(0,0,0); UpdateCamera(); const int WINSIZE_X = 1024; //초기 윈도우 가로 크기 const int WINSIZE_Y = 768; //초기 윈도우 세로 크기 Matrix44 proj; proj.SetProjection(D3DX_PI / 4.f, (float)WINSIZE_X / (float) WINSIZE_Y, 1.f, 1000.0f) ; graphic::GetDevice()->SetTransform(D3DTS_PROJECTION, (D3DXMATRIX*)&proj) ; graphic::GetDevice()->LightEnable ( 0, // 활성화/ 비활성화 하려는 광원 리스트 내의 요소 true); // true = 활성화 , false = 비활성화 return true; }
bool cViewer::OnInit() { DragAcceptFiles(m_hWnd, TRUE); ReadModelFile("../media/cube.dat", m_vtxBuff, m_idxBuff, m_texture); m_mtrl.InitWhite(); Vector4 color(1,1,1,1); m_light.Init( graphic::cLight::LIGHT_DIRECTIONAL, color * 0.4f, color, color * 0.6f, Vector3(1,0,0)); m_light.Bind(0); Matrix44 V; Vector3 dir = Vector3(0,0,0)-Vector3(0,0,-5); dir.Normalize(); V.SetView(Vector3(0,0,-500), dir, Vector3(0,1,0)); graphic::GetDevice()->SetTransform(D3DTS_VIEW, (D3DXMATRIX*)&V); const int WINSIZE_X = 1024; //초기 윈도우 가로 크기 const int WINSIZE_Y = 768; //초기 윈도우 세로 크기 Matrix44 proj; proj.SetProjection(D3DX_PI * 0.5f, (float)WINSIZE_X / (float) WINSIZE_Y, 1.f, 1000.0f) ; graphic::GetDevice()->SetTransform(D3DTS_PROJECTION, (D3DXMATRIX*)&proj) ; graphic::GetDevice()->LightEnable ( 0, // 활성화/ 비활성화 하려는 광원 리스트 내의 요소 true); // true = 활성화 , false = 비활성화 return true; }
bool InitVertexBuffer() { g_grid.Create(ROW_CELL_COUNT, COL_CELL_COUNT, CELL_SIZE, 1.f); g_grid.GetTexture().Create(TEXTURE_SIZE, TEXTURE_SIZE, D3DFMT_A8R8G8B8); // 카메라, 투영행렬 생성 UpdateCamera(); g_matProj.SetProjection(D3DX_PI * 0.5f, (float)WINSIZE_X / (float) WINSIZE_Y, 1.f, 10000.0f) ; g_pDevice->SetTransform(D3DTS_PROJECTION, (D3DXMATRIX*)&g_matProj) ; g_pDevice->SetRenderState(D3DRS_LIGHTING, false); return true; }
bool InitVertexBuffer() { g_grid1.Create(64, 64, 50.f); g_grid1.GetTexture().Create( "../../media/grass_spring1.jpg"); g_grid2.Create(64, 64, 50.f); g_grid2.GetTexture().Create( "../../media/alpha2.bmp"); // 카메라, 투영행렬 생성 UpdateCamera(); g_matProj.SetProjection(D3DX_PI * 0.5f, (float)WINSIZE_X / (float) WINSIZE_Y, 1.f, 10000.0f) ; g_pDevice->SetTransform(D3DTS_PROJECTION, (D3DXMATRIX*)&g_matProj) ; g_pDevice->SetRenderState(D3DRS_LIGHTING, false); return true; }
void Init() { ReadModelFile("../../media/model_normal.dat", g_vertices, g_indices, g_normals); g_matWorld1.SetTranslate(Vector3(0,0,0)); Vector3 dir = g_cameraLookat - g_cameraPos; dir.Normalize(); g_matView.SetView(g_cameraPos, dir, Vector3(0,1,0)); g_matProjection.SetProjection( MATH_PI / 4.f, 1.0f, 1.0f, 100.0f ); RECT cr; ::GetClientRect(g_hWnd, &cr); const float width = (float)(cr.right-cr.left); const float height = (float)(cr.bottom - cr.top); g_matViewPort.SetViewport(width, height); }
bool InitVertexBuffer() { ReadModelFile("../../media/data2.dat", global->vb, global->vtxSize, global->ib, global->faceSize); CreateFaceNormalLine(global->vb, global->vtxSize, global->ib, global->faceSize, global->fnvb, global->faceNormalVtxSize); CreateVertexNormalLine(global->vb, global->vtxSize, global->ib, global->faceSize, global->vnvb, global->vertexNormalVtxSize); D3DXCreateTextureFromFileA(g_pDevice, "../../media/강소라2.jpg", &global->texture); ZeroMemory(&global->mtrl, sizeof(global->mtrl)); global->mtrl.Ambient = D3DXCOLOR(1,1,1,1); global->mtrl.Diffuse = D3DXCOLOR(1,1,1,1); global->mtrl.Specular = D3DXCOLOR(1,1,1,1); global->mtrl.Emissive = D3DXCOLOR(0,0,0,1); global->mtrl.Power = 32.f; D3DXCOLOR color(1,1,1,1); ZeroMemory(&global->light, sizeof(global->light)); global->light.Type = D3DLIGHT_DIRECTIONAL; global->light.Ambient = color * 0.4f; global->light.Diffuse = color; global->light.Specular = color * 0.6f; global->light.Direction = *(D3DXVECTOR3*)&Vector3(0,0,1); g_pDevice->SetLight(0, &global->light); // 광원 설정. Matrix44 V; Vector3 dir = Vector3(0,0,0)-Vector3(0,0,-500); dir.Normalize(); V.SetView(Vector3(0,0,-500), dir, Vector3(0,1,0)); g_pDevice->SetTransform(D3DTS_VIEW, (D3DXMATRIX*)&V); Matrix44 proj; proj.SetProjection(D3DX_PI * 0.5f, (float)WINSIZE_X / (float) WINSIZE_Y, 1.f, 1000.0f) ; g_pDevice->SetTransform(D3DTS_PROJECTION, (D3DXMATRIX*)&proj) ; g_pDevice->LightEnable(0, true); //g_pDevice->SetRenderState(D3DRS_SPECULARENABLE, true); //g_pDevice->SetRenderState(D3DRS_NORMALIZENORMALS, true) ; return true; }
void CModelView::Init() { m_filePath = "../media/data.dat"; m_camPos = Vector3(100,100,-500); m_lookAtPos = Vector3(0,0,0); UpdateCamera(); const int WINSIZE_X = 1024; //초기 윈도우 가로 크기 const int WINSIZE_Y = 768; //초기 윈도우 세로 크기 Matrix44 proj; proj.SetProjection(D3DX_PI / 4.f, (float)WINSIZE_X / (float) WINSIZE_Y, 1.f, 10000.0f) ; graphic::GetDevice()->SetTransform(D3DTS_PROJECTION, (D3DXMATRIX*)&proj) ; graphic::GetDevice()->SetRenderState(D3DRS_NORMALIZENORMALS, TRUE); graphic::GetDevice()->LightEnable ( 0, // 활성화/ 비활성화 하려는 광원 리스트 내의 요소 true); // true = 활성화 , false = 비활성화 }
bool InitVertexBuffer() { HRESULT hr = D3DXCreateFont( g_pDevice, // D3D device 0, // Height 0, // Width FW_BOLD, // Weight 1, // MipLevels, 0 = autogen mipmaps FALSE, // Italic DEFAULT_CHARSET, // 그냥 디폴트 OUT_DEFAULT_PRECIS, // 정밀도 DEFAULT_QUALITY, // 그냥 디폴트 DEFAULT_PITCH | FF_DONTCARE, // 디폴트 L"굴림", // pFaceName &global->font ); // ppFont if (FAILED(hr)) return false; if (FAILED(hr = D3DXCreateSprite(g_pDevice, &global->textSprite))) return false; CreateD3DXTextMesh(g_pDevice, &global->mesh3DText, "굴림", 0, FALSE, FALSE); Matrix44 V; Vector3 dir = Vector3(0,0,0)-Vector3(0,0,-500); dir.Normalize(); V.SetView(Vector3(0,0,-500), dir, Vector3(0,1,0)); g_pDevice->SetTransform(D3DTS_VIEW, (D3DXMATRIX*)&V); Matrix44 proj; proj.SetProjection(D3DX_PI * 0.5f, (float)WINSIZE_X / (float) WINSIZE_Y, 1.f, 1000.0f) ; g_pDevice->SetTransform(D3DTS_PROJECTION, (D3DXMATRIX*)&proj) ; g_pDevice->LightEnable(0, true); //g_pDevice->SetRenderState(D3DRS_SPECULARENABLE, true); //g_pDevice->SetRenderState(D3DRS_NORMALIZENORMALS, true) ; return true; }
bool InitVertexBuffer() { ReadModelFile("../../media/cube.dat", g_pVB, g_VtxSize, g_pIB, g_FaceSize); D3DXCreateTextureFromFileA(g_pDevice, "../../media/강소라2.jpg", &g_Texture); ZeroMemory(&g_Mtrl, sizeof(g_Mtrl)); g_Mtrl.Ambient = D3DXCOLOR(1,1,1,1); g_Mtrl.Diffuse = D3DXCOLOR(1,1,1,1); g_Mtrl.Specular = D3DXCOLOR(1,1,1,1); g_Mtrl.Emissive = D3DXCOLOR(0,0,0,1); g_Mtrl.Power = 0.f; D3DXCOLOR color(1,1,1,1); ZeroMemory(&g_Light, sizeof(g_Light)); g_Light.Type = D3DLIGHT_DIRECTIONAL; g_Light.Ambient = color * 0.4f; g_Light.Diffuse = color; g_Light.Specular = color * 0.6f; g_Light.Direction = *(D3DXVECTOR3*)&Vector3(0,0,1); Matrix44 V; Vector3 dir = Vector3(0,0,0)-Vector3(0,0,-5); dir.Normalize(); V.SetView(Vector3(0,0,-500), dir, Vector3(0,1,0)); g_pDevice->SetTransform(D3DTS_VIEW, (D3DXMATRIX*)&V); Matrix44 proj; proj.SetProjection(D3DX_PI * 0.5f, (float)WINSIZE_X / (float) WINSIZE_Y, 1.f, 1000.0f) ; g_pDevice->SetTransform(D3DTS_PROJECTION, (D3DXMATRIX*)&proj) ; //g_pDevice->SetRenderState(D3DRS_CULLMODE, false); //g_pDevice->SetRenderState(D3DRS_FILLMODE, D3DFILL_WIREFRAME); g_pDevice->SetLight(0, &g_Light); // 광원 설정. g_pDevice->LightEnable( 0, // 활성화/ 비활성화 하려는 광원 리스트 내의 요소 true); // true = 활성화 , false = 비활성화 return true; }
bool InitVertexBuffer() { //D3DXCreateBox(g_pDevice, 2, 2, 2, &g_pMesh, 0); //D3DXCreateSphere(g_pDevice, 1, 10, 10, &g_pMesh, 0); //D3DXCreateCylinder(g_pDevice, 1, 1, 2, 10, 10, &g_pMesh, 0); D3DXCreateTeapot( g_pDevice, &g_pMesh, 0) ; //D3DXCreateTorus(g_pDevice, 0.5f, 2.f, 20, 20, &g_pMesh, 0) ; Matrix44 V; Vector3 dir = Vector3(0,0,0)-Vector3(0,0,-5); dir.Normalize(); V.SetView(Vector3(0,0,-5), dir, Vector3(0,1,0)); g_pDevice->SetTransform(D3DTS_VIEW, (D3DXMATRIX*)&V); Matrix44 proj; proj.SetProjection(D3DX_PI * 0.5f, (float)WINSIZE_X / (float) WINSIZE_Y, 1.f, 1000.0f) ; g_pDevice->SetTransform(D3DTS_PROJECTION, (D3DXMATRIX*)&proj) ; g_pDevice->SetRenderState(D3DRS_FILLMODE, D3DFILL_WIREFRAME); return true; }
bool InitVertexBuffer() { ReadModelFile("../../media/vase.dat", global->vb, global->vtxSize, global->ib, global->faceSize); //재질2 ZeroMemory(&global->mtrl, sizeof(global->mtrl)); global->mtrl.Ambient = D3DXCOLOR(1,0,0,1); global->mtrl.Diffuse = D3DXCOLOR(1,0,0,1); global->mtrl.Specular = D3DXCOLOR(1,0,0,1); global->mtrl.Emissive = D3DXCOLOR(0,0,0,1); global->mtrl.Power = 0.f; //광원2 (스나이프에서 3으로 되어있다!) D3DXCOLOR color(1,1,1,1); //광원이니깐 일반적으로 흰색 ZeroMemory(&global->light, sizeof(global->light)); global->light.Type = D3DLIGHT_DIRECTIONAL; global->light.Ambient = color * 0.4f; global->light.Diffuse = color; global->light.Specular = color * 0.6f; global->light.Direction = *(D3DXVECTOR3*)&Vector3(1,0,0); //광원4 g_pDevice->SetLight(0, &global->light); // 광원 설정. Matrix44 V; Vector3 dir = Vector3(0,0,0)-Vector3(0,0,-500); dir.Normalize(); V.SetView(Vector3(0,0,-500), dir, Vector3(0,1,0)); g_pDevice->SetTransform(D3DTS_VIEW, (D3DXMATRIX*)&V); Matrix44 proj; proj.SetProjection(D3DX_PI * 0.5f, (float)WINSIZE_X / (float) WINSIZE_Y, 1.f, 1000.0f) ; g_pDevice->SetTransform(D3DTS_PROJECTION, (D3DXMATRIX*)&proj) ; g_pDevice->LightEnable ( 0, // 활성화/ 비활성화 하려는 광원 리스트 내의 요소 true); // true = 활성화 , false = 비활성화 return true; }
bool InitVertexBuffer() { ZeroMemory(&g_Mtrl, sizeof(g_Mtrl)); g_Mtrl.Ambient = D3DXCOLOR(1,1,1,1); g_Mtrl.Diffuse = D3DXCOLOR(1,1,1,1); g_Mtrl.Specular = D3DXCOLOR(1,1,1,1); g_Mtrl.Emissive = D3DXCOLOR(0,0,0,1); g_Mtrl.Power = 0.f; D3DXCOLOR color(1,1,1,1); ZeroMemory(&g_Light, sizeof(g_Light)); g_Light.Type = D3DLIGHT_DIRECTIONAL; g_Light.Ambient = color * 0.4f; g_Light.Diffuse = color; g_Light.Specular = color * 0.6f; g_Light.Direction = *(D3DXVECTOR3*)&Vector3(0,-1,0); Matrix44 V; Vector3 camPos(0,200,-500); Vector3 lookAt(0, 0, 0); Vector3 dir = lookAt - camPos; dir.Normalize(); V.SetView(camPos, dir, Vector3(0,1,0)); g_pDevice->SetTransform(D3DTS_VIEW, (D3DXMATRIX*)&V); Matrix44 proj; proj.SetProjection(D3DX_PI * 0.5f, (float)WINSIZE_X / (float) WINSIZE_Y, 1.f, 1000.0f) ; g_pDevice->SetTransform(D3DTS_PROJECTION, (D3DXMATRIX*)&proj) ; g_pDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE); g_pDevice->SetRenderState(D3DRS_FILLMODE, D3DFILL_WIREFRAME); g_pDevice->SetLight(0, &g_Light); // 광원 설정. g_pDevice->LightEnable( 0, // 활성화/ 비활성화 하려는 광원 리스트 내의 요소 true); // true = 활성화 , false = 비활성화 return true; }
void cStage_IngameEnd::Render(const float elapseTime) { m_skybox->Render(); graphic::cCharacter* pMe = m_user == 1 ? character1 : character2; pMe->GetCamera()->SetView(); graphic::GetRenderer()->RenderFPS(); //--------------------------------------------------------------- // 모델 출력 + 그림자. LPDIRECT3DSURFACE9 pOldBackBuffer, pOldZBuffer; D3DVIEWPORT9 oldViewport; graphic::GetDevice()->GetRenderTarget(0, &pOldBackBuffer); graphic::GetDevice()->GetDepthStencilSurface(&pOldZBuffer); graphic::GetDevice()->GetViewport(&oldViewport); graphic::GetDevice()->SetRenderTarget(0, m_pShadowSurf); graphic::GetDevice()->SetDepthStencilSurface(m_pShadowTexZ); // 뷰포트변경 x y width height minz maxz D3DVIEWPORT9 viewport = {0,0, MAP_SIZE,MAP_SIZE,0.0f,1.0f}; graphic::GetDevice()->SetViewport(&viewport); // 그림자맵 클리어 graphic::GetDevice()->Clear(0L, NULL , D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER , 0x00000000, 1.0f, 0L); // Vector3 pos = pMe->GetCamera()->GetLook(); Vector3 light = Vector3(1111,1111,0); Matrix44 matView;// 뷰 행렬 // matView.SetView2( light, pos, Vector3(0,1,0)); //test matView.SetView2( light, pMe->GetCamera()->GetLook(), Vector3(0,1,0)); Matrix44 matProj;// 투영 행렬 matProj.SetProjection( D3DX_PI * 0.37f, 1, 0.1f, 7777); m_shader->SetMatrix( "mVP", matView * matProj); m_shader->SetVector( "vLightDir", Vector3(0,-1,0) ); m_shader->SetVector( "vEyePos", pMe->GetCamera()->GetPosition()); m_shader->SetRenderPass(1); // character1->RenderShadow( *m_shader ); // character2->RenderShadow( *m_shader ); pMe->RenderShadow( *m_shader ); //----------------------------------------------------- // 렌더링타겟 복구 //----------------------------------------------------- graphic::GetDevice()->SetRenderTarget(0, pOldBackBuffer); graphic::GetDevice()->SetDepthStencilSurface(pOldZBuffer); graphic::GetDevice()->SetViewport(&oldViewport); pOldBackBuffer->Release(); pOldZBuffer->Release(); graphic::GetDevice()->SetTransform( D3DTS_VIEW, (D3DXMATRIX*)&( pMe->GetCamera()->GetView() ) ); graphic::GetDevice()->SetTransform( D3DTS_PROJECTION, (D3DXMATRIX*)&( pMe->GetCamera()->GetProjection() ) ); m_shader->SetMatrix( "mVP", pMe->GetCamera()->GetView() * pMe->GetCamera()->GetProjection() ); m_shader->SetRenderPass(0); // character1->RenderShader( *m_shader ); // character2->RenderShader( *m_shader ); pMe->RenderShader( *m_shader ); //------------------------------------------------------------------------ // 지형 출력. //------------------------------------------------------------------------ D3DXMATRIX mTT; mTT = D3DXMATRIX(0.5f, 0.0f, 0.0f, 0.0f , 0.0f,-0.5f, 0.0f, 0.0f , 0.0f, 0.0f, 1.0f, 0.0f , 0.5f, 0.5f, 0.0f, 1.0f); Matrix44 mT = *(Matrix44*)&mTT; m_terrainShader->SetMatrix( "mVP", pMe->GetCamera()->GetView() * pMe->GetCamera()->GetProjection()); m_terrainShader->SetVector( "vLightDir", Vector3(0,-1,0) ); m_terrainShader->SetVector( "vEyePos", pMe->GetCamera()->GetPosition()); m_terrainShader->SetTexture("ShadowMap", m_pShadowTex); Matrix44 m = matView * matProj * mT; m_terrainShader->SetMatrix( "mWVPT", m ); m_terrainShader->SetRenderPass(2); m_terrain->RenderShader( *m_terrainShader , pMe->GetCamera() ); //결과 이미지 출력 m_image->Render( Matrix44() ); }
bool InitVertexBuffer() { HRESULT hr; ID3DXBuffer *adjBuff = NULL; ID3DXBuffer *mtrlBuff = NULL; DWORD numMtrls = 0; // 메쉬 정보 로드 hr = D3DXLoadMeshFromXA( "../../media/bigship1.x", D3DXMESH_MANAGED, g_pDevice, &adjBuff, &mtrlBuff, 0, &numMtrls, &g_pMesh ); if (FAILED(hr)) return false; ///////////////////////////////////////////////////////////////////////////// // 매터리얼 설정 if( mtrlBuff && numMtrls > 0 ) { D3DXMATERIAL *mtrls = (D3DXMATERIAL*)mtrlBuff->GetBufferPointer(); for( int i=0; i < (int)numMtrls; ++i ) { mtrls[ i].MatD3D.Ambient = mtrls[ i].MatD3D.Diffuse; g_Mtrls.push_back( mtrls[ i].MatD3D ); if( mtrls[ i].pTextureFilename ) { IDirect3DTexture9 *tex = NULL; string filePath = "../../media/"; filePath += mtrls[ i].pTextureFilename; D3DXCreateTextureFromFileA( g_pDevice, filePath.c_str(), &tex ); g_Texture.push_back( tex ); } else { g_Texture.push_back( 0 ); } } } mtrlBuff->Release(); // 메쉬 최적화 hr = g_pMesh->OptimizeInplace( D3DXMESHOPT_COMPACT | D3DXMESHOPT_ATTRSORT | D3DXMESHOPT_VERTEXCACHE, (DWORD*)adjBuff->GetBufferPointer(), (DWORD*)adjBuff->GetBufferPointer(), 0, 0 ); if (FAILED(hr)) return false; // 프로그레시브 메쉬 생성. hr = D3DXGeneratePMesh(g_pMesh, (DWORD*)adjBuff->GetBufferPointer(), 0, 0, 1, D3DXMESHSIMP_FACE, &g_pPMesh ); g_pMesh->Release(); g_pMesh = NULL; adjBuff->Release(); if (FAILED(hr)) return false; //DWORD maxFaces = g_pPMesh->GetMaxFaces(); //g_pPMesh->SetNumFaces( maxFaces ); D3DXCOLOR color(1,1,1,1); ZeroMemory(&g_Light, sizeof(g_Light)); g_Light.Type = D3DLIGHT_DIRECTIONAL; g_Light.Ambient = color * 0.4f; g_Light.Diffuse = color; g_Light.Specular = color * 0.6f; g_Light.Direction = *(D3DXVECTOR3*)&Vector3(0,-1,0); Matrix44 V; Vector3 camPos(0,0,-20); Vector3 lookAtPos(0,0,0); Vector3 dir = lookAtPos - camPos; dir.Normalize(); V.SetView(camPos, dir, Vector3(0,1,0)); g_pDevice->SetTransform(D3DTS_VIEW, (D3DXMATRIX*)&V); Matrix44 proj; proj.SetProjection(D3DX_PI * 0.5f, (float)WINSIZE_X / (float) WINSIZE_Y, 1.f, 1000.0f) ; g_pDevice->SetTransform(D3DTS_PROJECTION, (D3DXMATRIX*)&proj) ; g_pDevice->SetLight(0, &g_Light); // 광원 설정. g_pDevice->LightEnable( 0, // 활성화/ 비활성화 하려는 광원 리스트 내의 요소 true); // true = 활성화 , false = 비활성화 g_pDevice->SetRenderState(D3DRS_NORMALIZENORMALS, true); g_pDevice->SetRenderState(D3DRS_SPECULARENABLE, true); return true; }
bool cGameApp::OnInit() { srand(time(NULL)); ReadModelFile("box.dat" , _VB , _vSize , _IB , _vSizeFace , 0 , 255 , 0); ReadModelFile("ground.dat" , _groundVB , _groundSize , _groundIB, _groundSizeFace ,255 , 0 , 0); ReadModelFile("cone.dat" , _coneVB , _coneSize , _coneIB, _coneSizeFace , 100 , 20 ,255); _material.InitBlue(); Vector4 color(1 , 1 ,1 ,1); _light.Init(graphic::light::LIGHT_DIRECTIONAL, color * 0.4f, color , color * 0.6f , Vector3(1,0,0)); //// 버텍스 버퍼 생성. //if (FAILED(graphic::GetDevice()->CreateVertexBuffer( 8 * sizeof(Vertex), // D3DUSAGE_WRITEONLY, Vertex::FVF, // D3DPOOL_MANAGED, &_VB, NULL))) //{ // return false; //} // _VB.Create(8 , sizeof(Vertex) , Vertex::FVF); //if (FAILED(_VB->Lock( 0, sizeof(Vertex), (void**)&_vertex, 0))) // return false; /*_VB.Lock(); float width = 10.0f; _vertex[ 0] = Vertex(-width, -width, -width , D3DCOLOR_ARGB(0 , 255 , 255 , 0)); _vertex[ 1] = Vertex(-width, width, -width , D3DCOLOR_ARGB(0 , 255 , 255 , 0)); _vertex[ 2] = Vertex(width, width, -width , D3DCOLOR_ARGB(0 , 255 , 255 , 0)); _vertex[ 3] = Vertex(width, -width, -width , D3DCOLOR_ARGB(0 , 255 , 255 , 0)); _vertex[ 4] = Vertex(-width, -width, width , D3DCOLOR_ARGB(0 , 0 , 255 , 0)); _vertex[ 5] = Vertex(-width, width, width , D3DCOLOR_ARGB(0 , 0 , 255 , 0)); _vertex[ 6] = Vertex(width, width, width , D3DCOLOR_ARGB(0 , 0 , 255 , 0)); _vertex[ 7] = Vertex(width, -width, width , D3DCOLOR_ARGB(0 , 0 , 255 , 0)); _VB.Unlock();*/ //if (FAILED(graphic::GetDevice()->CreateIndexBuffer(36*sizeof(WORD), // D3DUSAGE_WRITEONLY, // D3DFMT_INDEX16, // D3DPOOL_MANAGED, // &_IB, NULL))) //{ // return false; //} //WORD *indices = NULL; //_IB->Lock(0, 0, (void**)&indices, 0); //int index = 0; //// front //indices[ index++] = 0; indices[ index++] = 1; indices[ index++] = 2; //indices[ index++] = 0; indices[ index++] = 2; indices[ index++] = 3; //// back //indices[ index++] = 4; indices[ index++] = 6; indices[ index++] = 5; //indices[ index++] = 4; indices[ index++] = 7; indices[ index++] = 6; //// left //indices[ index++] = 4; indices[ index++] = 5; indices[ index++] = 1; //indices[ index++] = 4; indices[ index++] = 1; indices[ index++] = 0; //// right //indices[ index++] = 3; indices[ index++] = 2; indices[ index++] = 6; //indices[ index++] = 3; indices[ index++] = 6; indices[ index++] = 7; //// top //indices[ index++] = 1; indices[ index++] = 5; indices[ index++] = 6; //indices[ index++] = 1; indices[ index++] = 6; indices[ index++] = 2; //// bottom //indices[ index++] = 4; indices[ index++] = 0; indices[ index++] = 3; //indices[ index++] = 4; indices[ index++] = 3; indices[ index++] = 7; //_IB->Unlock(); Matrix44 V; Vector3 dir = Vector3(0,0,0)-Vector3(0,0,-5); dir.Normalize(); V.SetView(Vector3(0,0,-100), dir, Vector3(0,1,0)); graphic::GetDevice()->SetTransform(D3DTS_VIEW, (D3DMATRIX*)&V); Matrix44 proj; proj.SetProjection(MATH_PI * 0.5f, (float)800 / (float) 600, 1.f, 1000.0f) ; graphic::GetDevice()->SetTransform(D3DTS_PROJECTION, (D3DMATRIX*)&proj) ; graphic::GetDevice()->SetRenderState(D3DRS_LIGHTING, true); //graphic::GetDevice() ->SetRenderState(D3DRS_FILLMODE , D3DFILL_WIREFRAME); _move = _z = 0; for(int i = 0; i < 5; i ++) { Matrix44 down , rota , groMat; down.SetTranslate(Vector3(0 , -70 , 300 * i )); rota.SetRotationX(3.1f); _groundLocal[i] = rota* down; } for(int i = 0 ; i < CONEMAX ; i++) { _coneLocal[i].SetTranslate(Vector3( (rand() % 250) - 150 , -70 , (rand() % 200) + 300)); } _jumpFlag = false; _jumpY = 8; _light.Bind(0); graphic::GetDevice() ->LightEnable( 0, true); return true; }
int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) { UNREFERENCED_PARAMETER(hPrevInstance); UNREFERENCED_PARAMETER(lpCmdLine); LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING); LoadString(hInstance, IDC_SOFTWARERENDERER, szWindowClass, MAX_LOADSTRING); MyRegisterClass(hInstance); // Y Z // | / // | / // -----------------------> X const float axisLineLength = 300.f; g_axises.reserve(8); g_axises.push_back( Vector3(0,0,0) ); g_axises.push_back( Vector3(axisLineLength,0,0) ); // x-axis g_axises.push_back( Vector3(0,0,0) ); g_axises.push_back( Vector3(0,axisLineLength,0) ); // y-axis g_axises.push_back( Vector3(0,0,0) ); g_axises.push_back( Vector3(0,0,axisLineLength) ); // z-axis // vertices1 // (-50,+50, +50) ----------------- (+50, +50, +50) // | | // | + | // | | // (-50,+50, -50) ----------------- (+50, +50, -50) // // (-50,-50, +50) ----------------- (+50, -50, +50) // | | // | + | // | | // (-50,-50, -50) ----------------- (+50, -50, -50) const float w = 30.f; g_vertices.reserve(128); g_vertices.push_back( Vector3(-w,w,w) ); g_vertices.push_back( Vector3(w,w,w) ); g_vertices.push_back( Vector3(w,w,-w) ); g_vertices.push_back( Vector3(-w,w,-w) ); g_vertices.push_back( Vector3(-w,-w,w) ); g_vertices.push_back( Vector3(w,-w,w) ); g_vertices.push_back( Vector3(w,-w,-w) ); g_vertices.push_back( Vector3(-w,-w,-w) ); g_indices.reserve(128); // top g_indices.push_back(0); g_indices.push_back(2); g_indices.push_back(3); g_indices.push_back(0); g_indices.push_back(1); g_indices.push_back(2); // front g_indices.push_back(3); g_indices.push_back(2); g_indices.push_back(7); g_indices.push_back(2); g_indices.push_back(6); g_indices.push_back(7); // back g_indices.push_back(1); g_indices.push_back(4); g_indices.push_back(5); g_indices.push_back(1); g_indices.push_back(0); g_indices.push_back(4); // left g_indices.push_back(3); g_indices.push_back(4); g_indices.push_back(0); g_indices.push_back(7); g_indices.push_back(4); g_indices.push_back(3); // right g_indices.push_back(2); g_indices.push_back(5); g_indices.push_back(6); g_indices.push_back(2); g_indices.push_back(1); g_indices.push_back(5); // bottom g_indices.push_back(4); g_indices.push_back(7); g_indices.push_back(6); g_indices.push_back(4); g_indices.push_back(6); g_indices.push_back(5); g_matWorld.SetIdentity(); g_matWorld.Translate(Vector3(0,0,0)); g_matLocal.SetIdentity(); g_matView.SetIdentity(); Vector3 dir = g_cameraLookat - g_cameraPos; dir.Normalize(); g_matView.SetView(g_cameraPos, dir, Vector3(0,1,0)); g_matProjection.SetProjection( MATH_PI / 4.f, 1.0f, 1.0f, 100.0f ); const float width = 800.f; const float height = 600.f; g_matViewPort.SetIdentity(); g_matViewPort._11 = width/2; g_matViewPort._22 = -height/2; g_matViewPort._33 = 0; g_matViewPort._41 = width/2; g_matViewPort._42 = height/2; g_matViewPort._43 = 0; if (!InitInstance (hInstance, nCmdShow)) { return FALSE; } MSG msg; HACCEL hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_SOFTWARERENDERER)); int oldT = GetTickCount(); while (1) { if (PeekMessageA(&msg, NULL, 0, 0, PM_REMOVE)) { if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) { TranslateMessage(&msg); DispatchMessage(&msg); } if(msg.message == WM_QUIT) break; } const int curT = GetTickCount(); const int elapseT = curT - oldT; if (elapseT > 15) { oldT = curT; MainLoop(elapseT); } } return (int) msg.wParam; }