RE: Light Direction relative to World Matrix

From: Mark Davis [MSFT] (markda_at_online.microsoft.com)
Date: 09/16/04


Date: Thu, 16 Sep 2004 00:54:54 GMT

Hi Kevin...

If you rotate the world and keep the light in a fixed position, the shadow
movement would be expected.

I believe that your world matrix would need to be an identity matrix.

It's usual practice to move the camera and derive the view matrix transform
from the camera position, orientation and lookat vectors. The world stays
fixed and the camera (and view) move around in the world space.

You can then move the light in an arc (always looking at 0,0,0) and get the
effect you are looking for. On each frame, calculate the new position of
the light (x=x*cos(angle)-y*sin(angle),y=y*cos(angle)-x*sin(angle)) and the
new direction vector (lookat-pos). Don't trust my math, though:O) Of
course, you probably also want to vary the intensity/color of the light to
achieve a more realistic sunset/sunrise.

Mark Davis (MSFT)

--
This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included information and code is subject to the terms specified at 
http://www.microsoft.com/info/cpyright.htm.
--------------------
>Reply-To: "Kevin Spencer" <kspencer@takempis.com>
>From: "Kevin Spencer" <kspencer@takempis.com>
>Subject: Light Direction relative to World Matrix
>Date: Wed, 15 Sep 2004 09:24:34 -0400
>Lines: 37
>X-Priority: 3
>X-MSMail-Priority: Normal
>X-Newsreader: Microsoft Outlook Express 6.00.3790.181
>X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.181
>Message-ID: <#r84JgymEHA.3564@tk2msftngp13.phx.gbl>
>Newsgroups: microsoft.public.win32.programmer.directx.managed
>NNTP-Posting-Host: dynamicsystems.com 216.54.1.213
>Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp13.phx.gbl
>Xref: cpmsftngxa06.phx.gbl 
microsoft.public.win32.programmer.directx.managed:7135
>X-Tomcat-NG: microsoft.public.win32.programmer.directx.managed
>
>Still working on my terrain-modelling app, and am now working on 
positioning
>and moving the camera, world matix, and lights. The problem I'm having:
>
>I position the camera directly above the 0,0,0 location in the center of my
>triangle strip, and point it down, making my "up" direction in the Z
>direction. I can then rotate the world matrix to rotate my camera. I use an
>Altitude field to set the vertical (Y) position (LookFrom) of the camera,
>and a CameraRotation field to rotate the world matrix, thus rotating my
>camera. I use a Tilt field to change the Z-component of my LookAt vector,
>and thus enable the camera to both rotate and tilt up and down. However, I
>find that when I change the X or Z component of the LookAt vector, it
>changes the direction of the light (directional) relative to the world
>matrix. This means that when I rotate the camera, the shadows on the 
terrain
>change, which they shouldn't. The light direction should remain constant
>relative to the world matrix. I can set X and Z to (0,0) to position the
>camera exactly in the center of the triangle strip (it's a spiralling
>square), and of course, the shadows don't change. However, I want to be 
able
>to simulate different times of day by setting the angle of the light. I
>spent a long time last night trying to find the solution.
>
>I believe my math skills are not well-developed enough. I know that the
>directional light direction is a vector, but I dont' know how to rotate it
>relative to the world matrix. I can rotate a matrix, but how do you rotate 
a
>vector? Or am I barking up the wrong tree here? Should I be rotating my
>camera instead of the world matrix?
>
>Any help?
>
>-- 
>TIA,
>Kevin Spencer
>.Net Developer
>Microsoft MVP
>I get paid good money to
>solve puzzles for a living
>
>
>


Relevant Pages

  • Re: FPS decrease in 3.0.2
    ... especialy when i rotate the camera or something. ... It's the shadows they added, ... warn they were drastically upgrading the graphics in WOTLK. ...
    (alt.games.warcraft)
  • Re: Camera preview orientation on HTC-Universal
    ... It sounds to me like you're seeing a camera ... does not use DirectShow or the DirectShow camera driver. ... This is necessary because as you rotate the shell on the device you also physically rotate the device. ... How can I tell the output renderer to NOT rotate / flip the content? ...
    (microsoft.public.pocketpc.developer)
  • Re: Light Direction relative to World Matrix
    ... > from the camera position, ... I can then rotate the world matrix to rotate my camera. ... I use a Tilt field to change the Z-component of my LookAt vector, ... >>Microsoft MVP ...
    (microsoft.public.win32.programmer.directx.managed)
  • Re: Camera preview orientation on HTC-Universal
    ... Rendering the preview pin as you did below should always result in the image ... It sounds to me like you're seeing a camera ... does not use DirectShow or the DirectShow camera driver. ... >> the correct orientation (don't rotate when rendering it). ...
    (microsoft.public.pocketpc.developer)
  • Light Direction relative to World Matrix
    ... Still working on my terrain-modelling app, and am now working on positioning ... I position the camera directly above the 0,0,0 location in the center of my ... I can then rotate the world matrix to rotate my camera. ... I use a Tilt field to change the Z-component of my LookAt vector, ...
    (microsoft.public.win32.programmer.directx.managed)