The code I posted earlier does not take into account rotation of the camera, it only works if the camera is not rotated. The following code gives a torch effect; imagine that you are looking through the eyes of a person holding a torch (or if you prefer, a person with a very bright face
). This works regardless of camera rotation:
#include "darkGDK.h"
void DarkGDK(void)
{
int iLightId = 1; // Id of light to be positioned ahead of camera
int iObjectId = 1; // Id of object used to find position for light to point towards
int fLightRange = 75.0f; // Range that light should travel
int fLightInner = 0.0f;
int fLightOuter = 360.0f;
// Create object
dbMakeObjectCube(iObjectId,1);
dbHideObject(iObjectId);
// Create light
dbMakeLight(iLightId);
dbSetSpotLight(iLightId,fLightInner,fLightOuter);
dbSetLightRange(iLightId,fLightRange);
dbColorLight(iLightId,dbRGB(255,0,0));
dbHideLight(0);
// Create something that we can see
dbMakeObjectCube(2,50);
while(LoopGDK())
{
dbSync();
dbControlCameraUsingArrowKeys(0,1,5); // Camera controls
dbPositionObject(iObjectId,dbCameraPositionX(0), dbCameraPositionY(0), dbCameraPositionZ(0)); // Position object used to find location that light should point towards
dbPointObject(iObjectId, 0, 0, dbCameraAngleZ(0)); // Rotate object used to find direction that it should be moved so that it is infront of camera
dbMoveObject(iObjectId,5); // Move object infront of camera
dbPositionLight(iLightId,dbCameraPositionX(0),dbCameraPositionY(0),dbCameraPositionZ(0)); // Position light at camera position
dbPointLight(iLightId,dbObjectPositionX(iObjectId),dbObjectPositionY(iObjectId),dbObjectPositionZ(iObjectId));
}
return;
}