Original Post
I am having trouble with my street lamp that follows the player and i am trying to make it so there is a light emmiting from the lamp but i am having trouble, i'm using c++ and DirextX 9 the lamp rotates to follow the player its just the light, it does not show any
CSearchLamp::CSearchLamp(void)
{
}
CSearchLamp::~CSearchLamp(void)
{
}
bool CSearchLamp::create(LPDIRECT3DDEVICE9 device)
{
positionVector.x = 0.0f;
positionVector.y = 0.0f;
positionVector.z = 0.0f;
pModel = new CModel();
pModel->loadModel(device, "./models/lamp.X");
return true;
}
D3DXVECTOR3 CSearchLamp::getPosition()
{
return positionVector;
}
void CSearchLamp::setPosition(D3DXVECTOR3 newPosition)
{
positionVector = newPosition;
}
void CSearchLamp::update(float dtime, float animRate, D3DXVECTOR3 playerPos)
{
// Get the ghost to turn to face player
////////////////////////////////////
//Get the desired direction that we want the ghost to face
desiredDirection = D3DXVECTOR3(playerPos.x - positionVector.x,playerPos.y - positionVector.y,playerPos.z - positionVector.z);
angle = atan2(desiredDirection.x, desiredDirection.z);//this returns the angle needed in Rads
rotationY = angle;
createSerchLights();
}
void CSearchLamp::render(LPDIRECT3DDEVICE9 device)
{
D3DXMATRIX transMatrix; // the translation matrix
D3DXMATRIX scaleMatrix; // the scale matrix
D3DXMATRIX rotateMatrix; // The rotation matrix
// Setup the translation matrix
D3DXMatrixTranslation(&transMatrix, positionVector.x, positionVector.y, positionVector.z);
// Cause the space to rotate
D3DXMatrixRotationY(&rotateMatrix,rotationY);
// Scale the space by the size amount
D3DXMatrixScaling(&scaleMatrix, size, size, size);
// Multiply the rotation matrix by the translation
D3DXMatrixMultiply(&transMatrix, &rotateMatrix, &transMatrix);
// Multiply the translation matrix by the scale
D3DXMatrixMultiply(&transMatrix, &scaleMatrix, &transMatrix);
// Transform the object into world space
device->SetTransform(D3DTS_WORLD, &transMatrix);
// Render
pModel->render(device);
}
void CSearchLamp::setSize(float Size)
{
size = Size;
}
void CSearchLamp::createSerchLights(void)
{
// Set the render states for the lights
D3DLIGHT9 spotlight;
ZeroMemory( &spotlight, sizeof(D3DLIGHT9) );
spotlight.Type = D3DLIGHT_SPOT;
D3DXVECTOR3 vDir (1.0f,-1.0f,0.0f);
D3DXVec3Normalize((D3DXVECTOR3*)&spotlight.Direction,&vDir);
spotlight.Position = D3DXVECTOR3(positionVector.x, positionVector.y,positionVector.z);
spotlight.Diffuse.r = 1.0f;
spotlight.Diffuse.g = 0.5f;
spotlight.Diffuse.b = 0.5f;
spotlight.Ambient.r = 0.5f;
spotlight.Ambient.g = 0.0f;
spotlight.Ambient.b = 0.0f;
spotlight.Range = sqrtf(FLT_MAX);
spotlight.Phi = 1.0f;
spotlight.Falloff = 0.5f;
spotlight.Theta = 0.5f;
dxMgr.pd3dDevice->SetLight(0, &spotlight );
dxMgr.pd3dDevice->LightEnable(0, TRUE );
}