   2D projection from 3D space
  I am working on lens flares and part of the algorithm is to draw a 2d occlusion test shape at a 3d position. I should be seeing my shape the way I have it set up, but I can't get it to render, nor do any of the coords look right.I am just trying to render a 100x100 pixel square, given a 3D position.So, I need to project the 3D position into screen space.I thought I had it right, but evidently not, or I would be seeing a white square on my screen. I've narrowed down the original attempt to the barebones step 1 I described in this thread:#ifndef LENSFLARE2_H#define LENSFLARE2_H// EngineX Includes#include "Graphics/3D/InputLayoutManager.h"#include "Graphics/Textures/TextureManager.h"#include "Graphics/Effects/EffectManager.h"#include "Graphics/3D/PolygonSet.h"// DirectX Includes#include <d3d10.h>#include <d3dx10.h>// Standard Includes#include <vector>//-----------------------------------------------------------------------class LensFlare2{public:   /**   * Constructor   **/   LensFlare2(ID3D10Device & device,InputLayoutManager & inputLayoutManager,    TextureManager & textureManager,EffectManager & effectManager);   /**   * Deconstructor   **/   ~LensFlare2();   /**   *   **/   void Render();private:   const floatm_querySize;   ID3D10Device &  m_device;// DirectX device   InputLayoutManager & m_inputLayoutManager;   // Contains and creates input layouts for shaders   TextureManager &m_textureManager;  // Contains all loaded textures    EffectManager & m_effectManager;   // Effect pool that contains all effects   PolygonSet *    m_occlusionShape;  // Shape to test for occlusion D3DXVECTOR3m_position;};#endif // LENSFLARE2_H#include "LensFlare2.h"// Common Lib Includes#include "StringUtil.h"#include "BaseException.h"// Standard Includes#include <algorithm>using namespace common_lib_cpisz;//---------------------------------------------------------------------------LensFlare2::LensFlare2(ID3D10Device & device,    InputLayoutManager & inputLayoutManager,    TextureManager & textureManager,   EffectManager & effectManager)   :   m_querySize(100.0f),   m_device(device),   m_inputLayoutManager(inputLayoutManager),   m_textureManager(textureManager),   m_effectManager(effectManager),   m_occlusionShape(NULL),   m_position(D3DXVECTOR3(0.0f, 100.f, 0.0f)){   BaseException exception("Not Set",  "LensFlare::LensFlare(ID3D10Device & device, InputLayoutManager & inputLayoutManager, TextureManager & textureManager, EffectManager & effectManager, const std::string & glowTextureFilePath, const std::string & flare1TextureFilePath, const std::string & flare2TextureFilePath, const std::string & flare3TextureFilePath)",  "LensFlare.cpp");   // Create the effect   Effect & effect = m_effectManager.CreateChildEffect("LensFlare", "LensFlare.fx");   // Create a occlusion query rectangle shape   //   // What should the z components be set to?   std::vector<Buffer::SharedPtr> occlusionShapeBuffers;   std::vector<Position> queryPositions;   queryPositions.push_back(Position( -m_querySize / 2.0f, -m_querySize / 2.0f, 0.0f));   queryPositions.push_back(Position( -m_querySize / 2.0f,  m_querySize / 2.0f, 0.0f));   queryPositions.push_back(Position(  m_querySize / 2.0f, -m_querySize / 2.0f, 0.0f));   queryPositions.push_back(Position(  m_querySize / 2.0f,  m_querySize / 2.0f, 0.0f));   Buffer::SharedPtr queryPositionBuffer(new Buffer(m_device, POSITION, queryPositions, false));   occlusionShapeBuffers.push_back(queryPositionBuffer);   m_occlusionShape = new PolygonSet(m_device, inputLayoutManager, effectManager);   m_occlusionShape->SetBuffers(occlusionShapeBuffers, D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);   m_occlusionShape->SetEffect(effect.GetName(), "OcclusionQuery");   Material occlusionMaterial = m_occlusionShape->GetMaterial();   occlusionMaterial.SetFloat4("diffuseColor", static_cast<D3DXVECTOR4>(D3DXCOLOR( 1.0f, 1.0f, 1.0f, 1.0f)));   m_occlusionShape->SetMaterial(occlusionMaterial);}//---------------------------------------------------------------------------LensFlare2::~LensFlare2(){   // Release the occlusion shape   if( m_occlusionShape )   { delete m_occlusionShape;   }}//---------------------------------------------------------------------------void LensFlare2::Render(){   // Get the viewport   UINT numViewports = 1;   D3D10_VIEWPORT viewport;   m_device.RSGetViewports(&numViewports, &viewport);   // Get the original matrices (that were set by the camera)   D3DXMATRIX origProjection;   D3DXMATRIX origView;   m_effectManager.GetViewMatrix(origView);   m_effectManager.GetProjectionMatrix(origProjection);   // Create new matrices for projection from 3D to 2D screen space   D3DXMATRIX world;   D3DXMatrixIdentity(&world);   D3DXMATRIX newView = origView;   newView._41 = newView._42 = newView._43 = 0.0f;   // Project the 3D position into 2D screen space   D3DXVECTOR3 projectedPosition;   D3DXVec3Project(&projectedPosition, &m_position, &viewport, &origProjection, &newView, &world);   // Create matrices to render the shape in 2D screen space   D3DXMatrixIdentity(&world);   world._31 = projectedPosition.x;   world._32 = projectedPosition.y;   world._33 = 0.1f;  // What should this be set to?   Effect & effect = m_effectManager.GetChildEffect("LensFlare");   effect.SetWorldMatrix(world);   D3DXMATRIX view;   D3DXMatrixIdentity(&view);   m_effectManager.SetViewMatrix(view);   D3DXMATRIX projection;   D3DXMatrixOrthoOffCenterLH(&projection,0.0f,static_cast<float>(viewport.Width),static_cast<float>(viewport.Height),0.0f,0.0f,1.0f);   m_effectManager.SetProjectionMatrix(projection);   // Render the shape   m_occlusionShape->Render();   // Restore Matrices   m_effectManager.SetViewMatrix(origView);   m_effectManager.SetProjectionMatrix(origProjection);}//--------------------------------------------------------------------------------------// File: LensFlare.fx////--------------------------------------------------------------------------------------#include "EffectPool.fxh"matrix world  : World;matrix worldInverseTranspose : WorldInverseTranspose;//-------------------// Diffuse Variables//// Diffuse Color can be a single color or sampled from a texturefloat4    diffuseColor    = float4(1.0f, 1.0f, 1.0f, 1.0f);Texture2D diffuseTexture;bool diffuseMapped   = false;   // true if texture is mapped to diffuse colorSamplerState samplerLinear{   Filter = MIN_MAG_MIP_LINEAR;   AddressU = Wrap;   AddressV = Wrap;};//////// CONNECTOR DATA STRUCTURES ////////////* Data from application vertex buffer */struct VS_INPUT{   float4   position  : POSITION;};/* Data passed from vertex shader to pixel shader */struct PS_INPUT{   float4 position : SV_POSITION;};//////// BLEND STATES ///////////BlendState NoBlending{   BlendEnable[0] = FALSE;};//--------------------------------------------------------------------------------------// Vertex Shader//--------------------------------------------------------------------------------------//--------------------------------------------------------------------------------------// Simply transforms positions and normals// PS_INPUT VS( VS_INPUT input ){   PS_INPUT output = (PS_INPUT)0; // Transform the incoming model-space position to projection space   matrix worldViewProjection = mul( mul(world, view), projection);   output.position  = mul( input.position, worldViewProjection);  return output;}//--------------------------------------------------------------------------------------// Pixel Shaders//--------------------------------------------------------------------------------------//--------------------------------------------------------------------------------------// Simply shades an object at 100% opacity, with no lights or shadows//float4 PS( PS_INPUT input ) : SV_Target{float4 colorD = diffuseColor;   //   if( diffuseMapped )//   {// colorD = diffuseTexture.Sample(samplerLinear, input.texCoord);//   } colorD.a = 1; return colorD;}//--------------------------------------------------------------------------------------// Techniques//--------------------------------------------------------------------------------------//--------------------------------------------------------------------------------------// Renders an object at 100% opacity, with no lights or shadows//technique10 RenderDefault{    pass P0    {   SetVertexShader( CompileShader( vs_4_0, VS() ) );   SetGeometryShader( NULL );   SetPixelShader( CompileShader( ps_4_0, PS() ) ); SetBlendState( NoBlending, float4(0.0f, 0.0f, 0.0f, 0.0f), 0xFFFFFFFF);    }}//--------------------------------------------------------------------------------------// Renders an object at 100% opacity, with no lights or shadows//technique10 OcclusionQuery{    pass P0    {   SetVertexShader( CompileShader( vs_4_0, VS() ) );   SetGeometryShader( NULL );   SetPixelShader( CompileShader( ps_4_0, PS() ) ); SetBlendState( NoBlending, float4(0.0f, 0.0f, 0.0f, 0.0f), 0xFFFFFFFF);    }}I am getting -1.#IND for my position components after the projection :/You will have to trust me that my PolygonShape, Effect, EffectManager, Material, etc. classes all work, as I have been using them for several other demos.I'm lost.   