Thread: is it possible to draw the ray D3DXIntersect creates?

  1. #1
    Registered User
    Join Date
    Nov 2002
    Posts
    319

    is it possible to draw the ray D3DXIntersect creates?

    is it possible to draw the ray D3DXIntersect creates? , DrawLine only draws x , y cordinates and not z ,

  2. #2
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    You would have to create a primitive using the ray. Using the parametric form you should be able to cast a ray using the info from D3DXIntersect and a set distance.

  3. #3
    Registered User
    Join Date
    Nov 2002
    Posts
    319
    but no primitive would be able to be drawn on the z axis

  4. #4
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    Sure it can. Given a 3D vector and a distance:

    Code:
    #ifndef VERTEX_H
    #define VERTEX_H
    
    struct  Vertex
    {
      float x,y,z;
      float u,v;
     
      Vertex():x(0.0f),y(0.0f),z(0.0f),u(0.0f),v(0.0f) { }
      Vertex(float x,float y,float z,float u, float v):x(x),y(y),z(z),u(u),v(v) { }
    
      static const DWORD FVF;
    };
    
    #endif
    Code:
    #include "Vertex.h"
    
    const DWORD Vertex::FVF = D3DFVF_XYZ | D3DFVF_TEX1;
    
    Vertex Vertices[4];
    
    void CreateVerticesFromRay(D3DXVECTOR3 vecRay, float dist)
    {
      D3DXVec3Normalize(&vecRay,&vecRay);
    
      Vertices[0]  = Vertex(0.0f,0.0f,0.0f,0.0f,0.0f);
      Vertices[1] = Vertex(vecRay.x * dist,0.0f,0.0f,1.0f,0.0f);
      Vertices[2] = Vertex(0.0f,0.0f,vecRay.z * dist,0.0f,1.0f);
      Vertices[3] = Vertex(vecRay.x * dist,0.0f, vecRay.z * dist,1.0f,1.0f);
    
    }
    What do you mean you cannot draw a primitive on the z axis?

  5. #5
    Registered User
    Join Date
    Nov 2002
    Posts
    319
    i cant seem to make the line transformed so if the ray moves , so does the line to show where the ray is , it seems like the line is just stuck on front of the screen with no z direction etc...here is a screen shot

    http://img86.imageshack.us/my.php?image=d3dlinest6.jpg

  6. #6
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    That's not much help. Post some code and I can help fix it. Incorrect rendering can be caused by incorrect projection matrices, incorrect translation/rotation/scaling/shearing, etc, etc matrices and so on. There are an inumerable about issues that could be happening. Guessing won't help you any so post the code that's drawing the line and setting the system up.

  7. #7
    Registered User
    Join Date
    Nov 2002
    Posts
    319
    DXCreateCylinder(d3dDevice, 0.5, 0.5, 4000, 8, 8, &m_RayMesh, NULL);
    D3DXMatrixInverse(&matRayWorld, NULL, &matView);
    bitmatRayWorld._42 -= 1.0f;
    meshd3dDevice->SetTransform(D3DTS_WORLD, matRayWorld);
    m_RayMesh->DrawSubset(0);

    this should draw the ray now right ? , RayPos ,
    Last edited by Anddos; 02-10-2008 at 05:09 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help designing a recursive function.
    By broli86 in forum C Programming
    Replies: 3
    Last Post: 07-24-2008, 12:45 PM
  2. Which is the better way to draw?
    By g4j31a5 in forum Game Programming
    Replies: 16
    Last Post: 01-22-2007, 11:56 PM
  3. draw function HELP!!!
    By sunoflight77 in forum C++ Programming
    Replies: 1
    Last Post: 05-10-2005, 11:28 PM
  4. ray casting
    By lambs4 in forum Game Programming
    Replies: 62
    Last Post: 01-09-2003, 06:57 PM
  5. Draw Shapes.
    By Unregistered in forum C Programming
    Replies: 1
    Last Post: 08-19-2002, 09:22 AM