Jump to content
  • Advertisement

TommyThree

Member
  • Content Count

    22
  • Joined

  • Last visited

Community Reputation

180 Neutral

About TommyThree

  • Rank
    Member

Personal Information

  • Interests
    Art
    Programming

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. I'm trying to make my code more organized and structured. I thought to have things such as a render system, input system, etc and have a message system send messages between each system. Sometimes I need data with the message like for example more than one system needs access to the directx device so I would like to pass that around. I had something that I was trying to make work but then halfway through I realized there was a circular dependency in the headers that I couldn't resolve. So what's a good way to pass data between your different systems?
  2. Polishing the game. I can make a game easily, done it before. But I have trouble putting in the little details that make people actually want to play it. That's why I wish I had an artist friend or something...so I could focus on the programming only and they could put all their time into the art. If I had someone who did art like I do code (like 8 hrs a day) we would make quite a team. O_o
  3. I used XMVectorUnproject to pick the screen. DirectX::XMVECTOR testpick::update(int x, int y, float width, float height, float nearZ, float farZ, DirectX::XMMATRIX projection, DirectX::XMMATRIX view) { DirectX::XMVECTOR mouseNear = DirectX::XMVectorSet((float)x, (float)y, 0.0f, 0.0f); DirectX::XMVECTOR mouseFar = DirectX::XMVectorSet((float)x, (float)y, 1.0f, 0.0f); DirectX::XMVECTOR unprojectedNear = DirectX::XMVector3Unproject(mouseNear, 0, 0, width, height, nearZ, farZ, projection, view, DirectX::XMMatrixIdentity()); DirectX::XMVECTOR unprojectedFar = DirectX::XMVector3Unproject(mouseFar, 0, 0, width, height, nearZ, farZ, projection, view, DirectX::XMMatrixIdentity()); DirectX::XMVECTOR dir = DirectX::XMVector3Normalize(DirectX::XMVectorSubtract(unprojectedFar, unprojectedNear)); return dir; } XMVECTOR origin = cam.GetPositionXM(); XMVECTOR dir = testpkr.update(pt.x, pt.y, Width, Height, 1.0f, 1000.0f, cam.Proj(), cam.View()); float temp; if (meshList[0].AABB_Box.Intersects(origin, dir, temp)) { aLog.AddLog(meshList[0].name.append("\n").c_str()); } if (meshList[1].AABB_Box.Intersects(origin, dir, temp)) { aLog.AddLog(meshList[1].name.append("\n").c_str()); } if (meshList[2].AABB_Box.Intersects(origin, dir, temp)) { aLog.AddLog(meshList[2].name.append("\n").c_str()); }
  4. I have some code I got off the net. It finds the direction of a ray when you click the screen. When I set the ray origin to 0,0,0 and direction to the calculated direction (see below code) it detects intersections on objects that are at the origin only. If I set the origin to the camera position, nothing happens. No intersections. The code in the Luna book does the same thing. What am I missing? MousePicker::MousePicker(DirectX::XMMATRIX proj, DirectX::XMMATRIX view) { projectionMatrix = proj; viewMatrix = view; } MousePicker::MousePicker() { } DirectX::XMFLOAT3 MousePicker::getCurrentRay() { return currentRay; } DirectX::XMVECTOR MousePicker::getCurrentRayXM() { return DirectX::XMLoadFloat3(&currentRay); } void MousePicker::update(DirectX::XMMATRIX view, float x, float y, float width, float height) { viewMatrix = view; currentRay = calculateMouseRay(x, y, width, height); } DirectX::XMFLOAT3 MousePicker::calculateMouseRay(float x, float y, float width, float height) { float mouseX = x; float mouseY = y; DirectX::XMFLOAT2 normalizedCoords = getNormalizedDeviceCoords(x, y, width, height); DirectX::XMFLOAT4 clipCoords = DirectX::XMFLOAT4(normalizedCoords.x, normalizedCoords.y, -1.0f, 1.0f); DirectX::XMFLOAT4 eyeCoord = toEyeCoords(clipCoords); DirectX::XMFLOAT3 worldRay = toWorldCoords(eyeCoord); return worldRay; } DirectX::XMFLOAT2 MousePicker::getNormalizedDeviceCoords(float mouseX, float mouseY, float width, float height) { float x = (2.0f*mouseX) / width - 1.0f; float y = (2.0f*mouseY) / height - 1.0f; return DirectX::XMFLOAT2(x, -y); } DirectX::XMFLOAT4 MousePicker::toEyeCoords(DirectX::XMFLOAT4 clipCoords) { DirectX::XMVECTOR clip = DirectX::XMLoadFloat4(&clipCoords); DirectX::XMMATRIX invertedProj = DirectX::XMMatrixInverse(nullptr, projectionMatrix); DirectX::XMVECTOR eyeCoords = DirectX::XMVector4Transform(clip, invertedProj); DirectX::XMFLOAT4 eyeCoord; DirectX::XMStoreFloat4(&eyeCoord, eyeCoords); return DirectX::XMFLOAT4(eyeCoord.x, eyeCoord.y, -1.0f, 0.0f); } DirectX::XMFLOAT3 MousePicker::toWorldCoords(DirectX::XMFLOAT4 eyeCoords) { DirectX::XMVECTOR eyeCoord = DirectX::XMLoadFloat4(&eyeCoords); DirectX::XMMATRIX invertedView = DirectX::XMMatrixInverse(nullptr, viewMatrix); DirectX::XMVECTOR rayWorld = DirectX::XMVector4Transform(eyeCoord, invertedView); DirectX::XMFLOAT4 ray; DirectX::XMStoreFloat4(&ray, rayWorld); DirectX::XMFLOAT3 mouseRay = DirectX::XMFLOAT3(ray.x, ray.y, ray.z); DirectX::XMVECTOR mRay = DirectX::XMVector3Normalize(DirectX::XMLoadFloat3(&mouseRay)); DirectX::XMFLOAT3 mouseR; DirectX::XMStoreFloat3(&mouseR, mRay); return mouseR; } MousePicker::~MousePicker() { } float temp; XMVECTOR origin = XMVectorSet(0.0f, 0.0f, 0.0f, 0.0f); if (meshList[0].AABB_Box.Intersects(origin, mp.getCurrentRayXM(), temp) ) { MessageBoxA(NULL, meshList[0].name.c_str(), "0", MB_OK); } if (meshList[1].AABB_Box.Intersects(origin, mp.getCurrentRayXM(), temp)) { MessageBoxA(NULL, meshList[1].name.c_str(), "1", MB_OK); } if (meshList[2].AABB_Box.Intersects(origin, mp.getCurrentRayXM(), temp)) { MessageBoxA(NULL, meshList[2].name.c_str(), "2", MB_OK); }
  5. TommyThree

    Find center and extents of AABB box

    Ahh thx. that was the problem.
  6. I have a function: void findMinMax(XMFLOAT3& center, XMFLOAT3& extents) { XMFLOAT3 vMin = XMFLOAT3(-INFINITY, -INFINITY, -INFINITY); XMFLOAT3 vMax = XMFLOAT3(INFINITY, INFINITY, INFINITY); XMVECTOR min = XMLoadFloat3(&vMin); XMVECTOR max = XMLoadFloat3(&vMax); for (int i = 0; i < meshList[0].vertices.size(); i++) { XMVECTOR p = XMLoadFloat3(&meshList[0].vertices[i].pos); min = XMVectorMin(min, p); max = XMVectorMax(max, p); } XMVECTOR c = 0.5f *(min + max); XMVECTOR e = 0.5f*(max - min); XMStoreFloat3(&center, c); XMStoreFloat3(&extents, e); } ...got it out of the frank luna book. IT's supposed to find the extents and center of a AABB box I think. What am I doing wrong because its not working? The box doesn't draw. It draws when I put other values just not these vectors.
  7. TommyThree

    Cam class won't work

    Atm I'm focusing on a camera like what's in Unity or Unreal...so 6DOF I think. I want a first person camera with wasd movement but also q and e to move up and down. I'm making a game editor. I'm reading a game math book and slowly wrapping my head around how to do a camera myself but if anyone has any code that works I'll take it. 😮
  8. TommyThree

    Cam class won't work

    I found some camera code on the net and tried to use it. It was really old so I converted it and the wasd works but the mouse look doesn't. It's giving strange results. I was wondering if anyone can see something in the math thats wrong? Like in the pitch and yaw functions for example. #include "CCamera.h" /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Summary: Default constructor * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ CCamera::CCamera() { m_maxPitch =DirectX::XMConvertToRadians(89.0f); m_maxVelocity = 1.0f; m_invertY = false; m_enableYMovement = true; m_position = DirectX::XMVectorSet(0.0f, 0.0f, 0.0f, 0.0f); m_velocity = DirectX::XMVectorSet(0.0f, 0.0f, 0.0f, 0.0f); m_look = DirectX::XMVectorSet(0.0f, 0.0f, 1.0f, 0.0f); CreateProjectionMatrix(DirectX::XMConvertToRadians(45.0f), 1920.0f / 1080.0f, 1.0f, 1000.0f); Update(); } /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Summary: Creates the projection matrix. Parameters: [in] fov - Field of view [in] aspect - Aspect ratio [in] near - Near plane [in] far - Far plane * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ void CCamera::CreateProjectionMatrix(float fov, float aspect, float nearPlane, float farPlane) { m_fov = fov; m_aspect = aspect; m_nearPlane = nearPlane; m_farPlane = farPlane; m_projection = DirectX::XMMatrixPerspectiveFovLH(m_fov, m_aspect, m_nearPlane, m_farPlane); } /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Summary: Moves the camera forward and backward Parameters: [in] units - Amount to move * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ void CCamera::MoveForward(float units) { if (m_enableYMovement) { DirectX::XMVECTOR vec = DirectX::XMVectorScale(m_look, units); m_velocity = DirectX::XMVectorAdd(m_velocity, vec); } else { DirectX::XMFLOAT3 look; DirectX::XMStoreFloat3(&look, m_look); DirectX::XMVECTOR moveVector = DirectX::XMVectorSet(look.x, look.y, look.z, 0.0f); moveVector = DirectX::XMVector3Normalize(moveVector); moveVector = DirectX::XMVectorScale(moveVector, units); moveVector = DirectX::XMVectorAdd(m_velocity, moveVector); } } /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Summary: Moves the camera left and right Parameters: [in] units - Amount to move * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ void CCamera::Strafe(float units) { DirectX::XMVECTOR scaledRight = DirectX::XMVectorScale(m_right, units); m_velocity = DirectX::XMVectorAdd(m_velocity, scaledRight); } /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Summary: Moves the camera up and down Parameters: [in] units - Amount to move * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ void CCamera::MoveUp(float units) { if (m_enableYMovement) { DirectX::XMFLOAT3 vel; DirectX::XMStoreFloat3(&vel, m_velocity); m_velocity = DirectX::XMVectorSet(vel.x, vel.y + units, vel.z, 0.0f); } } /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Summary: Yaw the camera around its Y-axis. Parameters: [in] radians - Radians to yaw. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ void CCamera::Yaw(float radians) { if (radians == 0.0f) { return; } DirectX::XMMATRIX rotation; rotation = DirectX::XMMatrixRotationAxis(m_up, radians); m_right = DirectX::XMVector3TransformNormal(m_right, rotation); m_look = DirectX::XMVector3TransformNormal(m_look, rotation); } /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Summary: Pitch the camera around its X-axis. Parameters: [in] radians - Radians to pitch. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ void CCamera::Pitch(float radians) { if (radians == 0.0f) { return; } radians = (m_invertY) ? -radians : radians; m_pitch -= radians; if (m_pitch > m_maxPitch) { radians += m_pitch - m_maxPitch; } else if (m_pitch < -m_maxPitch) { radians += m_pitch + m_maxPitch; } DirectX::XMMATRIX rotation; rotation = DirectX::XMMatrixRotationAxis(m_right, radians); m_up = DirectX::XMVector3TransformNormal(m_up, rotation); m_look = DirectX::XMVector3TransformNormal(m_look, rotation); } /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Summary: Roll the camera around its Z-axis. Parameters: [in] radians - Radians to roll. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ void CCamera::Roll(float radians) { if (radians == 0.0f) { return; } DirectX::XMMATRIX rotation; rotation = DirectX::XMMatrixRotationAxis(m_look, radians); DirectX::XMVector3TransformNormal(m_right, rotation); DirectX::XMVector3TransformNormal(m_up, rotation); } /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Summary: Updates the camera and creates a new view matrix. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ void CCamera::Update() { // Cap velocity to max velocity /* if (D3DXVec3Length(&m_velocity) > m_maxVelocity) { m_velocity = *(D3DXVec3Normalize(&m_velocity, &m_velocity)) * m_maxVelocity; }*/ // Move the camera m_position = DirectX::XMVectorAdd(m_position, m_velocity); // Could decelerate here. I'll just stop completely. m_velocity = DirectX::XMVectorSet(0.0f, 0.0f, 0.0f, 0.0f); m_lookAt = DirectX::XMVectorAdd(m_position, m_look); // Calculate the new view matrix DirectX::XMVECTOR up = DirectX::XMVectorSet(0.0f, 1.0f, 0.0f, 0.0f); m_view = DirectX::XMMatrixLookAtLH(m_position, m_lookAt, up); // Set the camera axes from the view matrix DirectX::XMFLOAT4X4 view; DirectX::XMStoreFloat4x4(&view, m_view); m_right = DirectX::XMVectorSet(view._11, view._21, view._31, 0.0f); m_up = DirectX::XMVectorSet(view._12, view._22, view._32, 0.0f); m_look = DirectX::XMVectorSet(view._13, view._23, view._33, 0.0f); // Calculate yaw and pitch DirectX::XMFLOAT3 look; DirectX::XMStoreFloat3(&look, m_look); float lookLengthOnXZ = sqrtf(look.z * look.z + look.x * look.x); m_pitch = atan2f(look.y, lookLengthOnXZ); m_yaw = atan2f(look.x, look.z); } /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Summary: Updates the camera and creates a new view matrix. Parameters: [in] pPosition - New position * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ void CCamera::SetPosition(DirectX::XMVECTOR* pPosition) { DirectX::XMFLOAT3 pos; DirectX::XMStoreFloat3(&pos, *(pPosition)); m_position = DirectX::XMVectorSet(pos.x, pos.y, pos.z, 0.0f); } /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Summary: Updates the camera and creates a new view matrix. Parameters: [in] pPosition - New target * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ void CCamera::SetLookAt(DirectX::XMVECTOR* pLookAt) { DirectX::XMFLOAT3 look; DirectX::XMStoreFloat3(&look, *(pLookAt)); m_lookAt = DirectX::XMVectorSet(look.x, look.y, look.z, 0.0f); DirectX::XMFLOAT3 la; DirectX::XMFLOAT3 p; DirectX::XMStoreFloat3(&la, m_lookAt); DirectX::XMStoreFloat3(&p, m_position); DirectX::XMVECTOR combined = DirectX::XMVectorSubtract(m_lookAt, m_position); m_lookAt = DirectX::XMVector3Normalize(combined); }
  9. TommyThree

    How do I pass this view and projection matrix?

    DirectX::XMFLOAT4X4 change_mat(DirectX::XMMATRIX mat) { DirectX::XMFLOAT4X4 temp; DirectX::XMStoreFloat4x4(&temp, mat); return temp; } ... DirectX::XMFLOAT4X4 v = change_mat(camView); DirectX::XMFLOAT4X4 p = change_mat(camProjection); DirectX::XMFLOAT4X4 w = change_mat(meshList[0].worldMat); ImGuizmo::SetRect(0, 0, io.DisplaySize.x,io.DisplaySize.y); ImGuizmo::Manipulate(&v.m[0][0], &p.m[0][0], mCurrentGizmoOperation, mCurrentGizmoMode, &w.m[0][0]);
  10. I'm using a library for gizmos (translate, rotate, scale) so that I can control my objects in a scene. I'm using this https://github.com/CedricGuillemet/ImGuizmo. There is a function called Manipulate that takes const float* as the type for a projection and view matrix. also float* for a matrix. I have those Matrices stored in a dx11 XMMATRIX. How do I pass that data?
  11. I was having trouble loading a model with assimp, nothing was showing up. I decided to strip down my code to bare minimum so I went here https://www.braynzarsoft.net/viewtutorial/q16390-9-transformations and copied the code. Removed the d3dx stuff in it and some other things and got it to compile. Still nothing is showing up on screen. The code from that site should work...it worked before. Is something wrong with my computer or something? It looks fine from all I can see...even in renderdoc. Renderdoc shows the vertices and indices correctly. Here is the code im using. Look at initdx, initscene, render, and updateScene and the shader. Doesn't everything look correct? I basically just copy/pasted the code and nothing is showing up. What would cause this? -edit- ok well i got it to show up but its distorted. Atleast something shows up. and I posted the wrong shader earlier. #include "Source.h" #include "DDSTextureLoader.h" //Global Declarations - Interfaces// IDXGISwapChain* SwapChain; ID3D11Device* d3d11Device; ID3D11DeviceContext* d3d11DevCon; ID3D11RenderTargetView* renderTargetView; ID3D11DepthStencilView* depthStencilView; ID3D11Texture2D* depthStencilBuffer; ID3D11Resource* tex; ID3D11RasterizerState * rasterState; ID3D11VertexShader* VS; ID3D11PixelShader* PS; ID3DBlob* VS_Blob; ID3DBlob* PS_Blob; ID3D11InputLayout* vertLayout; ID3D11Buffer* fbx_vertex_buf; ID3D11Buffer* fbx_index_buf; ID3D11Buffer* cbPerObjectBuffer; ID3D11ShaderResourceView* fbx_rc_view; ID3D11SamplerState* fbx_sampler_state; ID3D11ShaderResourceView* normal_rc_view; ID3D11Buffer* sqVertexBuf; ID3D11Buffer* sqIndexBuf; std::vector<MeshData> meshList; myConsole* con; //Global Declarations - Others// HWND hwnd = NULL; HRESULT hr; int Width = 300; int Height = 300; DirectX::XMMATRIX cube1World; DirectX::XMMATRIX WVP; ///////////////**************new**************//////////////////// DirectX::XMMATRIX mesh_world; ///////////////**************new**************//////////////////// DirectX::XMMATRIX camView; DirectX::XMMATRIX camProjection; DirectX::XMVECTOR camPosition; DirectX::XMVECTOR camTarget; DirectX::XMVECTOR camUp; ///////////////**************new**************//////////////////// DirectX::XMMATRIX Rotation; DirectX::XMMATRIX Scale; DirectX::XMMATRIX Translation; float rot = 0.01f; ///////////////**************new**************//////////////////// //Create effects constant buffer's structure// struct cbPerObject { DirectX::XMMATRIX WVP; }; cbPerObject cbPerObj; struct Vrx { Vrx() {} Vrx(float x, float y, float z, float cr, float cg, float cb, float ca) : pos(x, y, z), color(cr, cg, cb, ca) {} DirectX::XMFLOAT3 pos; DirectX::XMFLOAT4 color; }; D3D11_INPUT_ELEMENT_DESC layout[] = { { "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 }, { "COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0 }, }; UINT numElements = ARRAYSIZE(layout); // Event table for MyFrame wxBEGIN_EVENT_TABLE(MyFrame, wxFrame) EVT_MENU(wxID_EXIT, MyFrame::OnQuit) EVT_CLOSE(MyFrame::OnClose) wxEND_EVENT_TABLE() // Implements MyApp& GetApp() DECLARE_APP(MyApp) // Give wxWidgets the means to create a MyApp object IMPLEMENT_APP(MyApp) bool MyApp::OnInit() { // Create the main application window MyFrame *frame = new MyFrame(wxT("Worgen Engine Version 0")); // Show it frame->Show(true); return true; } void MyFrame::OnQuit(wxCommandEvent& event) { // Destroy the frame Close(); } void MyFrame::OnClose(wxCloseEvent& event) { timer->Stop(); //Release the COM Objects we created SwapChain->Release(); d3d11Device->Release(); d3d11DevCon->Release(); renderTargetView->Release(); event.Skip(); } MyFrame::MyFrame(const wxString& title) : wxFrame(NULL, wxID_ANY, title, wxDefaultPosition) { // Create a menu bar wxMenu *fileMenu = new wxMenu; // The “About” item should be in the help menu wxMenu *helpMenu = new wxMenu; helpMenu->Append(wxID_ABOUT, wxT("&About...\tF1"), wxT("ABout this program.")); fileMenu->Append(wxID_EXIT, wxT("E&xit\tAlt - X"), wxT("Quit this program")); // Now append the freshly created menu to the menu bar... wxMenuBar *menuBar = new wxMenuBar(); menuBar->Append(fileMenu, wxT("&File")); menuBar->Append(helpMenu, wxT("&Help")); // ... and attach this menu bar to the frame SetMenuBar(menuBar); // Create a status bar just for fun CreateStatusBar(2); SetStatusText(wxT("Welcome to Worgen Engine!")); nbHierarchy = new wxNotebook(this, wxID_ANY, wxDefaultPosition, wxSize(200, 300)); nbScene = new wxNotebook(this, wxID_ANY, wxDefaultPosition, wxSize(800, 600)); nbInspector = new wxNotebook(this, wxID_ANY, wxDefaultPosition, wxSize(200, 300)); timer = new RenderTimer(); console = new myConsole(wxSize(800, 300), wxTE_MULTILINE | wxTE_READONLY, this); timer->dxPanel = new MyDxPanel((MyFrame*)nbScene); wxPanel* hierarchyWindow = new wxPanel(nbHierarchy, wxID_ANY); nbHierarchy->AddPage(hierarchyWindow, "Hierarchy", false); nbScene->AddPage(timer->dxPanel, "Game", false); wxPanel* inspectorWindow = new wxPanel(nbInspector, wxID_ANY); nbInspector->AddPage(inspectorWindow, "Inspector", false); wxBoxSizer* sizer = new wxBoxSizer(wxHORIZONTAL); sizer->Add(nbHierarchy, 0, wxEXPAND, 0); sizer->Add(nbScene, 1, wxEXPAND, 0); sizer->Add(nbInspector, 0, wxEXPAND, 0); wxBoxSizer* console_sizer = new wxBoxSizer(wxVERTICAL); console_sizer->Add(sizer, 0, wxEXPAND, 0); console_sizer->Add(console, 0, wxEXPAND, 0); SetSizerAndFit(console_sizer); timer->dxPanel->c = console; timer->dxPanel->aLoader = new LoadMesh("C:\\Models\\wally.fbx", console, meshList); timer->dxPanel->initDx(timer->dxPanel->GetHWND()); timer->dxPanel->initScene(); timer->Start(); } MyFrame::~MyFrame() { delete timer; } wxBEGIN_EVENT_TABLE(MyDxPanel, wxPanel) EVT_PAINT(MyDxPanel::OnPaint) EVT_ERASE_BACKGROUND(MyDxPanel::OnEraseBackground) wxEND_EVENT_TABLE() MyDxPanel::MyDxPanel(MyFrame* parent) : wxPanel(parent) { parentFrame = parent; } MyDxPanel::~MyDxPanel() { } void MyDxPanel::OnEraseBackground(wxEraseEvent &WXUNUSED(event)) { //empty to avoid flashing } void MyDxPanel::updateScene() { //Keep the cubes rotating rot += .05f; if (rot > 6.26f) rot = 0.0f; //Reset cube1World cube1World = DirectX::XMMatrixIdentity(); //Define cube1's world space matrix DirectX::XMVECTOR rotaxis = DirectX::XMVectorSet(0.0f, 1.0f, 0.0f, 0.0f); Rotation = DirectX::XMMatrixRotationAxis(rotaxis, rot); Translation = DirectX::XMMatrixTranslation(0.0f, 0.0f, 4.0f); //Set cube1's world space using the transformations cube1World = Rotation; } void MyDxPanel::render() { //Clear our backbuffer float bgColor[4] = { 0.0f, 0.3f, 0.4f, 1.0f }; d3d11DevCon->ClearRenderTargetView(renderTargetView, bgColor); //Refresh the Depth/Stencil view d3d11DevCon->ClearDepthStencilView(depthStencilView, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0); ///////////////**************new**************//////////////////// //Set the WVP matrix and send it to the constant buffer in effect file WVP = cube1World * camView * camProjection; cbPerObj.WVP = XMMatrixTranspose(WVP); d3d11DevCon->UpdateSubresource(cbPerObjectBuffer, 0, NULL, &cbPerObj, 0, 0); d3d11DevCon->VSSetConstantBuffers(0, 1, &cbPerObjectBuffer); //Draw the first cube d3d11DevCon->DrawIndexed(36, 0, 0); //Present the backbuffer to the screen SwapChain->Present(0, 0); } void MyDxPanel::OnPaint(wxPaintEvent& event) { wxPaintDC dc(this); updateScene(); render(); } void MyDxPanel::initDx(HWND wnd) { //Describe our SwapChain Buffer DXGI_MODE_DESC bufferDesc; ZeroMemory(&bufferDesc, sizeof(DXGI_MODE_DESC)); bufferDesc.Width = Width; bufferDesc.Height = Height; bufferDesc.RefreshRate.Numerator = 60; bufferDesc.RefreshRate.Denominator = 1; bufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; bufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED; bufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED; //Describe our SwapChain DXGI_SWAP_CHAIN_DESC swapChainDesc; ZeroMemory(&swapChainDesc, sizeof(DXGI_SWAP_CHAIN_DESC)); swapChainDesc.BufferDesc = bufferDesc; swapChainDesc.SampleDesc.Count = 1; swapChainDesc.SampleDesc.Quality = 0; swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; swapChainDesc.BufferCount = 1; swapChainDesc.OutputWindow = wnd; swapChainDesc.Windowed = TRUE; swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD; //Create our SwapChain hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, NULL, NULL, NULL, D3D11_SDK_VERSION, &swapChainDesc, &SwapChain, &d3d11Device, NULL, &d3d11DevCon); //Create our BackBuffer ID3D11Texture2D* BackBuffer; hr = SwapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (void**)&BackBuffer); d3d11Device->CreateRenderTargetView(BackBuffer, NULL, &renderTargetView); //Describe our Depth/Stencil Buffer D3D11_TEXTURE2D_DESC depthStencilDesc; depthStencilDesc.Width = Width; depthStencilDesc.Height = Height; depthStencilDesc.MipLevels = 1; depthStencilDesc.ArraySize = 1; depthStencilDesc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT; depthStencilDesc.SampleDesc.Count = 1; depthStencilDesc.SampleDesc.Quality = 0; depthStencilDesc.Usage = D3D11_USAGE_DEFAULT; depthStencilDesc.BindFlags = D3D11_BIND_DEPTH_STENCIL; depthStencilDesc.CPUAccessFlags = 0; depthStencilDesc.MiscFlags = 0; //Create the Depth/Stencil View d3d11Device->CreateTexture2D(&depthStencilDesc, NULL, &depthStencilBuffer); d3d11Device->CreateDepthStencilView(depthStencilBuffer, NULL, &depthStencilView); //Set our Render Target d3d11DevCon->OMSetRenderTargets(1, &renderTargetView, depthStencilView); } void MyDxPanel::initScene() { //Compile Shaders from shader file HR(D3DCompileFromFile(L"Effects.fx", 0, 0, "VS", "vs_5_0", 0, 0, &VS_Blob, 0)); HR(D3DCompileFromFile(L"Effects.fx", 0, 0, "PS", "ps_5_0", 0, 0, &PS_Blob, 0)); //Create the Shader Objects hr = d3d11Device->CreateVertexShader(VS_Blob->GetBufferPointer(), VS_Blob->GetBufferSize(), NULL, &VS); hr = d3d11Device->CreatePixelShader(PS_Blob->GetBufferPointer(), PS_Blob->GetBufferSize(), NULL, &PS); //Set Vertex and Pixel Shaders d3d11DevCon->VSSetShader(VS, 0, 0); d3d11DevCon->PSSetShader(PS, 0, 0); ///////////////**************new**************//////////////////// //Create the vertex buffer Vrx v[] = { Vrx(-1.0f, -1.0f, -1.0f, 1.0f, 0.0f, 0.0f, 1.0f), Vrx(-1.0f, +1.0f, -1.0f, 0.0f, 1.0f, 0.0f, 1.0f), Vrx(+1.0f, +1.0f, -1.0f, 0.0f, 0.0f, 1.0f, 1.0f), Vrx(+1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 0.0f, 1.0f), Vrx(-1.0f, -1.0f, +1.0f, 0.0f, 1.0f, 1.0f, 1.0f), Vrx(-1.0f, +1.0f, +1.0f, 1.0f, 1.0f, 1.0f, 1.0f), Vrx(+1.0f, +1.0f, +1.0f, 1.0f, 0.0f, 1.0f, 1.0f), Vrx(+1.0f, -1.0f, +1.0f, 1.0f, 0.0f, 0.0f, 1.0f), }; DWORD indices[] = { // front face 0, 1, 2, 0, 2, 3, // back face 4, 6, 5, 4, 7, 6, // left face 4, 5, 1, 4, 1, 0, // right face 3, 2, 6, 3, 6, 7, // top face 1, 5, 6, 1, 6, 2, // bottom face 4, 0, 3, 4, 3, 7 }; D3D11_BUFFER_DESC indexBufferDesc; ZeroMemory(&indexBufferDesc, sizeof(indexBufferDesc)); indexBufferDesc.Usage = D3D11_USAGE_DEFAULT; indexBufferDesc.ByteWidth = sizeof(DWORD) * 12 * 3; indexBufferDesc.BindFlags = D3D11_BIND_INDEX_BUFFER; indexBufferDesc.CPUAccessFlags = 0; indexBufferDesc.MiscFlags = 0; D3D11_SUBRESOURCE_DATA iinitData; iinitData.pSysMem = indices; d3d11Device->CreateBuffer(&indexBufferDesc, &iinitData, &sqIndexBuf); d3d11DevCon->IASetIndexBuffer(sqIndexBuf, DXGI_FORMAT_R32_UINT, 0); D3D11_BUFFER_DESC vertexBufferDesc; ZeroMemory(&vertexBufferDesc, sizeof(vertexBufferDesc)); vertexBufferDesc.Usage = D3D11_USAGE_DEFAULT; vertexBufferDesc.ByteWidth = sizeof(Vertex) * 8; vertexBufferDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER; vertexBufferDesc.CPUAccessFlags = 0; vertexBufferDesc.MiscFlags = 0; ///////////////**************new**************//////////////////// D3D11_SUBRESOURCE_DATA vertexBufferData; ZeroMemory(&vertexBufferData, sizeof(vertexBufferData)); vertexBufferData.pSysMem = v; hr = d3d11Device->CreateBuffer(&vertexBufferDesc, &vertexBufferData, &sqVertexBuf); //Set the vertex buffer UINT stride = sizeof(Vertex); UINT offset = 0; d3d11DevCon->IASetVertexBuffers(0, 1, &sqVertexBuf, &stride, &offset); //Create the Input Layout hr = d3d11Device->CreateInputLayout(layout, numElements, VS_Blob->GetBufferPointer(), VS_Blob->GetBufferSize(), &vertLayout); //Set the Input Layout d3d11DevCon->IASetInputLayout(vertLayout); //Set Primitive Topology d3d11DevCon->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); //Create the Viewport D3D11_VIEWPORT viewport; ZeroMemory(&viewport, sizeof(D3D11_VIEWPORT)); viewport.TopLeftX = 0; viewport.TopLeftY = 0; viewport.Width = Width; viewport.Height = Height; viewport.MinDepth = 0.0f; viewport.MaxDepth = 1.0f; //Set the Viewport d3d11DevCon->RSSetViewports(1, &viewport); //Create the buffer to send to the cbuffer in effect file D3D11_BUFFER_DESC cbbd; ZeroMemory(&cbbd, sizeof(D3D11_BUFFER_DESC)); cbbd.Usage = D3D11_USAGE_DEFAULT; cbbd.ByteWidth = sizeof(cbPerObject); cbbd.BindFlags = D3D11_BIND_CONSTANT_BUFFER; cbbd.CPUAccessFlags = 0; cbbd.MiscFlags = 0; hr = d3d11Device->CreateBuffer(&cbbd, NULL, &cbPerObjectBuffer); //Camera information ///////////////**************new**************//////////////////// camPosition = DirectX::XMVectorSet(0.0f, 3.0f, -8.0f, 0.0f); ///////////////**************new**************//////////////////// camTarget = DirectX::XMVectorSet(0.0f, 0.0f, 0.0f, 0.0f); camUp = DirectX::XMVectorSet(0.0f, 1.0f, 0.0f, 0.0f); //Set the View matrix camView = DirectX::XMMatrixLookAtLH(camPosition, camTarget, camUp); //Set the Projection matrix camProjection = DirectX::XMMatrixPerspectiveFovLH(0.4f*3.14f, (float)Width / Height, 1.0f, 1000.0f); } RenderTimer::RenderTimer() : wxTimer() { } void RenderTimer::Notify() { dxPanel->Refresh(); } void RenderTimer::start() { wxTimer::Start(10); } cbuffer cbPerObject { float4x4 WVP; }; struct VS_OUTPUT { float4 Pos : SV_POSITION; float4 Color : COLOR; }; VS_OUTPUT VS(float4 inPos : POSITION, float4 inColor : COLOR) { VS_OUTPUT output; output.Pos = mul(inPos, WVP); output.Color = inColor; return output; } float4 PS(VS_OUTPUT input) : SV_TARGET { return input.Color; }
  12. Ok so I had some code using the old DXSDK. I went to windows 10 and updated my code. I also made some changes to where i stored the vector that holds the vertex positions but thats pretty much it. Now my model is not showing up. So I ran renderdoc. Now renderdoc can see my vertices and indices and the finished mesh when I click the draw call...see the attached image. When I run from vs2017 i cant see anything except the background color. I thought it was because of where my camera was positioned so I changed that and I still can't see anything. The camera is sitting slightly back from the origin....shouldn't the model be there? That's where it was before I made the changes to the source to update it for windows 10. I made the model file and made no changes to it ever since it worked before. Here is the source code and shader: #include "Source.h" #include "DDSTextureLoader.h" //Global Declarations - Interfaces// IDXGISwapChain* SwapChain; ID3D11Device* d3d11Device; ID3D11DeviceContext* d3d11DevCon; ID3D11RenderTargetView* renderTargetView; ID3D11DepthStencilView* depthStencilView; ID3D11Texture2D* depthStencilBuffer; ID3D11Resource* tex; ID3D11RasterizerState * rasterState; ID3D11VertexShader* VS; ID3D11PixelShader* PS; ID3DBlob* VS_Blob; ID3DBlob* PS_Blob; ID3D11InputLayout* vertLayout; ID3D11Buffer* fbx_vertex_buf; ID3D11Buffer* fbx_index_buf; ID3D11Buffer* cbPerObjectBuffer; ID3D11ShaderResourceView* fbx_rc_view; ID3D11SamplerState* fbx_sampler_state; ID3D11ShaderResourceView* normal_rc_view; std::vector<MeshData> meshList; myConsole* con; //Global Declarations - Others// HWND hwnd = NULL; HRESULT hr; int Width = 300; int Height = 300; DirectX::XMMATRIX WVP; ///////////////**************new**************//////////////////// DirectX::XMMATRIX mesh_world; ///////////////**************new**************//////////////////// DirectX::XMMATRIX camView; DirectX::XMMATRIX camProjection; DirectX::XMVECTOR camPosition; DirectX::XMVECTOR camTarget; DirectX::XMVECTOR camUp; ///////////////**************new**************//////////////////// DirectX::XMMATRIX Rotation; DirectX::XMMATRIX Scale; DirectX::XMMATRIX Translation; float rot = 0.01f; ///////////////**************new**************//////////////////// //Create effects constant buffer's structure// struct cbPerObject { DirectX::XMMATRIX WVP; }; cbPerObject cbPerObj; D3D11_INPUT_ELEMENT_DESC layout[] = { { "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 }, { "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 }, { "NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 }, { "TANGENT", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 }, { "BITANGENT", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 } }; UINT numElements = ARRAYSIZE(layout); // Event table for MyFrame wxBEGIN_EVENT_TABLE(MyFrame, wxFrame) EVT_MENU(wxID_EXIT, MyFrame::OnQuit) EVT_CLOSE(MyFrame::OnClose) wxEND_EVENT_TABLE() // Implements MyApp& GetApp() DECLARE_APP(MyApp) // Give wxWidgets the means to create a MyApp object IMPLEMENT_APP(MyApp) bool MyApp::OnInit() { // Create the main application window MyFrame *frame = new MyFrame(wxT("Worgen Engine Version 0")); // Show it frame->Show(true); return true; } void MyFrame::OnQuit(wxCommandEvent& event) { // Destroy the frame Close(); } void MyFrame::OnClose(wxCloseEvent& event) { timer->Stop(); //Release the COM Objects we created SwapChain->Release(); d3d11Device->Release(); d3d11DevCon->Release(); renderTargetView->Release(); event.Skip(); } MyFrame::MyFrame(const wxString& title) : wxFrame(NULL, wxID_ANY, title, wxDefaultPosition) { // Create a menu bar wxMenu *fileMenu = new wxMenu; // The “About” item should be in the help menu wxMenu *helpMenu = new wxMenu; helpMenu->Append(wxID_ABOUT, wxT("&About...\tF1"), wxT("ABout this program.")); fileMenu->Append(wxID_EXIT, wxT("E&xit\tAlt - X"), wxT("Quit this program")); // Now append the freshly created menu to the menu bar... wxMenuBar *menuBar = new wxMenuBar(); menuBar->Append(fileMenu, wxT("&File")); menuBar->Append(helpMenu, wxT("&Help")); // ... and attach this menu bar to the frame SetMenuBar(menuBar); // Create a status bar just for fun CreateStatusBar(2); SetStatusText(wxT("Welcome to Worgen Engine!")); nbHierarchy = new wxNotebook(this, wxID_ANY, wxDefaultPosition, wxSize(200, 300)); nbScene = new wxNotebook(this, wxID_ANY, wxDefaultPosition, wxSize(800, 600)); nbInspector = new wxNotebook(this, wxID_ANY, wxDefaultPosition, wxSize(200, 300)); timer = new RenderTimer(); console = new myConsole(wxSize(800, 300), wxTE_MULTILINE | wxTE_READONLY, this); timer->dxPanel = new MyDxPanel((MyFrame*)nbScene); wxPanel* hierarchyWindow = new wxPanel(nbHierarchy, wxID_ANY); nbHierarchy->AddPage(hierarchyWindow, "Hierarchy", false); nbScene->AddPage(timer->dxPanel, "Game", false); wxPanel* inspectorWindow = new wxPanel(nbInspector, wxID_ANY); nbInspector->AddPage(inspectorWindow, "Inspector", false); wxBoxSizer* sizer = new wxBoxSizer(wxHORIZONTAL); sizer->Add(nbHierarchy, 0, wxEXPAND, 0); sizer->Add(nbScene, 1, wxEXPAND, 0); sizer->Add(nbInspector, 0, wxEXPAND, 0); wxBoxSizer* console_sizer = new wxBoxSizer(wxVERTICAL); console_sizer->Add(sizer, 0, wxEXPAND, 0); console_sizer->Add(console, 0, wxEXPAND, 0); SetSizerAndFit(console_sizer); timer->dxPanel->c = console; timer->dxPanel->aLoader = new LoadMesh("C:\\Models\\wally.fbx", console, meshList); timer->dxPanel->initDx(timer->dxPanel->GetHWND()); timer->dxPanel->initScene(); timer->Start(); } MyFrame::~MyFrame() { delete timer; } wxBEGIN_EVENT_TABLE(MyDxPanel, wxPanel) EVT_PAINT(MyDxPanel::OnPaint) EVT_ERASE_BACKGROUND(MyDxPanel::OnEraseBackground) wxEND_EVENT_TABLE() MyDxPanel::MyDxPanel(MyFrame* parent) : wxPanel(parent) { parentFrame = parent; } MyDxPanel::~MyDxPanel() { } void MyDxPanel::OnEraseBackground(wxEraseEvent &WXUNUSED(event)) { //empty to avoid flashing } void MyDxPanel::updateScene() { rot += .05f; if (rot > 6.26f) rot = 0.0f; DirectX::XMVECTOR rotaxis = DirectX::XMVectorSet(0.0f, 1.0f, 0.0f, 0.0f); Rotation = DirectX::XMMatrixRotationAxis(rotaxis, -rot); mesh_world = DirectX::XMMatrixIdentity(); } void MyDxPanel::render() { //Clear our backbuffer float bgColor[4] = {0.0f, 0.6f, 0.4f, 1.0f }; d3d11DevCon->ClearRenderTargetView(renderTargetView, bgColor); //Refresh the Depth/Stencil view d3d11DevCon->ClearDepthStencilView(depthStencilView, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0); WVP = mesh_world * camView * camProjection; cbPerObj.WVP = DirectX::XMMatrixTranspose(WVP); d3d11DevCon->UpdateSubresource(cbPerObjectBuffer, 0, NULL, &cbPerObj, 0, 0); d3d11DevCon->VSSetConstantBuffers(0, 1, &cbPerObjectBuffer); d3d11DevCon->PSSetShaderResources(0, 1, &fbx_rc_view); d3d11DevCon->PSSetSamplers(0, 1, &fbx_sampler_state); d3d11DevCon->DrawIndexed(meshList[0].indices.size(), 0, 0); //Present the backbuffer to the screen SwapChain->Present(0, 0); } void MyDxPanel::OnPaint(wxPaintEvent& event) { wxPaintDC dc(this); updateScene(); render(); } void MyDxPanel::initDx(HWND wnd) { //Describe our SwapChain Buffer DXGI_MODE_DESC bufferDesc; ZeroMemory(&bufferDesc, sizeof(DXGI_MODE_DESC)); bufferDesc.Width = Width; bufferDesc.Height = Height; bufferDesc.RefreshRate.Numerator = 60; bufferDesc.RefreshRate.Denominator = 1; bufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; bufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED; bufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED; //Describe our SwapChain DXGI_SWAP_CHAIN_DESC swapChainDesc; ZeroMemory(&swapChainDesc, sizeof(DXGI_SWAP_CHAIN_DESC)); swapChainDesc.BufferDesc = bufferDesc; swapChainDesc.SampleDesc.Count = 1; swapChainDesc.SampleDesc.Quality = 0; swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; swapChainDesc.BufferCount = 1; swapChainDesc.OutputWindow = wnd; swapChainDesc.Windowed = TRUE; swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD; //Create our SwapChain hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, NULL, NULL, NULL, D3D11_SDK_VERSION, &swapChainDesc, &SwapChain, &d3d11Device, NULL, &d3d11DevCon); //Create our BackBuffer ID3D11Texture2D* BackBuffer; hr = SwapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (void**)&BackBuffer); d3d11Device->CreateRenderTargetView(BackBuffer, NULL, &renderTargetView); //Describe our Depth/Stencil Buffer D3D11_TEXTURE2D_DESC depthStencilDesc; depthStencilDesc.Width = Width; depthStencilDesc.Height = Height; depthStencilDesc.MipLevels = 1; depthStencilDesc.ArraySize = 1; depthStencilDesc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT; depthStencilDesc.SampleDesc.Count = 1; depthStencilDesc.SampleDesc.Quality = 0; depthStencilDesc.Usage = D3D11_USAGE_DEFAULT; depthStencilDesc.BindFlags = D3D11_BIND_DEPTH_STENCIL; depthStencilDesc.CPUAccessFlags = 0; depthStencilDesc.MiscFlags = 0; //Create the Depth/Stencil View d3d11Device->CreateTexture2D(&depthStencilDesc, NULL, &depthStencilBuffer); d3d11Device->CreateDepthStencilView(depthStencilBuffer, NULL, &depthStencilView); //Set our Render Target d3d11DevCon->OMSetRenderTargets(1, &renderTargetView, depthStencilView); } void MyDxPanel::initScene() { shaders(); generateBuffers(); setBuffers(0); setInputLayoutAndTopology(); setViewport(); setCameraInfo(); createConstantBuffer(); loadModelTexture("C:\\Models\\tex.DDS"); createSamplerState(); setRSState(); } void MyDxPanel::shaders() { //Compile Shaders from shader file HR(D3DCompileFromFile(L"Effects.fx", 0, 0, "VS", "vs_5_0", 0, 0, &VS_Blob, 0)); HR(D3DCompileFromFile(L"Effects.fx", 0, 0, "PS", "ps_5_0", 0, 0, &PS_Blob, 0)); //Create the Shader Objects HR(d3d11Device->CreateVertexShader(VS_Blob->GetBufferPointer(), VS_Blob->GetBufferSize(), NULL, &VS)); HR(d3d11Device->CreatePixelShader(PS_Blob->GetBufferPointer(), PS_Blob->GetBufferSize(), NULL, &PS)); //Set Vertex and Pixel Shaders d3d11DevCon->VSSetShader(VS, 0, 0); d3d11DevCon->PSSetShader(PS, 0, 0); } void MyDxPanel::generateBuffers() { D3D11_BUFFER_DESC indexBufferDesc; ZeroMemory(&indexBufferDesc, sizeof(indexBufferDesc)); indexBufferDesc.Usage = D3D11_USAGE_DEFAULT; indexBufferDesc.ByteWidth = meshList[0].indices.size() * sizeof(DWORD); indexBufferDesc.BindFlags = D3D11_BIND_INDEX_BUFFER; indexBufferDesc.CPUAccessFlags = 0; indexBufferDesc.MiscFlags = 0; D3D11_SUBRESOURCE_DATA iinitData; iinitData.pSysMem = &meshList[0].indices[0]; HR(d3d11Device->CreateBuffer(&indexBufferDesc, &iinitData, &meshList[0].indexBuffer)); D3D11_BUFFER_DESC vertexBufferDesc; ZeroMemory(&vertexBufferDesc, sizeof(vertexBufferDesc)); vertexBufferDesc.Usage = D3D11_USAGE_DEFAULT; vertexBufferDesc.ByteWidth = meshList[0].vertices.size() * sizeof(Vertex); vertexBufferDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER; vertexBufferDesc.CPUAccessFlags = 0; vertexBufferDesc.MiscFlags = 0; D3D11_SUBRESOURCE_DATA vertexBufferData; ZeroMemory(&vertexBufferData, sizeof(vertexBufferData)); vertexBufferData.pSysMem = &meshList[0].vertices[0]; HR(d3d11Device->CreateBuffer(&vertexBufferDesc, &vertexBufferData, &meshList[0].vertexBuffer)); } void MyDxPanel::setBuffers(int i) { d3d11DevCon->IASetIndexBuffer(meshList[i].indexBuffer, DXGI_FORMAT_R32_UINT, 0); UINT stride = sizeof(Vertex); UINT offset = 0; d3d11DevCon->IASetVertexBuffers(0, 1, &meshList[i].vertexBuffer, &stride, &offset); } void MyDxPanel::setInputLayoutAndTopology() { HR(d3d11Device->CreateInputLayout(layout, numElements, VS_Blob->GetBufferPointer(), VS_Blob->GetBufferSize(), &vertLayout)); d3d11DevCon->IASetInputLayout(vertLayout); d3d11DevCon->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); } void MyDxPanel::setViewport() { //Create the Viewport D3D11_VIEWPORT viewport; ZeroMemory(&viewport, sizeof(D3D11_VIEWPORT)); viewport.TopLeftX = 0; viewport.TopLeftY = 0; viewport.Width = Width; viewport.Height = Height; viewport.MinDepth = 0.0f; viewport.MaxDepth = 1.0f; //Set the Viewport d3d11DevCon->RSSetViewports(1, &viewport); } void MyDxPanel::createConstantBuffer() { //Create the buffer to send to the cbuffer in effect file D3D11_BUFFER_DESC cbbd; ZeroMemory(&cbbd, sizeof(D3D11_BUFFER_DESC)); cbbd.Usage = D3D11_USAGE_DEFAULT; cbbd.ByteWidth = sizeof(cbPerObject); cbbd.BindFlags = D3D11_BIND_CONSTANT_BUFFER; cbbd.CPUAccessFlags = 0; cbbd.MiscFlags = 0; cbPerObj.WVP = DirectX::XMMatrixTranspose(mesh_world * camView * camProjection); D3D11_SUBRESOURCE_DATA initData; initData.pSysMem = &cbPerObj; HR(d3d11Device->CreateBuffer(&cbbd, &initData , &cbPerObjectBuffer)); } void MyDxPanel::setCameraInfo() { camPosition = DirectX::XMVectorSet(-0.5f, -0.5f, 4.0f, 0.0f); camTarget = DirectX::XMVectorSet(0.0f, 0.0f, 0.0f, 0.0f); camUp = DirectX::XMVectorSet(0.0f, 1.0f, 0.0f, 0.0f); //Set the View matrix camView = DirectX::XMMatrixLookAtLH(camPosition, camTarget, camUp); //Set the Projection matrix camProjection = DirectX::XMMatrixPerspectiveFovLH(0.4f*3.14f, (float)Width / Height, 1.0f, 1000.0f); } void MyDxPanel::loadModelTexture(std::string path) { HR(DirectX::CreateDDSTextureFromFile(d3d11Device, L"C:\\Models\\tex.DDS", &tex, &fbx_rc_view)); } void MyDxPanel::createSamplerState() { D3D11_SAMPLER_DESC sampDesc; ZeroMemory(&sampDesc, sizeof(sampDesc)); sampDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR; sampDesc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP; sampDesc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP; sampDesc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP; sampDesc.ComparisonFunc = D3D11_COMPARISON_NEVER; sampDesc.MinLOD = 0; sampDesc.MaxLOD = D3D11_FLOAT32_MAX; //Create the Sample State HR(d3d11Device->CreateSamplerState(&sampDesc, &fbx_sampler_state)); } void MyDxPanel::setRSState() { D3D11_RASTERIZER_DESC rasterizerState; rasterizerState.FillMode = D3D11_FILL_SOLID; rasterizerState.CullMode = D3D11_CULL_NONE; rasterizerState.FrontCounterClockwise = true; rasterizerState.DepthBias = false; rasterizerState.DepthBiasClamp = 0; rasterizerState.SlopeScaledDepthBias = 0; rasterizerState.DepthClipEnable = true; rasterizerState.ScissorEnable = true; rasterizerState.MultisampleEnable = false; rasterizerState.AntialiasedLineEnable = false; d3d11Device->CreateRasterizerState(&rasterizerState, &rasterState); d3d11DevCon->RSSetState(rasterState); } RenderTimer::RenderTimer() : wxTimer() { } void RenderTimer::Notify() { dxPanel->Refresh(); } void RenderTimer::start() { wxTimer::Start(10); } cbuffer cbPerObject { float4x4 WVP; }; Texture2D ObjTexture; SamplerState ObjSamplerState; struct VS_OUTPUT { float4 Pos : SV_POSITION; float2 TexCoord : TEXCOORD; }; VS_OUTPUT VS(float4 inPos : POSITION, float2 inTexCoord : TEXCOORD) { VS_OUTPUT output; output.Pos = mul(inPos, WVP); output.TexCoord = inTexCoord; return output; } float4 PS(VS_OUTPUT input) : SV_TARGET { return ObjTexture.Sample(ObjSamplerState, input.TexCoord); }
  13. TommyThree

    Help with FBXSDK

    I got models loading by just doing a Draw instead of a DrawIndexed. But how do u load uvs? I loaded the UVSetName looking at your code. But I don't even see in the docs where it explains uv maps and stuff. Am I missing something? O_o Also, lets say I get the uv map into the program. I have the uv map painted with substance painter and its a separate file. In unity I import the model, import the painted uv texture, make material, add painted uv texture, and apply it to the model. How do I load this painted uv into my program? O_O Or whats the workflow I should use as an artist to get the painted uv correctly on my model?
  14. Anyone used the fbxsdk? I want to load models into my engine but when I load them, something is wrong. I load a sphere made and triangulated with maya and it looks like only the bottom of the sphere gets into the program. I did a cube too and it looks like just one side gets in. What is going on in FBXImport and the dx11 related functions in source.cpp? IT looks ok to me. :( Here is some code: FBXImport.h #pragma once #include <fbxsdk.h> #include <winerror.h> #include <vector> #include <d3d11.h> #include <d3dx11.h> #include <d3dx10.h> #include <xnamath.h> #include "wx/wx.h" #include "wx/notebook.h" #include <wx/timer.h> #include <wx/time.h> using namespace std; struct Vertex { Vertex() {} Vertex(float x, float y, float z, float cr, float cg, float cb, float ca) : pos(x, y, z), color(cr, cg, cb, ca) {} XMFLOAT3 pos; XMFLOAT4 color; }; void InitFBX(); void DestroyManager(); HRESULT ImportFile(vector<Vertex>* pos, vector<DWORD>* indices, wxTextCtrl* ctrl); FbxImport.cpp #include "FBXImport.h" #include <assert.h> #include <xnamath.h> FbxManager* fbxMgr = nullptr; vector<Vertex> vrx_positions; void InitFBX() { fbxMgr = FbxManager::Create(); } void DestroyManager() { fbxMgr->Destroy(); } HRESULT ImportFile(vector<Vertex>* pos, vector<DWORD>* indices, wxTextCtrl* console) { if(fbxMgr == nullptr) InitFBX(); FbxIOSettings* ios = FbxIOSettings::Create(fbxMgr, IOSROOT); fbxMgr->SetIOSettings(ios); FbxImporter* importer = FbxImporter::Create(fbxMgr, ""); FbxScene* scene = FbxScene::Create(fbxMgr, "myScene"); bool success = importer->Initialize("C:\\Models\\sphere.fbx", -1, fbxMgr->GetIOSettings()); if (!success) return E_FAIL; success = importer->Import(scene); if (!success) return E_FAIL; importer->Destroy(); FbxNode* root_node = scene->GetRootNode(); if (root_node) { for (int i = 0; i < root_node->GetChildCount(); i++) { FbxNode* child_node = root_node->GetChild(i); if (child_node->GetNodeAttribute() == NULL) continue; FbxNodeAttribute::EType attribute_type = child_node->GetNodeAttribute()->GetAttributeType(); if (attribute_type != FbxNodeAttribute::eMesh) continue; FbxMesh* mesh = (FbxMesh*)child_node->GetNodeAttribute(); FbxVector4* verts = mesh->GetControlPoints(); for (int j = 0; j < mesh->GetPolygonCount(); j++) { int numVerts = mesh->GetPolygonSize(j); assert(numVerts == 3); for (int k = 0; k < numVerts; k++) { DWORD control_pt_index = mesh->GetPolygonVertex(j, k); Vertex vrx((float)verts[control_pt_index].mData[0], (float)verts[control_pt_index].mData[1], (float)verts[control_pt_index].mData[2], 0.6f, 0.8f, 0.6f, 1.0f); pos->push_back(vrx); indices->push_back(control_pt_index); } } } } } Source.cpp #include <windows.h> #include <d3d11.h> #include <d3dx11.h> #include <d3dx10.h> #include <xnamath.h> #include "Source.h" #include "FBXImport.h" //Global Declarations - Interfaces// IDXGISwapChain* SwapChain; ID3D11Device* d3d11Device; ID3D11DeviceContext* d3d11DevCon; ID3D11RenderTargetView* renderTargetView; ID3D11Buffer* squareIndexBuffer; ID3D11DepthStencilView* depthStencilView; ID3D11Texture2D* depthStencilBuffer; ID3D11Buffer* squareVertBuffer; ID3D11VertexShader* VS; ID3D11PixelShader* PS; ID3D10Blob* VS_Buffer; ID3D10Blob* PS_Buffer; ID3D11InputLayout* vertLayout; ID3D11Buffer* cbPerObjectBuffer; ID3D11Buffer* fbx_index_buf; ID3D11Buffer* fbx_vert_buf; //Global Declarations - Others// LPCTSTR WndClassName = L"firstwindow"; HWND hwnd = NULL; HRESULT hr; int Width = 300; int Height = 300; vector<Vertex> verts; vector<DWORD> indices; Vertex* positions; DWORD* index; XMMATRIX WVP; ///////////////**************new**************//////////////////// XMMATRIX cube1World; XMMATRIX cube2World; XMMATRIX cube_fbx; ///////////////**************new**************//////////////////// XMMATRIX camView; XMMATRIX camProjection; XMVECTOR camPosition; XMVECTOR camTarget; XMVECTOR camUp; ///////////////**************new**************//////////////////// XMMATRIX Rotation; XMMATRIX Scale; XMMATRIX Translation; float rot = 0.01f; ///////////////**************new**************//////////////////// //Create effects constant buffer's structure// struct cbPerObject { XMMATRIX WVP; }; cbPerObject cbPerObj; D3D11_INPUT_ELEMENT_DESC layout[] = { { "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 }, { "COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0 }, }; UINT numElements = ARRAYSIZE(layout); // Event table for MyFrame wxBEGIN_EVENT_TABLE(MyFrame, wxFrame) EVT_MENU(wxID_EXIT, MyFrame::OnQuit) EVT_CLOSE(MyFrame::OnClose) wxEND_EVENT_TABLE() // Implements MyApp& GetApp() DECLARE_APP(MyApp) // Give wxWidgets the means to create a MyApp object IMPLEMENT_APP(MyApp) bool MyApp::OnInit() { // Create the main application window MyFrame *frame = new MyFrame(wxT("Worgen Engine Version 0")); // Show it frame->Show(true); return true; } void MyFrame::OnQuit(wxCommandEvent& event) { // Destroy the frame Close(); } void MyFrame::OnClose(wxCloseEvent& event) { timer->Stop(); //Release the COM Objects we created SwapChain->Release(); d3d11Device->Release(); d3d11DevCon->Release(); renderTargetView->Release(); VS->Release(); PS->Release(); VS_Buffer->Release(); PS_Buffer->Release(); vertLayout->Release(); depthStencilView->Release(); depthStencilBuffer->Release(); cbPerObjectBuffer->Release(); event.Skip(); } MyFrame::MyFrame(const wxString& title) : wxFrame(NULL, wxID_ANY, title, wxDefaultPosition) { // Create a menu bar wxMenu *fileMenu = new wxMenu; // The “About” item should be in the help menu wxMenu *helpMenu = new wxMenu; helpMenu->Append(wxID_ABOUT, wxT("&About...\tF1"), wxT("ABout this program.")); fileMenu->Append(wxID_EXIT, wxT("E&xit\tAlt - X"), wxT("Quit this program")); // Now append the freshly created menu to the menu bar... wxMenuBar *menuBar = new wxMenuBar(); menuBar->Append(fileMenu, wxT("&File")); menuBar->Append(helpMenu, wxT("&Help")); // ... and attach this menu bar to the frame SetMenuBar(menuBar); // Create a status bar just for fun CreateStatusBar(2); SetStatusText(wxT("Welcome to Worgen Engine!")); nbHierarchy = new wxNotebook(this, wxID_ANY, wxDefaultPosition, wxSize(200, 300)); nbScene = new wxNotebook(this, wxID_ANY, wxDefaultPosition, wxSize(800, 600)); nbInspector = new wxNotebook(this, wxID_ANY, wxDefaultPosition, wxSize(200, 300)); console = new wxTextCtrl(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(800, 300), wxTE_MULTILINE | wxTE_READONLY); timer = new RenderTimer(); timer->dxPanel = new MyDxPanel((MyFrame*)nbScene); wxPanel* hierarchyWindow = new wxPanel(nbHierarchy, wxID_ANY); nbHierarchy->AddPage(hierarchyWindow, "Hierarchy", false); nbScene->AddPage(timer->dxPanel, "Game", false); wxPanel* inspectorWindow = new wxPanel(nbInspector, wxID_ANY); nbInspector->AddPage(inspectorWindow, "Inspector", false); wxBoxSizer* sizer = new wxBoxSizer(wxHORIZONTAL); sizer->Add(nbHierarchy, 0, wxEXPAND, 0); sizer->Add(nbScene, 1, wxEXPAND, 0); sizer->Add(nbInspector, 0, wxEXPAND, 0); wxBoxSizer* console_sizer = new wxBoxSizer(wxVERTICAL); console_sizer->Add(sizer, 0, wxEXPAND, 0); console_sizer->Add(console, 0, wxEXPAND, 0); SetSizerAndFit(console_sizer); HRESULT hr = ImportFile(&verts, &indices, console); if (hr == E_FAIL) { wxMessageBox("Error importing fbx"); } positions = &verts[0]; index = &indices[0]; timer->dxPanel->initDx(timer->dxPanel->GetHWND()); timer->dxPanel->initScene(); timer->Start(); } MyFrame::~MyFrame() { delete timer; } wxBEGIN_EVENT_TABLE(MyDxPanel, wxPanel) EVT_PAINT(MyDxPanel::OnPaint) EVT_ERASE_BACKGROUND(MyDxPanel::OnEraseBackground) wxEND_EVENT_TABLE() MyDxPanel::MyDxPanel(MyFrame* parent) : wxPanel(parent) { parentFrame = parent; } MyDxPanel::~MyDxPanel() { } void MyDxPanel::OnEraseBackground(wxEraseEvent &WXUNUSED(event)) { //empty to avoid flashing } void MyDxPanel::updateScene() { rot += .05f; if (rot > 6.26f) rot = 0.0f; XMVECTOR rotaxis = XMVectorSet(0.0f, 1.0f, 0.0f, 0.0f); Rotation = XMMatrixRotationAxis(rotaxis, -rot); cube_fbx = Rotation; } void MyDxPanel::render() { //Clear our backbuffer float bgColor[4] = { (0.0f, 0.0f, 0.0f, 0.0f) }; d3d11DevCon->ClearRenderTargetView(renderTargetView, bgColor); //Refresh the Depth/Stencil view d3d11DevCon->ClearDepthStencilView(depthStencilView, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0); WVP = cube_fbx * camView * camProjection; cbPerObj.WVP = XMMatrixTranspose(WVP); d3d11DevCon->UpdateSubresource(cbPerObjectBuffer, 0, NULL, &cbPerObj, 0, 0); d3d11DevCon->VSSetConstantBuffers(0, 1, &cbPerObjectBuffer); d3d11DevCon->DrawIndexed(indices.size(), 0, 0); //Present the backbuffer to the screen SwapChain->Present(0, 0); } void MyDxPanel::OnPaint(wxPaintEvent& event) { wxPaintDC dc(this); updateScene(); render(); } void MyDxPanel::initDx(HWND wnd) { //Describe our SwapChain Buffer DXGI_MODE_DESC bufferDesc; ZeroMemory(&bufferDesc, sizeof(DXGI_MODE_DESC)); bufferDesc.Width = Width; bufferDesc.Height = Height; bufferDesc.RefreshRate.Numerator = 60; bufferDesc.RefreshRate.Denominator = 1; bufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; bufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED; bufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED; //Describe our SwapChain DXGI_SWAP_CHAIN_DESC swapChainDesc; ZeroMemory(&swapChainDesc, sizeof(DXGI_SWAP_CHAIN_DESC)); swapChainDesc.BufferDesc = bufferDesc; swapChainDesc.SampleDesc.Count = 1; swapChainDesc.SampleDesc.Quality = 0; swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; swapChainDesc.BufferCount = 1; swapChainDesc.OutputWindow = wnd; swapChainDesc.Windowed = TRUE; swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD; //Create our SwapChain hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, NULL, NULL, NULL, D3D11_SDK_VERSION, &swapChainDesc, &SwapChain, &d3d11Device, NULL, &d3d11DevCon); //Create our BackBuffer ID3D11Texture2D* BackBuffer; hr = SwapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (void**)&BackBuffer); //Create our Render Target hr = d3d11Device->CreateRenderTargetView(BackBuffer, NULL, &renderTargetView); BackBuffer->Release(); //Describe our Depth/Stencil Buffer D3D11_TEXTURE2D_DESC depthStencilDesc; depthStencilDesc.Width = Width; depthStencilDesc.Height = Height; depthStencilDesc.MipLevels = 1; depthStencilDesc.ArraySize = 1; depthStencilDesc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT; depthStencilDesc.SampleDesc.Count = 1; depthStencilDesc.SampleDesc.Quality = 0; depthStencilDesc.Usage = D3D11_USAGE_DEFAULT; depthStencilDesc.BindFlags = D3D11_BIND_DEPTH_STENCIL; depthStencilDesc.CPUAccessFlags = 0; depthStencilDesc.MiscFlags = 0; //Create the Depth/Stencil View d3d11Device->CreateTexture2D(&depthStencilDesc, NULL, &depthStencilBuffer); d3d11Device->CreateDepthStencilView(depthStencilBuffer, NULL, &depthStencilView); //Set our Render Target d3d11DevCon->OMSetRenderTargets(1, &renderTargetView, depthStencilView); } void MyDxPanel::initScene() { //Compile Shaders from shader file hr = D3DX11CompileFromFile(L"Effects.fx", 0, 0, "VS", "vs_4_0", 0, 0, 0, &VS_Buffer, 0, 0); hr = D3DX11CompileFromFile(L"Effects.fx", 0, 0, "PS", "ps_4_0", 0, 0, 0, &PS_Buffer, 0, 0); //Create the Shader Objects hr = d3d11Device->CreateVertexShader(VS_Buffer->GetBufferPointer(), VS_Buffer->GetBufferSize(), NULL, &VS); hr = d3d11Device->CreatePixelShader(PS_Buffer->GetBufferPointer(), PS_Buffer->GetBufferSize(), NULL, &PS); //Set Vertex and Pixel Shaders d3d11DevCon->VSSetShader(VS, 0, 0); d3d11DevCon->PSSetShader(PS, 0, 0); D3D11_BUFFER_DESC indexBufferDesc; ZeroMemory(&indexBufferDesc, sizeof(indexBufferDesc)); indexBufferDesc.Usage = D3D11_USAGE_DEFAULT; indexBufferDesc.ByteWidth = sizeof(DWORD) * indices.size(); indexBufferDesc.BindFlags = D3D11_BIND_INDEX_BUFFER; indexBufferDesc.CPUAccessFlags = 0; indexBufferDesc.MiscFlags = 0; D3D11_SUBRESOURCE_DATA iinitData; iinitData.pSysMem = index; d3d11Device->CreateBuffer(&indexBufferDesc, &iinitData, &fbx_index_buf); d3d11DevCon->IASetIndexBuffer(fbx_index_buf, DXGI_FORMAT_R32_UINT, 0); D3D11_BUFFER_DESC vertexBufferDesc; ZeroMemory(&vertexBufferDesc, sizeof(vertexBufferDesc)); vertexBufferDesc.Usage = D3D11_USAGE_DEFAULT; vertexBufferDesc.ByteWidth = sizeof(Vertex) * verts.size(); vertexBufferDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER; vertexBufferDesc.CPUAccessFlags = 0; vertexBufferDesc.MiscFlags = 0; ///////////////**************new**************//////////////////// D3D11_SUBRESOURCE_DATA vertexBufferData; ZeroMemory(&vertexBufferData, sizeof(vertexBufferData)); vertexBufferData.pSysMem = positions; hr = d3d11Device->CreateBuffer(&vertexBufferDesc, &vertexBufferData, &fbx_vert_buf); //Set the vertex buffer UINT stride = sizeof(Vertex); UINT offset = 0; d3d11DevCon->IASetVertexBuffers(0, 1, &fbx_vert_buf, &stride, &offset); //Create the Input Layout hr = d3d11Device->CreateInputLayout(layout, numElements, VS_Buffer->GetBufferPointer(), VS_Buffer->GetBufferSize(), &vertLayout); //Set the Input Layout d3d11DevCon->IASetInputLayout(vertLayout); //Set Primitive Topology d3d11DevCon->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); //Create the Viewport D3D11_VIEWPORT viewport; ZeroMemory(&viewport, sizeof(D3D11_VIEWPORT)); viewport.TopLeftX = 0; viewport.TopLeftY = 0; viewport.Width = Width; viewport.Height = Height; viewport.MinDepth = 0.0f; viewport.MaxDepth = 1.0f; //Set the Viewport d3d11DevCon->RSSetViewports(1, &viewport); //Create the buffer to send to the cbuffer in effect file D3D11_BUFFER_DESC cbbd; ZeroMemory(&cbbd, sizeof(D3D11_BUFFER_DESC)); cbbd.Usage = D3D11_USAGE_DEFAULT; cbbd.ByteWidth = sizeof(cbPerObject); cbbd.BindFlags = D3D11_BIND_CONSTANT_BUFFER; cbbd.CPUAccessFlags = 0; cbbd.MiscFlags = 0; hr = d3d11Device->CreateBuffer(&cbbd, NULL, &cbPerObjectBuffer); //Camera information ///////////////**************new**************//////////////////// camPosition = XMVectorSet(0.0f, 3.0f, -8.0f, 0.0f); ///////////////**************new**************//////////////////// camTarget = XMVectorSet(0.0f, 0.0f, 0.0f, 0.0f); camUp = XMVectorSet(0.0f, 1.0f, 0.0f, 0.0f); //Set the View matrix camView = XMMatrixLookAtLH(camPosition, camTarget, camUp); //Set the Projection matrix camProjection = XMMatrixPerspectiveFovLH(0.4f*3.14f, (float)Width / Height, 1.0f, 1000.0f); } RenderTimer::RenderTimer() : wxTimer() { } void RenderTimer::Notify() { dxPanel->Refresh(); } void RenderTimer::start() { wxTimer::Start(10); }
  15. Thx for the reply. Sorry if this is in the wrong section. WarpPointer does indeed generate another mouse event so it cancels out what I do. I modified the code to be like this: void MyGLCanvas::onMouseMove(wxMouseEvent& event) { GLfloat xoffset = event.GetX() - lastx; GLfloat yoffset = lasty - event.GetY(); if (xoffset > 0) xoffset = 0.5f; if (xoffset < 0) xoffset = -0.5f; if (yoffset > 0) yoffset = 0.5f; if (yoffset < 0) yoffset = -0.5f; yaw += xoffset; pitch += yoffset; if (pitch > 89.0f) pitch = 89.0f; if (pitch < -89.0f) pitch = -89.0f; glm::vec3 front; front.x = cos(glm::radians(yaw)) * cos(glm::radians(pitch)); front.y = sin(glm::radians(pitch)); front.z = sin(glm::radians(yaw)) * cos(glm::radians(pitch)); aCam->cameraAt = glm::normalize(front); lastx = event.GetX(); lasty = event.GetY(); } and I called warppointer in my render function. Then I can move the camera while keeping the cursor centered. The only thing is that its choppy. It's looks pretty bad. How can I fix the choppiness?
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!