Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Defining World, Projection and View Matrices

Defining World, Projection and View Matrices

Scheduled Pinned Locked Moved C / C++ / MFC
graphicshelp
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Alan Chambers
    wrote on last edited by
    #1

    Hi all, got stuck on Direct3D again, already. I have created my translation, rotation, scale and concatenation matrices and would like to create a world, projection and view matrix so that I can render a triangle defined in 3d space to the screen. So far my world matrix is equivelant to the Identity matrix (1,0,0,0)(0,1,0,0)(0,0,1,0)(0,0,0,1). I have the following code for my projection and view matrix respectively: void CDXMaths::Projection(float nearplane, float farplane, float fov) { cosine = (float)cos(fov*0.5); sine = (float)sin(fov*0.5); quat = sine / (1.0f - (nearplane / farplane)); m_Projection = Empty(); m_Projection(0,0) = cosine; m_Projection(1,1) = cosine; m_Projection(2,2) = quat; m_Projection(2,3) = sine; m_Projection(3,2) = -quat * nearplane; } void CDXMaths::View(D3DVECTOR from, D3DVECTOR lookat, D3DVECTOR worldup, float roll) { m_View = Identity(); D3DVECTOR updir, rightdir, viewdir; viewdir = Normalize(lookat - from); rightdir = CrossProduct(worldup, viewdir); updir = CrossProduct(viewdir, rightdir); rightdir = Normalize(rightdir); updir = Normalize(worldup); m_View(0,0) = rightdir.x; m_View(0,1) = updir.x; m_View(0,2) = viewdir.x; m_View(1,0) = rightdir.y; m_View(1,1) = updir.y; m_View(1,2) = viewdir.y; m_View(2,0) = rightdir.z; m_View(2,1) = updir.z; m_View(2,2) = viewdir.z; m_View(3,0) = -DotProduct(rightdir, from); m_View(3,1) = -DotProduct(updir, from); m_View(3,2) = -DotProduct(viewdir, from); if (roll != 0.0f) { m_View = Multiply(RotateZ(-roll), m_View); } } For the Projection matrix I set the field of view to 60 degrees (converted to radians) with a near plane of 1.0f and a far plane of 1000.0f. For the view matrix I set the from vector to (0,0,0), the lookat vector to (0,0,1), the worldup vector to (0,1,0) and the roll to 0. I then set the D3DDevices geometry pipeline to these world, projection and view matrices (in that order, with appropriate flags). The code I then use to render is: m_pD3DDevice->SetRenderState(D3DRENDERSTATE_LIGHTING, false); if (SUCCEEDED(m_pD3DDevice->BeginScene())) { D3DLVERTEX v[3]; v[0] = D3DLVERTEX(D3DVECTOR(0,2,10), D3DRGB(1,0,0), D3DRGB(1,0,0), 0, 0); v[1] = D3DLVERTEX(D3DVECTOR(2,-2,10), D3DRGB(0,1,0), D3DRGB(1,0,0), 0, 0); v[2] = D3DLVERTEX(D3DVECTOR(-2,-2,10), D3DRGB(0,0,1), D3DRGB(1,0,0), 0, 0); m_pD3DDevice->DrawPrimitive(D3DPT_TRIANGLELIST, D3DFVF_LVERTEX, (LPVOID)v, 3, NULL); } return m_pD3DDevice->EndScene(); However, I just get a black scree

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups