XNA Creators Club Online
Page 1 of 1 (5 items)
Sort Posts: Previous Next

Ray casting & 3D cursor

Last post 05-16-2008 10:24 AM by skytigercube. 4 replies.
  • 05-13-2008 9:05 AM

    Ray casting & 3D cursor

    Hello

    Well the subject is a bit confusing, in fact i got two seperate questions :

    -First is there any tool for checking where a ray intersects a given mesh? The only related thing i found was the Ray structure but unfortunately returned values don't help much.What could be the best solution to determine where the ray intersects the mesh if it does.Argh I' m missing D3DXIntersectTri ...

    - Second question how can i render a 3D cursor which fit the mesh shape that is under mouse cursor (I'm working on a level builder) ; if i want this cursor to be a simple colored shape ? and if i want it to be a texture ?

    Sincerely.

     

     

  • 05-13-2008 10:29 AM In reply to

    Re: Ray casting & 3D cursor

    Are you using XNA or native DirectX? D3DXIntersectTri is native only.

    If you are looking for XNA equivalent then check out the picking sample http://creators.xna.com/Headlines/developmentaspx/archive/2007/01/01/Picking-with-Triangle_2D00_Accuracy.aspx

    To draw a 3d cursor you need to use similar math from that sample. Take the 2d mouse coordinates and project them into world space. Then you can manipulate the world coordinates however you want to draw in 3d under the mouse. I admit I'm not 100% sure what you are looking for though.



    The ZBuffer News and information for XNA

    Please read the forum FAQs - Bug reporting
  • 05-14-2008 2:17 PM In reply to

    Re: Ray casting & 3D cursor

    Thanks for the link .For the cursor thing i would like to splat a cursor pattern on the mesh pointed by the mouse(like a decal) it could be a colored circle,square or a texture ... I could use a simple textured square but i want the cursor to have a similar shape , it should map on the given mesh.Because a picture is better than my poor english here' s an example similar to what i'm trying to do ; note the yellow circle under the character.

    Thanks.

  • 05-16-2008 5:56 AM In reply to

    Re: Ray casting & 3D cursor

    use the face normal at the intersection point

    to place a "light" a standard distance from the point

    use a static texture with a yellow circle

    use shadow mapping technique
    translate the mesh vertex world positions
    into the "light" point of view and lookup texel
    blend with normal color


  • 05-16-2008 10:24 AM In reply to

    Re: Ray casting & 3D cursor

    I am on a RenderMonkey mission at the moment so I knocked this up for you

    float4x4 matViewProj;
    float4x4 matView;
    float4x4 matProj;
    float4x4 matLight;
    float4x4 matObject;
    //
    struct VS_INPUT {
    float4 Position : POSITION0;
    float2 TexCoord : TEXCOORD0;
    };
    //
    struct VS_OUTPUT {
    float4 Position : POSITION0;
    float2 TexCoord : TEXCOORD0;
    float4 ShadowCoord : TEXCOORD1;
    };
    //
    VS_OUTPUT vs_main(VS_INPUT Input) {
    //
    VS_OUTPUT Output;
    //
    float4 worldPos = Input.Position;
    float4x4 matViewProj = mul(matView, matProj);
    Output.Position = mul(worldPos, matViewProj);
    //
    Output.TexCoord = Input.TexCoord; // for texture
    Output.ShadowCoord = mul(worldPos, mul(matLight, matProj));
    Output.ShadowCoord /= Output.ShadowCoord.w;
    //
    return Output;
    //
    }//method

    //
    sampler texture0;
    sampler texture1;
    //
    struct PS_INPUT {
    float2 TexCoord : TEXCOORD0;
    float4 ShadowCoord : TEXCOORD1;
    };
    //
    float4 ps_main(PS_INPUT Input) : COLOR0 {
    float4 diffuse = tex2D(texture0, Input.TexCoord);
    float2 coord = (1.0f + Input.ShadowCoord.xy) * 0.5f;
    float depth = Input.ShadowCoord.z;
    float4 shadow = tex2D(texture1, coord);
    return (diffuse + shadow) * 0.5f;
    }//method

Page 1 of 1 (5 items) Previous Next