• Advertisement
Sign in to follow this  

DX11 Plane generation issue...

This topic is 2057 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, im Miguel Petersen, and im currently having a problem with generating planes... I know that i did a stupid mistake, but unfortunately, i can't find itdry.png

So, i would like to ask you for some help:


#include <d3d11.h>
#include <d3dx11.h>
#include <d3dx10.h>
struct PLANE {FLOAT X, Y, Z; D3DXVECTOR3 Normal; FLOAT U, V;};
class PlaneStruct
{
public:PLANE PlaneVertices[3];
public:DWORD PlaneIndices[5];
void CreatePlane(float size)
{
PLANE PlaneObject;
PlaneObject.X = 1.0f * size;
PlaneObject.Y = 0.0f;
PlaneObject.Z = 1.0f * size;
PlaneObject.Normal = D3DXVECTOR3(0.0f, 0.0f, 1.0f);
PlaneObject.U = 0.0f;
PlaneObject.V = 0.0f;
PLANE PlaneObject1;
PlaneObject.X = -1.0f * size;
PlaneObject.Y = 0.0f;
PlaneObject.Z = 1.0f * size;
PlaneObject.Normal = D3DXVECTOR3(0.0f, 0.0f, 1.0f);
PlaneObject.U = 0.0f;
PlaneObject.V = 1.0f;
PLANE PlaneObject2;
PlaneObject.X = -1.0f * size;
PlaneObject.Y = 0.0f;
PlaneObject.Z = -1.0f * size;
PlaneObject.Normal = D3DXVECTOR3(0.0f, 0.0f, 1.0f);
PlaneObject.U = 1.0f;
PlaneObject.V = 0.0f;
PLANE PlaneObject3;
PlaneObject.X = 1.0f * size;
PlaneObject.Y = 0.0f;
PlaneObject.Z = -1.0f * size;
PlaneObject.Normal = D3DXVECTOR3(0.0f, 0.0f, 1.0f);
PlaneObject.U = 1.0f;
PlaneObject.V = 1.0f;

PlaneVertices[0] = PlaneObject;
PlaneVertices[1] = PlaneObject1;
PlaneVertices[2] = PlaneObject2;
PlaneVertices[3] = PlaneObject3;
PlaneIndices[0] = 0;
PlaneIndices[1] = 2;
PlaneIndices[2] = 1;
PlaneIndices[3] = 0;
PlaneIndices[4] = 3;
PlaneIndices[5] = 2;
}
};


Best Regards
Miguel Petersen Edited by Migi0027

Share this post


Link to post
Share on other sites
Advertisement
You are messing up pretty badly with the vertices/indices, a simple plane would simply look like this:
//4 vertices, 6 indices
[source lang="cpp"]
vertices[0].pos = D3DXVECTOR3(0.0f, 0.0f, 0.0f);
vertices[1].pos = D3DXVECTOR3(10.0f, 0.0f, 0.0f);
vertices[2].pos = D3DXVECTOR3(0.0f, 0.0f, 10.0f);
vertices[3].pos = D3DXVECTOR3(10.0f, 0.0f, 10.0f);

vertices[0].normal = D3DXVECTOR3(0.0f, 1.0f, 0.0f);
vertices[1].normal = D3DXVECTOR3(0.0f, 1.0f, 0.0f);
vertices[2].normal = D3DXVECTOR3(0.0f, 1.0f, 0.0f);
vertices[3].normal = D3DXVECTOR3(0.0f, 1.0f, 0.0f);


vertices[0].tex = D3DXVECTOR2(0.0f, 1.0f); // texcoords start left top corner!
vertices[1].tex = D3DXVECTOR2(1.0f, 1.0f);
vertices[2].tex = D3DXVECTOR2(0.0f, 0.0f);
vertices[3].tex = D3DXVECTOR2(1.0f, 0.0f);



indices[0] = 0;
indices[1] = 1;
indices[2] = 2;
indices[3] = 0;
indices[4] = 2;
indices[5] = 3;

[/source]


I hope that helps Edited by gnomgrol

Share this post


