Boxlights

This commit is contained in:
cholleme 2003-05-04 21:45:44 +00:00
parent 54617420eb
commit 81fc563d32
3 changed files with 905 additions and 342 deletions

View file

@ -86,8 +86,17 @@ Check if rectangles overlap
returns true if they overlap
*/
qboolean R_RectOverlap(screenrect_t *r1, screenrect_t *r2) {
if (r1->coords[0] > r2->coords[2]) return false;
if (r1->coords[1] > r2->coords[3]) return false;
if (r1->coords[2] < r2->coords[0]) return false;
if (r1->coords[3] < r2->coords[1]) return false;
return true;
//r1 is rightof r2
if (r1->coords[0] > r2->coords[0]) {
/*if (r1->coords[0] > r2->coords[0]) {
//overlap in x dir?
if ((r1->coords[0] - r2->coords[2]) < 0) {
//check y dir
@ -132,7 +141,7 @@ qboolean R_RectOverlap(screenrect_t *r1, screenrect_t *r2) {
} else {
return false;
}
}
}*/
}
screenrect_t *recList; //first rectangle of the list
@ -171,4 +180,293 @@ void R_AddRectList(screenrect_t *rec) {
void R_SetTotalRect() {
glScissor(totalRect.coords[0], totalRect.coords[1],
totalRect.coords[2]-totalRect.coords[0], totalRect.coords[3]-totalRect.coords[1]);
}
}
/*
Some bounding box stuff for the new boxlights support
*/
/**
Returns true if both boxes intersect
*/
aabox_t emptyBox (void) {
aabox_t result;
VectorCopy(vec3_origin, result.maxs);
VectorCopy(vec3_origin, result.mins);
return result;
}
aabox_t constructBox (vec3_t mins, vec3_t maxs) {
aabox_t result;
VectorCopy(mins, result.mins);
VectorCopy(maxs, result.maxs);
return result;
}
qboolean intersectsBox(aabox_t *b1, aabox_t *b2) {
if (b1->mins[0] > b2->maxs[0]) return false;
if (b1->mins[1] > b2->maxs[1]) return false;
if (b1->mins[2] > b2->maxs[2]) return false;
if (b1->maxs[0] < b2->mins[0]) return false;
if (b1->maxs[1] < b2->mins[1]) return false;
if (b1->maxs[2] < b2->mins[2]) return false;
return true;
}
qboolean intersectsBoxPoint(aabox_t *b1, vec3_t p) {
if (p[0] > b1->maxs[0]) return false;
if (p[1] > b1->maxs[1]) return false;
if (p[2] > b1->maxs[2]) return false;
if (p[0] < b1->mins[0]) return false;
if (p[1] < b1->mins[1]) return false;
if (p[2] < b1->mins[2]) return false;
return true;
}
qboolean intersectsMinsMaxs(aabox_t *b1, vec3_t mins, vec3_t maxs) {
if (b1->mins[0] > maxs[0]) return false;
if (b1->mins[1] > maxs[1]) return false;
if (b1->mins[2] > maxs[2]) return false;
if (b1->maxs[0] < mins[0]) return false;
if (b1->maxs[1] < mins[1]) return false;
if (b1->maxs[2] < mins[2]) return false;
return true;
}
void vmax(vec3_t i1, vec3_t i2, vec3_t r) {
r[0] = max(i1[0],i2[0]);
r[1] = max(i1[1],i2[1]);
r[2] = max(i1[2],i2[2]);
}
void vmin(vec3_t i1, vec3_t i2, vec3_t r) {
r[0] = min(i1[0],i2[0]);
r[1] = min(i1[1],i2[1]);
r[2] = min(i1[2],i2[2]);
}
aabox_t intersectBoxes(aabox_t *b1, aabox_t *b2) {
aabox_t result;
float temp;
int i;
vmax(b1->mins,b2->mins,result.mins);
vmin(b1->maxs,b2->maxs,result.maxs);
for (i=0;i<3;i++) {
if (result.mins[i]>result.maxs[i]) {
result = emptyBox();
return result;
/*
temp = result.maxs[i];
result.maxs[i] = result.mins[i];
result.mins[i] = temp;
*/
}
}
return result;
}
aabox_t addBoxes(aabox_t *b1, aabox_t *b2) {
aabox_t result;
vmin(b1->mins,b2->mins,result.mins);
vmax(b1->maxs,b2->maxs,result.maxs);
return result;
}
void boxScreenSpaceRect(aabox_t *b, int *rect);
void drawBoxWireframe(aabox_t *b) {
glBegin(GL_LINES);
//Top plane
glVertex3f(b->maxs[0],b->maxs[1],b->maxs[2]);
glVertex3f(b->mins[0],b->maxs[1],b->maxs[2]);
glVertex3f(b->maxs[0],b->maxs[1],b->maxs[2]);
glVertex3f(b->maxs[0],b->mins[1],b->maxs[2]);
glVertex3f(b->mins[0],b->mins[1],b->maxs[2]);
glVertex3f(b->mins[0],b->maxs[1],b->maxs[2]);
glVertex3f(b->mins[0],b->mins[1],b->maxs[2]);
glVertex3f(b->maxs[0],b->mins[1],b->maxs[2]);
//Bottom plane
glVertex3f(b->maxs[0],b->maxs[1],b->mins[2]);
glVertex3f(b->mins[0],b->maxs[1],b->mins[2]);
glVertex3f(b->maxs[0],b->maxs[1],b->mins[2]);
glVertex3f(b->maxs[0],b->mins[1],b->mins[2]);
glVertex3f(b->mins[0],b->mins[1],b->mins[2]);
glVertex3f(b->mins[0],b->maxs[1],b->mins[2]);
glVertex3f(b->mins[0],b->mins[1],b->mins[2]);
glVertex3f(b->maxs[0],b->mins[1],b->mins[2]);
//Sides
glVertex3f(b->mins[0],b->maxs[1],b->mins[2]);
glVertex3f(b->mins[0],b->maxs[1],b->maxs[2]);
glVertex3f(b->maxs[0],b->maxs[1],b->mins[2]);
glVertex3f(b->maxs[0],b->maxs[1],b->maxs[2]);
glVertex3f(b->mins[0],b->mins[1],b->mins[2]);
glVertex3f(b->mins[0],b->mins[1],b->maxs[2]);
glVertex3f(b->maxs[0],b->mins[1],b->mins[2]);
glVertex3f(b->maxs[0],b->mins[1],b->maxs[2]);
glEnd();
}
void IntersectRayPlane(vec3_t v1, vec3_t v2, plane_t *plane, vec3_t res) {
vec3_t v;
float sect;
VectorSubtract (v1, v2, v);
sect = -(DotProduct (plane->normal, v1)-plane->dist) / DotProduct (plane->normal, v);
VectorScale (v,sect,v);
VectorAdd (v1, v, res);
}
void addPoint(matrix_4x4 modelviewproj, vec3_t v1, int *rect) {
matrix_1x4 point, res;
float px, py;
point[0] = v1[0];
point[1] = v1[1];
point[2] = v1[2];
point[3] = 1.0f;
Mat_Mul_1x4_4x4(point, modelviewproj, res);
px = (res[0]*(1/res[3])+1.0) * 0.5;
py = (res[1]*(1/res[3])+1.0) * 0.5;
px = px * r_Iviewport[2] + r_Iviewport[0];
py = py * r_Iviewport[3] + r_Iviewport[1];
if (px > rect[2]) rect[2] = (int)px;
if (px < rect[0]) rect[0] = (int)px;
if (py > rect[3]) rect[3] = (int)py;
if (py < rect[1]) rect[1] = (int)py;
}
void addEdge(matrix_4x4 modelviewproj, vec3_t v1, vec3_t v2, int *rect) {
vec3_t intersect;
plane_t plane;
qboolean side1, side2;
plane.normal[0] = vpn[0];
plane.normal[1] = vpn[1];
plane.normal[2] = vpn[2];
plane.dist = DotProduct(r_refdef.vieworg,vpn) + 5.0;
//Check edge to frustrum near plane
side1 = ((DotProduct(plane.normal, v1) - plane.dist) >= 0.0);
side2 = ((DotProduct(plane.normal, v2) - plane.dist) >= 0.0);
if (!side1 && !side2) return; //edge behind near plane
if (!side1 || !side2)
IntersectRayPlane(v1,v2,&plane,intersect);
if (!side1) {
VectorCopy(intersect,v1);
} else if (!side2) {
VectorCopy(intersect,v2);
}
addPoint(modelviewproj, v1, rect);
addPoint(modelviewproj, v2, rect);
}
/**
Recturns the screen space rectangle taken by the box.
(Clips the box to the near plane to have correct results even if the box intersects the near plane)
*/
void boxScreenSpaceRect(aabox_t *b, int *rect) {
matrix_4x4 modelviewproj, world, proj;
vec3_t v1, v2;
glGetFloatv (GL_MODELVIEW_MATRIX, &world[0][0]);
glGetFloatv (GL_PROJECTION_MATRIX, &proj[0][0]);
Mat_Mul_4x4_4x4(world, proj, modelviewproj);
rect[0] = 100000000;
rect[1] = 100000000;
rect[2] = -100000000;
rect[3] = -100000000;
VectorConstruct(b->maxs[0],b->maxs[1],b->maxs[2],v1);
VectorConstruct(b->mins[0],b->maxs[1],b->maxs[2],v2);
addEdge(modelviewproj, v1, v2, rect);
VectorConstruct(b->maxs[0],b->maxs[1],b->maxs[2],v1);
VectorConstruct(b->maxs[0],b->mins[1],b->maxs[2],v2);
addEdge(modelviewproj, v1, v2, rect);
VectorConstruct(b->mins[0],b->mins[1],b->maxs[2],v1);
VectorConstruct(b->mins[0],b->maxs[1],b->maxs[2],v2);
addEdge(modelviewproj, v1, v2, rect);
VectorConstruct(b->mins[0],b->mins[1],b->maxs[2],v1);
VectorConstruct(b->maxs[0],b->mins[1],b->maxs[2],v2);
addEdge(modelviewproj, v1, v2, rect);
//Bottom plane
VectorConstruct(b->maxs[0],b->maxs[1],b->mins[2],v1);
VectorConstruct(b->mins[0],b->maxs[1],b->mins[2],v2);
addEdge(modelviewproj, v1, v2, rect);
VectorConstruct(b->maxs[0],b->maxs[1],b->mins[2],v1);
VectorConstruct(b->maxs[0],b->mins[1],b->mins[2],v2);
addEdge(modelviewproj, v1, v2, rect);
VectorConstruct(b->mins[0],b->mins[1],b->mins[2],v1);
VectorConstruct(b->mins[0],b->maxs[1],b->mins[2],v2);
addEdge(modelviewproj, v1, v2, rect);
VectorConstruct(b->mins[0],b->mins[1],b->mins[2],v1);
VectorConstruct(b->maxs[0],b->mins[1],b->mins[2],v2);
addEdge(modelviewproj, v1, v2, rect);
//Sides
VectorConstruct(b->mins[0],b->maxs[1],b->mins[2],v1);
VectorConstruct(b->mins[0],b->maxs[1],b->maxs[2],v2);
addEdge(modelviewproj, v1, v2, rect);
VectorConstruct(b->maxs[0],b->maxs[1],b->mins[2],v1);
VectorConstruct(b->maxs[0],b->maxs[1],b->maxs[2],v2);
addEdge(modelviewproj, v1, v2, rect);
VectorConstruct(b->mins[0],b->mins[1],b->mins[2],v1);
VectorConstruct(b->mins[0],b->mins[1],b->maxs[2],v2);
addEdge(modelviewproj, v1, v2, rect);
VectorConstruct(b->maxs[0],b->mins[1],b->mins[2],v1);
VectorConstruct(b->maxs[0],b->mins[1],b->maxs[2],v2);
addEdge(modelviewproj, v1, v2, rect);
}

File diff suppressed because it is too large Load diff

View file

@ -1,3 +1,3 @@
void R_InitDrawWorld (void)
void R_DrawWorldAmbient (void)
//void R_DrawWorldAmbient (void)
void R_WorldMultiplyTextures(void)