From 566c2217b932dce09b7639e259929a6857a74580 Mon Sep 17 00:00:00 2001 From: Rtch90 Date: Thu, 12 Apr 2012 00:49:50 +0100 Subject: [PATCH] [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; }