bbox.cpp

Sat, 16 Mar 2013 17:50:13 +0200

author
Santeri Piippo <crimsondusk64@gmail.com>
date
Sat, 16 Mar 2013 17:50:13 +0200
changeset 22
335e430a6b4f
parent 7
098e3c4949c6
child 26
83184d9407c7
permissions
-rw-r--r--

So much for that pointer class, caused more problems than it solved. For instance splitting a second quad after a first one had been split would trigger a peculiar crash...

#include "common.h"
#include "bbox.h"
#include "ldtypes.h"
#include "io.h"

void bbox::calculate () {
	if (!g_CurrentFile)
		return;
	
	// The bounding box, bbox for short, is the
	// box that encompasses the model we have open.
	// v0 is the minimum vertex, v1 is the maximum vertex.
	for (uint i = 0; i < g_CurrentFile->objects.size(); i++) {
		LDObject* obj = g_CurrentFile->objects[i];
		switch (obj->getType ()) {
		
		case OBJ_Line:
			{
				LDLine* line = static_cast<LDLine*> (obj);
				for (short i = 0; i < 2; ++i)
					checkVertex (line->vaCoords[i]);
			}
			break;
		
		case OBJ_Triangle:
			{
				LDTriangle* tri = static_cast<LDTriangle*> (obj);
				for (short i = 0; i < 3; ++i)
					checkVertex (tri->vaCoords[i]);
			}
			break;
		
		case OBJ_Quad:
			{
				LDQuad* quad = static_cast<LDQuad*> (obj);
				for (short i = 0; i < 4; ++i)
					checkVertex (quad->vaCoords[i]);
			}
			break;
		
		case OBJ_CondLine:
			{
				LDCondLine* line = static_cast<LDCondLine*> (obj);
				for (short i = 0; i < 2; ++i) {
					checkVertex (line->vaCoords[i]);
					checkVertex (line->vaControl[i]);
				}
			}
			break;
		
		default:
			break;
		}
	}
}

#define CHECK_DIMENSION(V,X) \
	if (V.X < v0.X) v0.X = V.X; \
	if (V.X > v1.X) v1.X = V.X;
void bbox::checkVertex (vertex v) {
	CHECK_DIMENSION (v, x)
	CHECK_DIMENSION (v, y)
	CHECK_DIMENSION (v, z)
}
#undef CHECK_DIMENSION

bbox::bbox () {
	memset (&v0, 0, sizeof v0);
	memset (&v1, 0, sizeof v1);
}

mercurial