Jump to content
  • Advertisement
Sign in to follow this  
steg

D3D10 - world position for objects and objects in world

This topic is 3317 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I've just started to use D3D10, have used DX9 a few years back but not touched it for ages and certainly didn't use any shader stuff. Now with the new pipeline in D3D10 I have to use shaders. What I have is a simple fx file to position some primitives, all pretty simple here:

matrix World;
matrix View;
matrix Projection;

struct PS_INPUT
{

  float4 Pos : SV_POSITION;
  float4 Color : COLOR0;
};

 
PS_INPUT VS( float4 Pos : POSITION, float4 Color : COLOR )
{

  PS_INPUT psInput;
  
  Pos = mul( Pos, World );
  Pos = mul( Pos, View );

  psInput.Pos = mul( Pos, Projection );

  psInput.Color = Color;
  return psInput; 
}

float4 PS( PS_INPUT psInput ) : SV_Target
{
    return psInput.Color;
}

technique10 Render

{
    pass P0
    {
        SetVertexShader( CompileShader( vs_4_0, VS() ) );
        SetGeometryShader( NULL );
        SetPixelShader( CompileShader( ps_4_0, PS() ) );
    }
}
Now, my question is, for each object in my 'world', I guess I just pass in its world coordinates to my world matrix in the shader file to position it? Every object I have will have its own world coordinates, simple class shown below:

template <typename T>
class CGenericObj
{
public:
   virtual void DrawObject(T buffer) = 0;
   virtual void UpdateObject(float wPos, float yPos, float zPos) = 0;
private:
   D3D10_SUBRESOURCE_DATA resData;
   D3D10_BUFFER_DESC buffDesc;
   std::vector<T>objectVertexBuffer;  // hold vertices for object
   float world_xPos, world_yPos, world_zPos;
   // etc...
};

Okay, class has a few functions etc and some buffers. What is needed to encapsulate a full object in order to render it? I mean, besides it's world position, it needs its geometry ( vertices ), buffer description, sub resource structure, what else would it need? It's own input layout? It's own effect file, although wouldn't have thought so. What I'm trying to do is have a class which encapsulates what is needed to just render an object. Of course there would be many other classes which each class would derive from such as maybe a state class, for the state of the object ( alive, dead, energy left etc...). Sorry if this doesn't make any sense?! Thanks, Steve

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

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

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!