# Lights and bounderies. ( limits)

This topic is 4112 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi! Iam creating a First Person Shooter and i have got the cameras,mouse and movement going, but i am facing two problems. 1, bounderies. I have created a mesh with a floor and three walls. i have to make the player stay inside the box and not go too far left/rigth/forward/backward. At first i thought this should be easy, just some IF here and there but it turns out that its not quite that simple, due to the rotation of the players view. How is a standard procedure for these kinds of code? Here is some sample code.
public void Rotate_View(float speed)
{
tVector3 vVector = new tVector3((mView.x - mPos.x), (mView.y - mPos.y), (mView.z - mPos.z));	// Get the view vector
mView.z = (float)(mPos.z + Math.Sin(speed) * vVector.x + Math.Cos(speed) * vVector.z);
mView.x = (float)(mPos.x + Math.Cos(speed) * vVector.x - Math.Sin(speed) * vVector.z);
}

public void StrafeCamera(float speed)
{
//tVector3 vVector = mView - mPos;	// Get the view vector
tVector3 vVector = new tVector3((mView.x - mPos.x), (mView.y - mPos.y), (mView.z - mPos.z));	// Get the view vector
tVector3 vOrthoVector = new tVector3(0, 0, 0);              // Orthogonal vector for the view vector

vOrthoVector.x = -vVector.z;
vOrthoVector.z = vVector.x;

// left negative -cameraspeed and right positive +cameraspeed.
mPos.x = mPos.x - vOrthoVector.x * speed;
mPos.z = mPos.z - vOrthoVector.z * speed;
mView.x = mView.x - vOrthoVector.x * speed;
mView.z = mView.z - vOrthoVector.z * speed;
}

public void MoveCamera(float speed)
{
tVector3 vVector = new tVector3((mView.x - mPos.x), (mView.y - mPos.y), (mView.z - mPos.z));
// forward positive camera speed and backward negative camera speed.
mPos.x  = mPos.x  + vVector.x * speed;
mPos.z  = mPos.z  + vVector.z * speed;
mView.x = mView.x + vVector.x * speed;
mView.z = mView.z + vVector.z * speed;
}

private void UpdateInputState()
{
KeyboardState k_state = d_keyboard.GetCurrentKeyboardState();
MouseState CurrentState = new MouseState();
CurrentState = d_mouse.CurrentMouseState;

mouseX = CurrentState.X;
mouseY = CurrentState.Y;

Rotate_View(-mouseX * 0.002f);
mView.y -= mouseY*0.1f;

if (k_state[Key.W])
Here i tried to set the bounderies but i don´t get it to work.
MoveCamera(0.04f);
if (k_state[Key.S])
MoveCamera(-0.04f);
if (k_state[Key.A])
StrafeCamera(-0.02f);
if (k_state[Key.D])
StrafeCamera(0.02f);
if (k_state[Key.Z])
Box.y += 1.0f;
if (k_state[Key.X])
Box.y -= 1.0f;
}

Problem nr 2, lights! With the spot light or directional light shouldent there be a way of settings the light(spot) in the same position as the player? now the light comes from outside and my box with roof will become totaly black. any suggestions? maybe these things are easy to fix but i have been coding for like 12 hours and my brain is getting tired so i think i need som guidence... EDIT: Please remember 'source' tags in future. [Edited by - jollyjeffers on July 17, 2007 5:01:05 PM]

##### Share on other sites
Quote:
 Original post by MeshboyHow is a standard procedure for these kinds of code?
You probably want to run "collision detection" through your favourite search engine. For simple primitives like you describe a sphere<->plane test might be sufficient, but collision detection (a subset of the "physics engine" realm) gets as complicated as you let it [wink]

Quote:
 Original post by MeshboyWith the spot light or directional light shouldent there be a way of settings the light(spot) in the same position as the player?
Directional lights have no position nor target, so you're wrong there. A spot light has both of these properties, but you haven't decided whether you want it from or to your player. In all cases it usually boils down to some vector mathematics - are you familiar with this, or do you have some specific questions or need guidance?

Quote:
 Original post by Meshboynow the light comes from outside and my box with roof will become totaly black.any suggestions?
Typically most rendering API's will not allow 2-sided lighting, which may well be your solution. A given triangle with a face normal (or averaged vertex normals with interpolation) faces in a given direction and the cosine law says only one side receives light energy. Without more detail I couldn't really say what you situation is, but it may well be that you need to set up 2-sided lighting and/or change the orientation of the faces you're trying to light.

hth
Jack

P.S. Nothing in here specific to DirectX so I'm moving this to 'Maths & Physics' [smile]

1. 1
Rutin
28
2. 2
3. 3
4. 4
5. 5

• 13
• 11
• 10
• 13
• 20
• ### Forum Statistics

• Total Topics
632948
• Total Posts
3009410
• ### Who's Online (See full list)

There are no registered users currently online

×