Discussion:
Shadows
(too old to reply)
m***@bmtmis.demon.co.uk
2008-02-26 11:24:25 UTC
Permalink
Hi,

Can anyone help me with this?

I have a VERY simple application - Visual Studio 2005 using C#

I have two vertexbuffers.

One is filled with the four corners of a sqaure. The square lays on
the z = 0 plane and is of side length 40 - so vertices are (-40,-40,0),
(40,-40,0),(40,40,0),(-40,40,0) - easy.

The other is filled with the vertices of a cube. cube's centre is at
(0,0,1) and is of side length 2. So it sits on the plane defined by
the squre.

All I want to do is render the shadow of the cube on the plane.

My light source position is (13,0,3)

I define the following:

Plane m_shadowPlane = new Plane(0.0f, 0.0f, 1.0f, 0.0f);

Matrix m_shadowMatrix;
m_shadowMatrix.Shadow(new Vector4(13,0,3,0), m_shadowPlane);

Then in my render code I have:

m_device.Transform.World = Matrix.Identity;
RenderCube();
RenderSquare();

m_device.Transform.World = m_shadowMatrix;
RenderCube();

All works fine. Shadow is there.

BUT if I change the cube so that is is NOT centred at the origin BUT
centred directly under the light at (13,0,3) the the shaow stays at
the origin and stays of the same shape as it was before.

Now that the light is right above the cube the shadow should be a
square, not the extented shape which is was previously when the cube
was at the origin.

Has anyone managed to use Matrix.Shadow correctly?

Where am I wrong, this seems soooooooooo simple.

Thanks,
Mitch.
m***@bmtmis.demon.co.uk
2008-02-26 14:58:13 UTC
Permalink
Post by m***@bmtmis.demon.co.uk
Hi,
Can anyone help me with this?
I have a VERY simple application - Visual Studio 2005 using C#
I have two vertexbuffers.
One is filled with the four corners of a sqaure. The square lays on
the z = 0 plane and is of side length 40 - so vertices are (-40,-40,0),
(40,-40,0),(40,40,0),(-40,40,0) - easy.
The other is filled with the vertices of a cube. cube's centre is at
(0,0,1) and is of side length 2. So it sits on the plane defined by
the squre.
All I want to do is render the shadow of the cube on the plane.
My light source position is (13,0,3)
Plane m_shadowPlane = new Plane(0.0f, 0.0f, 1.0f, 0.0f);
Matrix m_shadowMatrix;
m_shadowMatrix.Shadow(new Vector4(13,0,3,0), m_shadowPlane);
m_device.Transform.World = Matrix.Identity;
RenderCube();
RenderSquare();
m_device.Transform.World = m_shadowMatrix;
RenderCube();
All works fine. Shadow is there.
BUT if I change the cube so that is is NOT centred at the origin BUT
centred directly under the light at (13,0,3) the the shaow stays at
the origin and stays of the same shape as it was before.
Now that the light is right above the cube the shadow should be a
square, not the extented shape which is was previously when the cube
was at the origin.
Has anyone managed to use Matrix.Shadow correctly?
Where am I wrong, this seems soooooooooo simple.
Thanks,
Mitch.
No worries. Found my error.

Mitch.

Loading...