void CError::Start ( char* fname ) { if ( fname != 0x0 && strlen(fname) > 0 ) { // Read error message file. NOT YET IMPLEMENTED } else { debug.Print ( "error", "No error file loaded." ); } debug.Print ( "error", "Error handler started." ); m_bStarted = true; }
void CError::OutputMessage () { // Create sysbox message std::string box_msg; box_msg = "Subsystem: " + m_ErrorSubsys + "\n\n"; box_msg += "Error: " + m_ErrorMsg + "\n"; if ( m_ErrorExtra.length() > 0) box_msg += "Info: " + m_ErrorExtra + "\n"; if ( m_ErrorFix.length() > 0) box_msg += "\nFix: " + m_ErrorFix + "\n"; if ( m_ErrorID.length() > 0 ) box_msg += "Error ID: " + m_ErrorID + "\n"; if ( m_ErrorFunc.length() > 0 ) box_msg += "Function: " + m_ErrorFunc + "\n"; // Error output to debug file debug.PrintErr ( m_ErrorID, m_ErrorSubsys, m_ErrorMsg, box_msg ); }
void RecreateOctree() { // You will not need this function for the octree. It is just for the tutorial // every time we change our subdivision information. g_EndNodeCount = 0; // Reset the end node count g_Debug.Clear(); // Clear the list of debug lines g_Octree.DestroyOctree(); // Destroy the octree and start again // Get the new scene dimensions since we destroyed the previous octree g_Octree.GetSceneDimensions(g_pVertices, g_NumberOfVerts); // Create our new octree with the new subdivision information g_Octree.CreateNode(g_pVertices, g_NumberOfVerts, g_Octree.GetCenter(), g_Octree.GetWidth()); }
void RenderScene() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); // Reset The matrix // Position the camera g_Camera.Look(); // Each frame we calculate the new frustum. In reality you only need to // calculate the frustum when we move the camera. g_Frustum.CalculateFrustum(); // Initialize the total node count that is being draw per frame g_TotalNodesDrawn = 0; /////// * /////////// * /////////// * NEW * /////// * /////////// * /////////// * // Here we draw the octree, starting with the root node and recursing down each node. // This time, we pass in the root node and just the original world model. You could // just store the world in the root node and not have to keep the original data around. // This is up to you. I like this way better because it's easy, though it could be // more error prone. g_Octree.DrawOctree(&g_Octree, &g_World); // Render the cubed nodes to visualize the octree (in wire frame mode) if( g_bDisplayNodes ) g_Debug.RenderDebugLines(); // Create a buffer to store the octree information for the title bar static char strBuffer[255] = {0}; // Display in window mode the current subdivision information. We now display the // max triangles per node, the max level of subdivision, total end nodes, current nodes drawn // and frames per second we are receiving. sprintf(strBuffer, "Triangles: %d Subdivisions: %d EndNodes: %d NodesDraw: %d FPS: %s", g_MaxTriangles, g_MaxSubdivisions, g_EndNodeCount, g_TotalNodesDrawn, g_strFrameRate); /////// * /////////// * /////////// * NEW * /////// * /////////// * /////////// * // Set our window title bar to the subdivision information SetWindowText(g_hWnd, strBuffer); // Swap the backbuffers to the foreground SwapBuffers(g_hDC); }
void RenderScene() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer glLoadIdentity(); // Reset The matrix // Give OpenGL our camera position g_Camera.Look(); /////// * /////////// * /////////// * NEW * /////// * /////////// * /////////// * // Each frame we calculate the new frustum. In reality you only need to // calculate the frustum when we move the camera. g_Frustum.CalculateFrustum(); // Initialize the total node count that is being draw per frame g_TotalNodesDrawn = 0; /////// * /////////// * /////////// * NEW * /////// * /////////// * /////////// * // Here we draw the octree, starting with the root node and recursing down each node. // When we get to each of the end nodes we will draw the vertices assigned to them. g_Octree.DrawOctree(&g_Octree); // Render the cube'd nodes to visualize the octree (in wire frame mode) g_Debug.RenderDebugLines(); SwapBuffers(g_hDC); // Swap the backbuffers to the foreground char strBuffer[255] = {0}; // Create a character buffer // To view our octree information I set the window's title bar to the some basic // information such as the max triangles per node, the max subdivisions, // total end nodes and the total drawn end nodes that are currently in the frustum. // Display in window mode the current subdivision information sprintf(strBuffer, "MaxTriangles: %d MaxSubdivisions: %d TotalEndNodes: %d TotalNodesDraw: %d", g_MaxTriangles, g_MaxSubdivisions, g_EndNodeCount, g_TotalNodesDrawn); // Set our window title bar to the subdivision data SetWindowText(g_hWnd, strBuffer); }
void COctree::CreateNode(CVector3 *pVertices, int numberOfVerts, CVector3 vCenter, float width) { // This is our main function that creates the octree. We will recurse through // this function until we finish subdividing. Either this will be because we // subdivided too many levels or we divided all of the triangles up. // Create a variable to hold the number of triangles int numberOfTriangles = numberOfVerts / 3; // Initialize this node's center point. Now we know the center of this node. m_vCenter = vCenter; // Initialize this nodes cube width. Now we know the width of this current node. m_Width = width; // Add the current node to our debug rectangle list so we can visualize it. // We can now see this node visually as a cube when we render the rectangles. // Since it's a cube we pass in the width for width, height and depth. g_Debug.AddDebugRectangle(vCenter, width, width, width); // Check if we have too many triangles in this node and we haven't subdivided // above our max subdivisions. If so, then we need to break this node into // 8 more nodes (hence the word OCTree). Both must be true to divide this node. if( (numberOfTriangles > g_MaxTriangles) && (g_CurrentSubdivision < g_MaxSubdivisions) ) { // Since we need to subdivide more we set the divided flag to true. // This let's us know that this node does NOT have any vertices assigned to it, // but nodes that perhaps have vertices stored in them (Or their nodes, etc....) // We will querey this variable when we are drawing the octree. m_bSubDivided = true; // Create a list for each new node to store if a triangle should be stored in it's // triangle list. For each index it will be a true or false to tell us if that triangle // is in the cube of that node. Below we check every point to see where it's // position is from the center (I.E. if it's above the center, to the left and // back it's the TOP_LEFT_BACK node). Depending on the node we set the pList // index to true. This will tell us later which triangles go to which node. // You might catch that this way will produce doubles in some nodes. Some // triangles will intersect more than 1 node right? We won't split the triangles // in this tutorial just to keep it simple, but the next tutorial we will. // Create the list of booleans for each triangle index vector<bool> pList1(numberOfTriangles); // TOP_LEFT_FRONT node list vector<bool> pList2(numberOfTriangles); // TOP_LEFT_BACK node list vector<bool> pList3(numberOfTriangles); // TOP_RIGHT_BACK node list vector<bool> pList4(numberOfTriangles); // TOP_RIGHT_FRONT node list vector<bool> pList5(numberOfTriangles); // BOTTOM_LEFT_FRONT node list vector<bool> pList6(numberOfTriangles); // BOTTOM_LEFT_BACK node list vector<bool> pList7(numberOfTriangles); // BOTTOM_RIGHT_BACK node list vector<bool> pList8(numberOfTriangles); // BOTTOM_RIGHT_FRONT node list // Create this variable to cut down the thickness of the code below (easier to read) CVector3 vCtr = vCenter; // Go through all of the vertices and check which node they belong too. The way // we do this is use the center of our current node and check where the point // lies in relationship to the center. For instance, if the point is // above, left and back from the center point it's the TOP_LEFT_BACK node. // You'll see we divide by 3 because there are 3 points in a triangle. // If the vertex index 0 and 1 are in a node, 0 / 3 and 1 / 3 is 0 so it will // just set the 0'th index to TRUE twice, which doesn't hurt anything. When // we get to the 3rd vertex index of pVertices[] it will then be checking the // 1st index of the pList*[] array. We do this because we want a list of the // triangles in the node, not the vertices. for(int i = 0; i < numberOfVerts; i++) { // Create some variables to cut down the thickness of the code (easier to read) CVector3 vPoint = pVertices[i]; // Check if the point lines within the TOP LEFT FRONT node if( (vPoint.x <= vCtr.x) && (vPoint.y >= vCtr.y) && (vPoint.z >= vCtr.z) ) pList1[i / 3] = true; // Check if the point lines within the TOP LEFT BACK node if( (vPoint.x <= vCtr.x) && (vPoint.y >= vCtr.y) && (vPoint.z <= vCtr.z) ) pList2[i / 3] = true; // Check if the point lines within the TOP RIGHT BACK node if( (vPoint.x >= vCtr.x) && (vPoint.y >= vCtr.y) && (vPoint.z <= vCtr.z) ) pList3[i / 3] = true; // Check if the point lines within the TOP RIGHT FRONT node if( (vPoint.x >= vCtr.x) && (vPoint.y >= vCtr.y) && (vPoint.z >= vCtr.z) ) pList4[i / 3] = true; // Check if the point lines within the BOTTOM LEFT FRONT node if( (vPoint.x <= vCtr.x) && (vPoint.y <= vCtr.y) && (vPoint.z >= vCtr.z) ) pList5[i / 3] = true; // Check if the point lines within the BOTTOM LEFT BACK node if( (vPoint.x <= vCtr.x) && (vPoint.y <= vCtr.y) && (vPoint.z <= vCtr.z) ) pList6[i / 3] = true; // Check if the point lines within the BOTTOM RIGHT BACK node if( (vPoint.x >= vCtr.x) && (vPoint.y <= vCtr.y) && (vPoint.z <= vCtr.z) ) pList7[i / 3] = true; // Check if the point lines within the BOTTOM RIGHT FRONT node if( (vPoint.x >= vCtr.x) && (vPoint.y <= vCtr.y) && (vPoint.z >= vCtr.z) ) pList8[i / 3] = true; } // Here we create a variable for each list that holds how many triangles // were found for each of the 8 subdivided nodes. int triCount1 = 0; int triCount2 = 0; int triCount3 = 0; int triCount4 = 0; int triCount5 = 0; int triCount6 = 0; int triCount7 = 0; int triCount8 = 0; // Go through each of the lists and increase the triangle count for each node. for(int i = 0; i < numberOfTriangles; i++) { // Increase the triangle count for each node that has a "true" for the index i. if(pList1[i]) triCount1++; if(pList2[i]) triCount2++; if(pList3[i]) triCount3++; if(pList4[i]) triCount4++; if(pList5[i]) triCount5++; if(pList6[i]) triCount6++; if(pList7[i]) triCount7++; if(pList8[i]) triCount8++; } // Next we do the dirty work. We need to set up the new nodes with the triangles // that are assigned to each node, along with the new center point of the node. // Through recursion we subdivide this node into 8 more nodes. // Create the subdivided nodes if necessary and then recurse through them. // The information passed into CreateNewNode() are essential for creating the // new nodes. We pass the 8 ID's in so it knows how to calculate it's new center. CreateNewNode(pVertices, pList1, numberOfVerts, vCenter, width, triCount1, TOP_LEFT_FRONT); CreateNewNode(pVertices, pList2, numberOfVerts, vCenter, width, triCount2, TOP_LEFT_BACK); CreateNewNode(pVertices, pList3, numberOfVerts, vCenter, width, triCount3, TOP_RIGHT_BACK); CreateNewNode(pVertices, pList4, numberOfVerts, vCenter, width, triCount4, TOP_RIGHT_FRONT); CreateNewNode(pVertices, pList5, numberOfVerts, vCenter, width, triCount5, BOTTOM_LEFT_FRONT); CreateNewNode(pVertices, pList6, numberOfVerts, vCenter, width, triCount6, BOTTOM_LEFT_BACK); CreateNewNode(pVertices, pList7, numberOfVerts, vCenter, width, triCount7, BOTTOM_RIGHT_BACK); CreateNewNode(pVertices, pList8, numberOfVerts, vCenter, width, triCount8, BOTTOM_RIGHT_FRONT); } else { // If we get here we must either be subdivided past our max level, or our triangle // count went below the minimum amount of triangles so we need to store them. // Assign the vertices to this node since we reached the end node. // This will be the end node that actually gets called to be drawn. // We just pass in the vertices and vertex count to be assigned to this node. AssignVerticesToNode(pVertices, numberOfVerts); } }
//============================================================================= // エントリー関数 //============================================================================= int APIENTRY WinMain(HINSTANCE _instanceHandle ,HINSTANCE _instanceHandlePrev, LPSTR _cmdLine, int _cmdShow) { _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF); UNREFERENCED_PARAMETER(_instanceHandlePrev); UNREFERENCED_PARAMETER(_cmdLine); DWORD execLastTime; DWORD LastTimeFPS; DWORD currentTime; DWORD flameCount; WNDCLASSEX wcex = { sizeof(WNDCLASSEX), CS_CLASSDC, WndProc, 0, 0, _instanceHandle, NULL, LoadCursor(NULL, IDC_ARROW), (HBRUSH)(COLOR_WINDOW + 1), NULL, CLASS_NAME, NULL }; HWND windowHandle; MSG msg; // ウィンドウクラスの登録 RegisterClassEx(&wcex); // ウィンドウの作成 windowHandle = CreateWindowEx(0, CLASS_NAME, WINDOW_NAME, WS_OVERLAPPEDWINDOW & ~WS_MAXIMIZEBOX & ~WS_THICKFRAME, CW_USEDEFAULT, CW_USEDEFAULT, static_cast<int>(SCREEN_WIDTH + GetSystemMetrics(SM_CXDLGFRAME) * 2), static_cast<int>(SCREEN_HEIGHT + GetSystemMetrics(SM_CXDLGFRAME) * 2 + GetSystemMetrics(SM_CYCAPTION)), NULL, NULL, _instanceHandle, NULL); // フレームカウント初期化 timeBeginPeriod(1); // 分解能を設定 execLastTime = LastTimeFPS = timeGetTime(); currentTime = flameCount = 0; // ウインドウの表示(初期化処理の後に呼ばないと駄目) ShowWindow(windowHandle, _cmdShow); UpdateWindow(windowHandle); #ifndef _DEBUG LoadLibraryA("WiiYourself.dll"); #else LoadLibraryA("WiiYourself_debug.dll"); #endif LPDIRECT3D9 direct3D; // Direct3D9用デバイス LPDIRECT3DDEVICE9 device; // _deviceオブジェクト(描画に必要) D3DDISPLAYMODE displayMode; D3DPRESENT_PARAMETERS presentParameter; // Direct3Dオブジェクトの作成 direct3D = Direct3DCreate9(D3D_SDK_VERSION); direct3D->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &displayMode); // デバイスのプレゼンテーションパラメータの設定 //-------------------------------------------------------------------- // ワークをゼロクリア ZeroMemory(&presentParameter, sizeof(presentParameter)); // バックバッファの数をセット presentParameter.BackBufferCount = 1; //ゲーム画面サイズ presentParameter.BackBufferWidth = static_cast<int>SCREEN_WIDTH; presentParameter.BackBufferHeight = static_cast<int>SCREEN_HEIGHT; // バックバッファフォーマットはディスプレイモードに合わせて使う presentParameter.BackBufferFormat = displayMode.Format; // 映像信号に同期してフリップする presentParameter.SwapEffect = D3DSWAPEFFECT_DISCARD; // ウィンドウモード presentParameter.Windowed = TRUE; // デプスバッファ(Zバッファ)とステンシルバッファを作成 presentParameter.EnableAutoDepthStencil = TRUE; // デプスバッファの利用方法 // D3DFMT_D16 デプスバッファのみを16bitとして扱う // D3DFMT_D24S8 デプスバッファを24bit ステンシルバッファを8bitとして扱う presentParameter.AutoDepthStencilFormat = D3DFMT_D24S8; // ウィンドウモード presentParameter.FullScreen_RefreshRateInHz = 0; presentParameter.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE; //-------------------------------------------------------------------- direct3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, windowHandle, D3DCREATE_HARDWARE_VERTEXPROCESSING, &presentParameter, &device); CDebug* debug = new CDebug(); debug->Init(device); CKeyboard* keyboard = new CKeyboard(); keyboard->Init(_instanceHandle, windowHandle); CMouse* mouse = new CMouse(); mouse->Init(_instanceHandle, windowHandle); CWiiController* wiiController = new CWiiController(); // メッセージループ for (;;) { if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { if (msg.message == WM_QUIT) { // PostQuitMessage()が呼ばれたらループ終了 break; } else { // メッセージの翻訳とディスパッチ TranslateMessage(&msg); DispatchMessage(&msg); } } else { currentTime = timeGetTime(); if ((currentTime - LastTimeFPS) >= 500) { #ifdef _DEBUG countFPS = flameCount * 1000 / (currentTime - LastTimeFPS); #endif LastTimeFPS = currentTime; flameCount = 0; } if ((currentTime - execLastTime) >= (1000 / 60)) { execLastTime = currentTime ; keyboard->Update(); mouse->Update(); wiiController->update(); { // 本体 { debug->SetDebug("本体の加速度X [%f]\n", wiiController->getAccelerationX()); debug->SetDebug("本体の加速度Y [%f]\n", wiiController->getAccelerationY()); debug->SetDebug("本体の加速度Z [%f]\n", wiiController->getAccelerationZ()); debug->SetDebug("本体の回転角X [%f]\n", wiiController->getRotX()); debug->SetDebug("本体の回転角Y [%f]\n", wiiController->getRotY()); debug->SetDebug("本体の回転角Z [%f]\n", wiiController->getRotZ()); debug->SetDebug("本体の回転角の変異X [%f]\n", wiiController->getChangeRotX()); debug->SetDebug("本体の回転角の変異Y [%f]\n", wiiController->getChangeRotY()); debug->SetDebug("本体の回転角の変異Z [%f]\n", wiiController->getChangeRotZ()); debug->SetDebug("本体の角速度X [%f]\n", wiiController->getRotSpeedX()); debug->SetDebug("本体の角速度Y [%f]\n", wiiController->getRotSpeedY()); debug->SetDebug("本体の角速度Z [%f]\n", wiiController->getRotSpeedZ()); } // ヌンチャク { debug->SetDebug("ヌンチャクの加速度X [%f]\n", wiiController->getAccelerationNX()); debug->SetDebug("ヌンチャクの加速度Y [%f]\n", wiiController->getAccelerationNY()); debug->SetDebug("ヌンチャクの加速度Z [%f]\n", wiiController->getAccelerationNZ()); debug->SetDebug("ヌンチャクの回転角X [%f]\n", wiiController->getRotNX()); debug->SetDebug("ヌンチャクの回転角Y [%f]\n", wiiController->getRotNY()); debug->SetDebug("ヌンチャクの回転角Z [%f]\n", wiiController->getRotNZ()); debug->SetDebug("ヌンチャクの位置X [%f]\n", wiiController->getJoystick().x); debug->SetDebug("ヌンチャクの位置Y [%f]\n", wiiController->getJoystick().y); } // 赤外線 { debug->SetDebug("赤外線X [%f]\n", wiiController->getIR().x); debug->SetDebug("赤外線Y [%f]\n", wiiController->getIR().y); } debug->SetDebug("バッテリー残量[%d%]\n", wiiController->battery()); debug->SetDebug("モーションPlusの接続状態[%d]\n", wiiController->getMotionConnect()); /*if (wiiController->getTrigger(WC_A)) wiiController->rumble(true); if (wiiController->getTrigger(WC_B)) wiiController->rumble(false); if (wiiController->getTrigger(WC_UP)) wiiController->rumble((unsigned int)1000);*/ // Aボタン { if (wiiController->getPress(WC_A)) debug->SetDebug("A [ON]\n"); else debug->SetDebug("A [OFF]\n"); } // Bボタン { if (wiiController->getPress(WC_B)) debug->SetDebug("B [ON]\n"); else debug->SetDebug("B [OFF]\n"); } // Cボタン { if (wiiController->getPress(WC_C)) debug->SetDebug("C [ON]\n"); else debug->SetDebug("C [OFF]\n"); } // Zボタン { if (wiiController->getPress(WC_Z)) debug->SetDebug("Z [ON]\n"); else debug->SetDebug("Z [OFF]\n"); } // ↑ボタン { if (wiiController->getPress(WC_UP)) debug->SetDebug("UP [ON]\n"); else debug->SetDebug("UP [OFF]\n"); } // ↓ボタン { if (wiiController->getPress(WC_DOWN)) debug->SetDebug("DOWN [ON]\n"); else debug->SetDebug("DOWN [OFF]\n"); } // ←ボタン { if (wiiController->getPress(WC_LEFT)) debug->SetDebug("LEFT [ON]\n"); else debug->SetDebug("LEFT [OFF]\n"); } // →ボタン { if (wiiController->getPress(WC_RIGHT)) debug->SetDebug("RIGHT [ON]\n"); else debug->SetDebug("RIGHT [OFF]\n"); } // -ボタン { if (wiiController->getPress(WC_MINUS)) debug->SetDebug("MINUS [ON]\n"); else debug->SetDebug("MINUS [OFF]\n"); if(wiiController->getTrigger(WC_MINUS)) wiiController->rotSpeedCalibration(); } // +ボタン { if (wiiController->getPress(WC_PLUS)) debug->SetDebug("PLUS [ON]\n"); else debug->SetDebug("PLUS [OFF]\n"); if(wiiController->getTrigger(WC_PLUS)) wiiController->rotReset(); } // 1ボタン { if (wiiController->getPress(WC_ONE)) debug->SetDebug("ONE [ON]\n"); else debug->SetDebug("ONE [OFF]\n"); } // 2ボタン { if (wiiController->getPress(WC_TWO)) debug->SetDebug("TWO [ON]\n"); else debug->SetDebug("TWO [OFF]\n"); } // HOMEボタン { if (wiiController->getPress(WC_HOME)) debug->SetDebug("HOME [ON]\n"); else debug->SetDebug("HOME [OFF]\n"); } } // バックバッファ&Zバッファのクリア device->Clear(0, NULL, (D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER), D3DCOLOR_RGBA(255, 255, 255, 255), 1.0f, 0); // Direct3Dによる描画の開始 if (SUCCEEDED(device->BeginScene())) { CDebug::Draw(); // Direct3Dによる描画の終了 device->EndScene(); } // バックバッファとフロントバッファの入れ替える device->Present(NULL, NULL, NULL, NULL); flameCount++; } } } SAFE_DELETE(wiiController); SAFE_DELETE(keyboard); SAFE_DELETE(mouse); SAFE_DELETE(debug); // ウィンドウクラスの登録を解除 UnregisterClass(CLASS_NAME, wcex.hInstance); timeEndPeriod(1); // 分解能を戻す return static_cast<int>(msg.wParam); }
// User-defined operator delete. void operator delete( void *pvMem ) { debug.Printf ( "DELETE %p\n", pvMem ); free ( pvMem ); }
// User-defined operator new. void *operator new( size_t stSize ) { void* pvMem = malloc( stSize ); debug.Printf ( "NEW %p (%d bytes)\n", pvMem, stSize ); return pvMem; }
void CError::Exit ( int code ) { debug.Exit ( code ); }