Example #1
0
void Player::DoCollision() {
	if (noclip) return;
	Vector3I up = playerUp;
	bool X, Y, Z;
	X = Y = Z = true;

	Vector3D vel = FromWorld(this->vel);

	if (Game::world->Intersects(BBox().Offset(ToWorld(vel.X())))) {
		vel.x = 0;
		X = false;
	}
	if (Game::world->Intersects(BBox().Offset(ToWorld(vel.Y())))) {
		vel.y = 0;
		Y = false;
	}
	if (Game::world->Intersects(BBox().Offset(ToWorld(vel.Z())))) {
		inAir = vel.z > 0;
		vel.z = 0;
		Z = false;
	} else {
		inAir = true;
	}

	Vector3D avel = vel.Abs();


	if (X && Y && Z && Game::world->Intersects(BBox().Offset(this->vel))) {
		if (avel.x < avel.y && avel.x < avel.z) {
			vel.x = 0;
		} else if (avel.y < avel.z) {
			vel.y = 0;
		} else {
			vel.z = 0;
		}
	} else if (X && Y && Game::world->Intersects(BBox().Offset(ToWorld(vel.XY())))) {
		if (avel.x < avel.y) {
			vel.x = 0;
		} else {
			vel.y = 0;
		}
	} else if (X && Z && Game::world->Intersects(BBox().Offset(ToWorld(vel.XZ())))) {
		if (avel.x < avel.z) {
			vel.x = 0;
		} else {
			vel.z = 0;
		}
	} else if (Y && Z && Game::world->Intersects(BBox().Offset(ToWorld(vel.YZ())))) {
		if (avel.y < avel.z) {
			vel.y = 0;
		} else {
			vel.z = 0;
		}
	}

	this->vel = ToWorld(vel);
}
Example #2
0
void Player::UpdateVelocity() {
	if (!noclip) {
		if (inAir && Game::world->GetUp(pos) == playerUp) {
			vel -= (Game::world->GetUpSmooth(pos).ToDouble() * 0.0008);
		} else {
			vel -= (Game::world->GetUp(pos).ToDouble() * 0.0008);
		}
	}

	vel += ToWorldSmooth(kvec * (inAir && !noclip ? 0.015 : 0.10));

	Vector3D vel = FromWorld(this->vel);

	vel.x *= (inAir && !noclip ? 0.99 : 0.94);
	vel.y *= (inAir && !noclip ? 0.99 : 0.94);
	vel.z *= noclip ? 0.95 : 0.999;

	this->vel = ToWorld(vel);
}
Example #3
0
void MyRenderGL::RenderSurface( const std::shared_ptr<gsurface_t> &surf ) {
    idmat4 mvpMatrix;

    mvpMatrix = m_projectionMatrix * glflipMatrix 
        * m_viewMatrix * surf.m_modelMatrix;

    surf->m_material.m_program->Bind( "mvp_matrix", mvpMatrix.Transpose() );
    surf->m_material.m_program->Bind( "model_matrix", 
            ( flipMatrix * surf.m_modelMatrix ).Transpose() );
    surf->m_material.m_program->Bind( "eye_pos", ToWorld( m_eye.ToVec3() ) );

    surf->m_material.m_program->Use();

    surf->m_material.m_texture->Bind();

    _CH(glBindVertexArray( surf->m_vao ));

    _CH(glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, surf->m_indexBuffer ));

    _CH(glDrawElements( GL_TRIANGLES, 
                surf->m_numIndices, GL_UNSIGNED_SHORT, 0 ));
}