From c1b19ea1786a8443f40dd3526102ebef8ee03a7b Mon Sep 17 00:00:00 2001 From: Rtch90 Date: Thu, 12 Apr 2012 00:33:44 +0100 Subject: [PATCH 1/2] [Add] Working on AABB, trying to find the top left and bottom right of a surface. --- src/Collision/AABB.cpp | 16 +++++++++++++++- src/Collision/AABB.h | 1 + 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/Collision/AABB.cpp b/src/Collision/AABB.cpp index 0253e29..dead861 100644 --- a/src/Collision/AABB.cpp +++ b/src/Collision/AABB.cpp @@ -64,9 +64,23 @@ void AABB::CreateAABBFromSprite(const char* filename) { // Find the min, look through until we find a first instance of a white color. bool found = false; int color = 0; + DWORD* pixels = (DWORD*)screen->pixels; + for(int width = 0; width < _sprite->GetWidth(); width++) { for(int height = 0; height < _sprite->GetHeight(); height++) { - DWORD offset; + // FUCKING PAIN IN THE ASS MOTHERFUCKER!!!! + DWORD offset = height * screen->pitch + width; + if(((DWORD)pixels[offset]) != 0 && !found) { + _min = Vec2((float)width, (float)height); + found = true; + color = ((DWORD)pixels[offset]); + // Break out of these god forsaken loops. + width = _sprite->GetWidth(); + height = _sprite->GetHeight(); + } } } + + // Let's try to find the max.x now.. + _max.x = (float)_sprite->GetWidth(); } diff --git a/src/Collision/AABB.h b/src/Collision/AABB.h index 0098673..3dfb289 100644 --- a/src/Collision/AABB.h +++ b/src/Collision/AABB.h @@ -3,6 +3,7 @@ #include "../Math/Vec2.h" #include "../Sprite/Sprite.h" +#include "../Global/Globals.h" /* * The axis aligned bounding box contains From 566c2217b932dce09b7639e259929a6857a74580 Mon Sep 17 00:00:00 2001 From: Rtch90 Date: Thu, 12 Apr 2012 00:49:50 +0100 Subject: [PATCH 2/2] [Add] Frecking finished the AABB!! (I think, got to go test the thing now - But it's in.) --- src/Collision/AABB.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/Collision/AABB.cpp b/src/Collision/AABB.cpp index dead861..e4b3994 100644 --- a/src/Collision/AABB.cpp +++ b/src/Collision/AABB.cpp @@ -83,4 +83,28 @@ void AABB::CreateAABBFromSprite(const char* filename) { // Let's try to find the max.x now.. _max.x = (float)_sprite->GetWidth(); + found = false; + for(int width = (int)_min.x; width < _sprite->GetWidth(); width++) { + DWORD offset = _min.y * screen->pitch + width; + if(((DWORD)pixels[offset] != color && !found)) { + found = true; + _max.x = (float)width; + } + } + + // Now for the max.y + _max.y = (float)_sprite->GetHeight(); + found = false; + for(int height = (int)_min.y; height < _sprite->GetWidth(); height++) { + DWORD offset = (DWORD)(height * screen->pitch + _min.x); + if(((DWORD)pixels[offset]) != color && !found) { + found = true; + _max.y = (float)height; + break; + } + } + _staticMax = _max; + _staticMin = _min; + delete _sprite; + _sprite = 0; }