Link to post
Share on other sites
Thanks for replying, ill test if it works when i get another challange done:
http://www.gamedev.net/topic/627421-c-dx11-render-to-panel/

Share this post


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

  • Advertisement
  • Advertisement
  • Popular Tags

  • Advertisement
  • Popular Now

  • Similar Content

    • By Karol Plewa
      Hi, 
       
      I am working on a project where I'm trying to use Forward Plus Rendering on point lights. I have a simple reflective scene with many point lights moving around it. I am using effects file (.fx) to keep my shaders in one place. I am having a problem with Compute Shader code. I cannot get it to work properly and calculate the tiles and lighting properly. 
       
      Is there anyone that is wishing to help me set up my compute shader?
      Thank you in advance for any replies and interest!
    • By turanszkij
      Hi, right now building my engine in visual studio involves a shader compiling step to build hlsl 5.0 shaders. I have a separate project which only includes shader sources and the compiler is the visual studio integrated fxc compiler. I like this method because on any PC that has visual studio installed, I can just download the solution from GitHub and everything just builds without additional dependencies and using the latest version of the compiler. I also like it because the shaders are included in the solution explorer and easy to browse, and double-click to open (opening files can be really a pain in the ass in visual studio run in admin mode). Also it's nice that VS displays the build output/errors in the output window.
      But now I have the HLSL 6 compiler and want to build hlsl 6 shaders as well (and as I understand I can also compile vulkan compatible shaders with it later). Any idea how to do this nicely? I want only a single project containing shader sources, like it is now, but build them for different targets. I guess adding different building projects would be the way to go that reference the shader source project? But how would they differentiate from shader type of the sources (eg. pixel shader, compute shader,etc.)? Now the shader building project contains for each shader the shader type, how can other building projects reference that?
      Anyone with some experience in this?
    • By osiris_dev
      Hello!
      Have a problem with reflection shader for D3D11:
      1>engine_render_d3d11_system.obj : error LNK2001: unresolved external symbol IID_ID3D11ShaderReflection
      I tried to add this:
      #include <D3D11Shader.h>
      #include <D3Dcompiler.h>
      #include <D3DCompiler.inl>
      #pragma comment(lib, "D3DCompiler.lib")
      //#pragma comment(lib, "D3DCompiler_47.lib")
      As MSDN tells me but still no fortune. I think lot of people did that already, what I missing?
      I also find this article http://mattfife.com/?p=470
      where recommend to use SDK headers and libs before Wind SDK, but I am not using DirectX SDK for this project at all, should I?
    • By trojanfoe
      Hi there, this is my first post in what looks to be a very interesting forum.
      I am using DirectXTK to put together my 2D game engine but would like to use the GPU depth buffer in order to avoid sorting back-to-front on the CPU and I think I also want to use GPU instancing, so can I do that with SpriteBatch or am I looking at implementing my own sprite rendering?
      Thanks in advance!
    • By Matt_Aufderheide
      I am trying to draw a screen-aligned quad with arbitrary sizes.
       
      currently I just send 4 vertices to the vertex shader like so:
      pDevCon->IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
      pDevCon->Draw(4, 0);
       
      then in the vertex shader I am doing this:
      float4 main(uint vI : SV_VERTEXID) : SV_POSITION
      {
       float2 texcoord = float2(vI & 1, vI >> 1);
      return float4((texcoord.x - 0.5f) * 2, -(texcoord.y - 0.5f) * 2, 0, 1);
      }
      that gets me a screen-sized quad...ok .. what's the correct way to get arbitrary sizes?...I have messed around with various numbers, but I think I don't quite get something in these relationships.
      one thing I tried is: 
       
      float4 quad = float4((texcoord.x - (xpos/screensizex)) * (width/screensizex), -(texcoord.y - (ypos/screensizey)) * (height/screensizey), 0, 1);
       
      .. where xpos and ypos is number of pixels from upper right corner..width and height is the desired size of the quad in pixels
      this gets me somewhat close, but not right.. a bit too small..so I'm missing something ..any ideas?
       
      .
  • Advertisement