Fixing bug with collisions
This commit is contained in:
parent
efad2dde3e
commit
9c39782729
@ -340,8 +340,8 @@ private:
|
|||||||
|
|
||||||
{
|
{
|
||||||
const std::vector<Eigen::Vector3f> localOffsets = {
|
const std::vector<Eigen::Vector3f> localOffsets = {
|
||||||
Eigen::Vector3f(-1.5f, 0.9f, 5.0f),
|
Eigen::Vector3f(-1.5f, 0.9f - 6.f, 5.0f),
|
||||||
Eigen::Vector3f(1.5f, 0.9f, 5.0f)
|
Eigen::Vector3f(1.5f, 0.9f - 6.f, 5.0f)
|
||||||
};
|
};
|
||||||
|
|
||||||
uint64_t now_ms = std::chrono::duration_cast<std::chrono::milliseconds>(
|
uint64_t now_ms = std::chrono::duration_cast<std::chrono::milliseconds>(
|
||||||
@ -532,7 +532,8 @@ void update_world(net::steady_timer& timer, net::io_context& ioc) {
|
|||||||
|
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> bm(g_boxes_mutex);
|
std::lock_guard<std::mutex> bm(g_boxes_mutex);
|
||||||
const float projectileHitRadius = 1.5f;
|
//const float projectileHitRadius = 1.5f;
|
||||||
|
const float projectileHitRadius = 5.0f;
|
||||||
const float boxCollisionRadius = 2.0f;
|
const float boxCollisionRadius = 2.0f;
|
||||||
|
|
||||||
std::vector<std::pair<size_t, size_t>> boxProjectileCollisions;
|
std::vector<std::pair<size_t, size_t>> boxProjectileCollisions;
|
||||||
@ -540,11 +541,12 @@ void update_world(net::steady_timer& timer, net::io_context& ioc) {
|
|||||||
for (size_t bi = 0; bi < g_serverBoxes.size(); ++bi) {
|
for (size_t bi = 0; bi < g_serverBoxes.size(); ++bi) {
|
||||||
if (g_serverBoxes[bi].destroyed) continue;
|
if (g_serverBoxes[bi].destroyed) continue;
|
||||||
|
|
||||||
Eigen::Vector3f boxWorld = g_serverBoxes[bi].position + Eigen::Vector3f(0.0f, 6.0f, 45000.0f);
|
Eigen::Vector3f boxWorld = g_serverBoxes[bi].position + Eigen::Vector3f(0.0f, 0.0f, 45000.0f);
|
||||||
|
|
||||||
for (size_t pi = 0; pi < g_projectiles.size(); ++pi) {
|
for (size_t pi = 0; pi < g_projectiles.size(); ++pi) {
|
||||||
const auto& pr = g_projectiles[pi];
|
const auto& pr = g_projectiles[pi];
|
||||||
Eigen::Vector3f diff = pr.pos - boxWorld;
|
Eigen::Vector3f diff = pr.pos - boxWorld;
|
||||||
|
//std::cout << "diff norm is " << diff.norm() << std::endl;
|
||||||
float thresh = boxCollisionRadius + projectileHitRadius;
|
float thresh = boxCollisionRadius + projectileHitRadius;
|
||||||
|
|
||||||
if (diff.squaredNorm() <= thresh * thresh) {
|
if (diff.squaredNorm() <= thresh * thresh) {
|
||||||
@ -714,6 +716,7 @@ int main() {
|
|||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lock(g_boxes_mutex);
|
std::lock_guard<std::mutex> lock(g_boxes_mutex);
|
||||||
g_serverBoxes = generateServerBoxes(50);
|
g_serverBoxes = generateServerBoxes(50);
|
||||||
|
//g_serverBoxes = generateServerBoxes(1);
|
||||||
std::cout << "Generated " << g_serverBoxes.size() << " boxes on server\n";
|
std::cout << "Generated " << g_serverBoxes.size() << " boxes on server\n";
|
||||||
}
|
}
|
||||||
net::io_context ioc;
|
net::io_context ioc;
|
||||||
|
|||||||
10
src/Game.cpp
10
src/Game.cpp
@ -582,12 +582,14 @@ namespace ZL
|
|||||||
|
|
||||||
renderer.LoadIdentity();
|
renderer.LoadIdentity();
|
||||||
renderer.TranslateMatrix({ 0,0, -1.0f * Environment::zoom });
|
renderer.TranslateMatrix({ 0,0, -1.0f * Environment::zoom });
|
||||||
|
renderer.PushMatrix();
|
||||||
renderer.TranslateMatrix({ 0, -6.f, 0 }); //Ship camera offset
|
renderer.TranslateMatrix({ 0, -6.f, 0 }); //Ship camera offset
|
||||||
|
|
||||||
if (shipAlive) {
|
if (shipAlive) {
|
||||||
glBindTexture(GL_TEXTURE_2D, spaceshipTexture->getTexID());
|
glBindTexture(GL_TEXTURE_2D, spaceshipTexture->getTexID());
|
||||||
renderer.DrawVertexRenderStruct(spaceship);
|
renderer.DrawVertexRenderStruct(spaceship);
|
||||||
}
|
}
|
||||||
|
renderer.PopMatrix();
|
||||||
glEnable(GL_BLEND);
|
glEnable(GL_BLEND);
|
||||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||||
|
|
||||||
@ -597,12 +599,14 @@ namespace ZL
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
projectileEmitter.draw(renderer, Environment::zoom, Environment::width, Environment::height);
|
||||||
|
|
||||||
if (shipAlive) {
|
if (shipAlive) {
|
||||||
renderer.PushMatrix();
|
renderer.PushMatrix();
|
||||||
renderer.TranslateMatrix({ 0, 0, 16 });
|
renderer.TranslateMatrix({ 0, 0, 16 });
|
||||||
|
renderer.TranslateMatrix({ 0, -6.f, 0 });
|
||||||
sparkEmitter.draw(renderer, Environment::zoom, Environment::width, Environment::height);
|
sparkEmitter.draw(renderer, Environment::zoom, Environment::width, Environment::height);
|
||||||
renderer.PopMatrix();
|
renderer.PopMatrix();
|
||||||
projectileEmitter.draw(renderer, Environment::zoom, Environment::width, Environment::height);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (showExplosion) {
|
if (showExplosion) {
|
||||||
@ -1320,8 +1324,8 @@ namespace ZL
|
|||||||
|
|
||||||
void Game::fireProjectiles() {
|
void Game::fireProjectiles() {
|
||||||
std::vector<Vector3f> localOffsets = {
|
std::vector<Vector3f> localOffsets = {
|
||||||
Vector3f{ -1.5f, 0.9f, 5.0f },
|
Vector3f{ -1.5f, 0.9f - 6.f, 5.0f },
|
||||||
Vector3f{ 1.5f, 0.9f, 5.0f }
|
Vector3f{ 1.5f, 0.9f - 6.f, 5.0f }
|
||||||
};
|
};
|
||||||
|
|
||||||
const float projectileSpeed = 60.0f;
|
const float projectileSpeed = 60.0f;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user