Add in distance-based lighting.
This commit is contained in:
parent
b0e348658c
commit
3e52016067
@ -78,48 +78,48 @@ void FaceBall::LoadLevel(int level)
|
||||
objects.push_back({ mapMesh });
|
||||
}
|
||||
|
||||
bool FaceBall::CheckCollision(vec3d movementVector){
|
||||
utils::geom2d::circle<float>newPos{ {player.GetPos().x + movementVector.x,player.GetPos().z + movementVector.z},player.GetRadius() };
|
||||
bool FaceBall::CheckCollision(vec3d movementVector,vf2d pos,float radius){
|
||||
utils::geom2d::circle<float>newPos{ {pos.x + movementVector.x,pos.y + movementVector.z},radius };
|
||||
bool collisionOccured = false;
|
||||
for (int y = -1; y <= 1; y++) {
|
||||
for (int x = -1; x <= 1; x++) {
|
||||
int offsetX = (int)player.GetPos().x + x;
|
||||
int offsetY = (int)player.GetPos().z + y;
|
||||
int offsetX = (int)pos.x + x;
|
||||
int offsetY = (int)pos.y + y;
|
||||
if (offsetX >= 0 && offsetX < MAP_SIZE.x && offsetY >= 0 && offsetY < MAP_SIZE.y) {
|
||||
MapSquare tile = map[offsetY][offsetX];
|
||||
if (tile.wallN != NULL) {
|
||||
utils::geom2d::line<float>wall{ {(float)offsetX,(float)offsetY},{(float)offsetX+1,(float)offsetY} };
|
||||
if (((int)(newPos.pos.x-player.GetRadius())==offsetX||
|
||||
(int)(newPos.pos.x + player.GetRadius()) == offsetX)
|
||||
if (((int)(newPos.pos.x-radius)==offsetX||
|
||||
(int)(newPos.pos.x + radius) == offsetX)
|
||||
&&
|
||||
newPos.pos.y > wall.start.y && wall.start.y > newPos.pos.y - player.GetRadius()) {
|
||||
newPos.pos.y > wall.start.y && wall.start.y > newPos.pos.y - radius) {
|
||||
collisionOccured = true;
|
||||
goto breakOutOfCollisionLoop;
|
||||
}
|
||||
}
|
||||
if (tile.wallE != NULL) {
|
||||
utils::geom2d::line<float>wall{ {(float)offsetX+1,(float)offsetY},{(float)offsetX + 1,(float)offsetY+1} };
|
||||
if (((int)(newPos.pos.y - player.GetRadius()) == offsetY ||
|
||||
(int)(newPos.pos.y + player.GetRadius()) == offsetY)
|
||||
&& newPos.pos.x<wall.start.x && wall.start.x < newPos.pos.x + player.GetRadius()) {
|
||||
if (((int)(newPos.pos.y - radius) == offsetY ||
|
||||
(int)(newPos.pos.y + radius) == offsetY)
|
||||
&& newPos.pos.x<wall.start.x && wall.start.x < newPos.pos.x + radius) {
|
||||
collisionOccured = true;
|
||||
goto breakOutOfCollisionLoop;
|
||||
}
|
||||
}
|
||||
if (tile.wallS != NULL) {
|
||||
utils::geom2d::line<float>wall{ {(float)offsetX,(float)offsetY+1},{(float)offsetX + 1,(float)offsetY+1} };
|
||||
if (((int)(newPos.pos.x - player.GetRadius()) == offsetX ||
|
||||
(int)(newPos.pos.x + player.GetRadius()) == offsetX)
|
||||
&& newPos.pos.y < wall.start.y && wall.start.y < newPos.pos.y + player.GetRadius()) {
|
||||
if (((int)(newPos.pos.x - radius) == offsetX ||
|
||||
(int)(newPos.pos.x + radius) == offsetX)
|
||||
&& newPos.pos.y < wall.start.y && wall.start.y < newPos.pos.y + radius) {
|
||||
collisionOccured = true;
|
||||
goto breakOutOfCollisionLoop;
|
||||
}
|
||||
}
|
||||
if (tile.wallW != NULL) {
|
||||
utils::geom2d::line<float>wall{ {(float)offsetX,(float)offsetY},{(float)offsetX,(float)offsetY + 1} };
|
||||
if (((int)(newPos.pos.y - player.GetRadius()) == offsetY ||
|
||||
(int)(newPos.pos.y + player.GetRadius()) == offsetY)
|
||||
&& newPos.pos.x > wall.start.x && wall.start.x > newPos.pos.x - player.GetRadius()) {
|
||||
if (((int)(newPos.pos.y - radius) == offsetY ||
|
||||
(int)(newPos.pos.y + radius) == offsetY)
|
||||
&& newPos.pos.x > wall.start.x && wall.start.x > newPos.pos.x - radius) {
|
||||
collisionOccured = true;
|
||||
goto breakOutOfCollisionLoop;
|
||||
}
|
||||
@ -520,6 +520,10 @@ void FaceBall::RenderWorld() {
|
||||
triViewed.uv[1] = triTransformed.uv[1];
|
||||
triViewed.uv[2] = triTransformed.uv[2];
|
||||
triViewed.col = Pixel(triTransformed.col.r * dp * dp, triTransformed.col.g * dp * dp, triTransformed.col.b * dp * dp);
|
||||
float dist = std::sqrtf(std::powf((freeRoam ? freeRoamCamera : player.GetPos()).x - tri.p[0].x, 2) + std::powf((freeRoam ? freeRoamCamera : player.GetPos()).y - tri.p[0].y, 2) + std::powf((freeRoam ? freeRoamCamera : player.GetPos()).z - tri.p[0].z, 2));
|
||||
float colorMult = dist>5*PI/3?0:std::sinf(0.3 * dist + PI / 2);
|
||||
triViewed.col = Pixel(triViewed.col.r * colorMult, triViewed.col.g * colorMult, triViewed.col.b * colorMult);
|
||||
//triViewed.col = triTransformed.col;
|
||||
|
||||
int nClippedTriangles = 0;
|
||||
Triangle clipped[2];
|
||||
@ -670,11 +674,11 @@ void FaceBall::HandleKeys(float fElapsedTime) {
|
||||
freeRoamCamera = Vector_Add(freeRoamCamera, vForward);
|
||||
}
|
||||
else {
|
||||
if (!CheckCollision({ vForward.x,0,0 })) {
|
||||
if (!CheckCollision({ vForward.x,0,0 }, {player.GetPos().x,player.GetPos().z},player.GetRadius())) {
|
||||
vec3d xMovement{ vForward.x,0,0 };
|
||||
player.UpdatePos(Vector_Add(player.GetPos(), xMovement));
|
||||
}
|
||||
if (!CheckCollision({ 0,0,vForward.z })) {
|
||||
if (!CheckCollision({ 0,0,vForward.z }, { player.GetPos().x,player.GetPos().z }, player.GetRadius())) {
|
||||
vec3d zMovement{ 0,0,vForward.z };
|
||||
player.UpdatePos(Vector_Add(player.GetPos(), zMovement));
|
||||
}
|
||||
@ -686,11 +690,11 @@ void FaceBall::HandleKeys(float fElapsedTime) {
|
||||
freeRoamCamera = Vector_Add(freeRoamCamera, vReverse);
|
||||
}
|
||||
else {
|
||||
if (!CheckCollision({ vReverse.x,0,0 })) {
|
||||
if (!CheckCollision({ vReverse.x,0,0 }, { player.GetPos().x,player.GetPos().z }, player.GetRadius())) {
|
||||
vec3d xMovement{ vReverse.x,0,0 };
|
||||
player.UpdatePos(Vector_Add(player.GetPos(), xMovement));
|
||||
}
|
||||
if (!CheckCollision({ 0,0,vReverse.z })) {
|
||||
if (!CheckCollision({ 0,0,vReverse.z }, { player.GetPos().x,player.GetPos().z }, player.GetRadius())) {
|
||||
vec3d zMovement{ 0,0,vReverse.z };
|
||||
player.UpdatePos(Vector_Add(player.GetPos(), zMovement));
|
||||
}
|
||||
|
@ -223,5 +223,5 @@ class FaceBall : public PixelGameEngine
|
||||
void OnTextEntryComplete(const std::string& sText) override;
|
||||
void InitializeEnemyData();
|
||||
void LoadLevel(int level);
|
||||
bool CheckCollision(vec3d movementVector);
|
||||
bool CheckCollision(vec3d movementVector,vf2d pos,float radius);
|
||||
};
|
Loading…
x
Reference in New Issue
Block a user