2005-08-26 22:49:36 +00:00
|
|
|
#include "quakedef.h"
|
2007-05-25 22:16:29 +00:00
|
|
|
|
2005-08-26 22:49:36 +00:00
|
|
|
#if defined(TERRAIN) && !defined(SERVERONLY) //fixme
|
2009-11-04 21:16:50 +00:00
|
|
|
#ifdef GLQUAKE
|
2005-08-26 22:49:36 +00:00
|
|
|
#include "glquake.h"
|
2007-05-25 22:16:29 +00:00
|
|
|
#endif
|
2009-11-04 21:16:50 +00:00
|
|
|
#include "shader.h"
|
2005-08-26 22:49:36 +00:00
|
|
|
|
|
|
|
//heightmaps work thusly:
|
|
|
|
//there is one raw heightmap file
|
|
|
|
//the file is split to 4*4 sections.
|
|
|
|
//each section is textured independantly (remember banshees are capped at 512 pixels)
|
|
|
|
//there's a detailtexture blended over the top to fake the detail.
|
|
|
|
//it's built into 16 seperate display lists, these display lists are individually culled, but the drivers are expected to optimise them too.
|
|
|
|
//Tei claims 14x speedup with a single display list. hopefully we can achieve the same speed by culling per-texture.
|
|
|
|
//we get 20->130
|
2006-03-06 01:41:09 +00:00
|
|
|
//perhaps we should build it with multitexture? (no - slower on ati)
|
2005-08-26 22:49:36 +00:00
|
|
|
|
|
|
|
#define SECTIONS 8
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
char path[MAX_QPATH];
|
2011-05-20 04:10:46 +00:00
|
|
|
char hmapname[MAX_QPATH];
|
2005-08-26 22:49:36 +00:00
|
|
|
unsigned short *heights;
|
|
|
|
int terrainsize;
|
|
|
|
float terrainscale;
|
|
|
|
float heightscale;
|
|
|
|
int numsegs;
|
2009-11-04 21:16:50 +00:00
|
|
|
texid_t detailtexture;
|
|
|
|
texid_t textures[SECTIONS*SECTIONS];
|
2005-08-26 22:49:36 +00:00
|
|
|
int displaylist[SECTIONS*SECTIONS]; //display lists are famous for being stupidly fast with heightmaps.
|
|
|
|
unsigned short mins[SECTIONS*SECTIONS], maxs[SECTIONS*SECTIONS];
|
2011-05-20 04:10:46 +00:00
|
|
|
|
|
|
|
shader_t *skyshader;
|
|
|
|
shader_t *shader;
|
|
|
|
mesh_t mesh[SECTIONS*SECTIONS];
|
|
|
|
mesh_t *amesh[SECTIONS*SECTIONS];
|
|
|
|
mesh_t skymesh;
|
|
|
|
mesh_t *askymesh;
|
|
|
|
|
|
|
|
qboolean modified[SECTIONS*SECTIONS];
|
2005-08-26 22:49:36 +00:00
|
|
|
} heightmap_t;
|
|
|
|
|
|
|
|
#define DISPLISTS
|
2006-03-06 01:41:09 +00:00
|
|
|
//#define MULTITEXTURE //ATI suck. I don't know about anyone else (this goes at 1/5th the speed).
|
2005-08-26 22:49:36 +00:00
|
|
|
|
2011-05-20 04:10:46 +00:00
|
|
|
void GL_DrawHeightmapModel (batch_t **batches, entity_t *e)
|
2005-08-26 22:49:36 +00:00
|
|
|
{
|
|
|
|
//a 512*512 heightmap
|
|
|
|
//will draw 2 tris per square, drawn twice for detail
|
|
|
|
//so a million triangles per frame if the whole thing is visible.
|
|
|
|
|
|
|
|
//with 130 to 180fps, display lists rule!
|
2011-05-20 04:10:46 +00:00
|
|
|
int x, y, vx, vy, v;
|
2005-08-26 22:49:36 +00:00
|
|
|
float subsize;
|
|
|
|
int minx, miny;
|
|
|
|
vec3_t mins, maxs;
|
|
|
|
model_t *m = e->model;
|
|
|
|
heightmap_t *hm = m->terrain;
|
2011-05-20 04:10:46 +00:00
|
|
|
mesh_t *mesh;
|
|
|
|
batch_t *b;
|
2005-08-26 22:49:36 +00:00
|
|
|
|
2005-10-15 20:06:34 +00:00
|
|
|
if (e->model == cl.worldmodel)
|
|
|
|
{
|
2011-05-20 04:10:46 +00:00
|
|
|
b = BE_GetTempBatch();
|
|
|
|
if (b)
|
|
|
|
{
|
|
|
|
b->ent = e;
|
|
|
|
b->shader = hm->skyshader;
|
|
|
|
b->flags = 0;
|
|
|
|
b->mesh = &hm->askymesh;
|
|
|
|
b->mesh[0] = &hm->skymesh;
|
|
|
|
b->meshes = 1;
|
|
|
|
b->buildmeshes = NULL;
|
|
|
|
b->skin = &b->shader->defaulttextures;
|
|
|
|
b->texture = NULL;
|
|
|
|
// vbo = b->vbo = hm->vbo[x+y*SECTIONS];
|
|
|
|
b->vbo = NULL;
|
|
|
|
|
|
|
|
b->next = batches[b->shader->sort];
|
|
|
|
batches[b->shader->sort] = b;
|
|
|
|
}
|
2005-10-15 20:06:34 +00:00
|
|
|
}
|
|
|
|
|
2011-05-20 04:10:46 +00:00
|
|
|
subsize = hm->terrainsize/SECTIONS;
|
2005-08-26 22:49:36 +00:00
|
|
|
for (x = 0; x < hm->numsegs; x++)
|
|
|
|
{
|
2011-05-20 04:10:46 +00:00
|
|
|
mins[0] = (x+0)*subsize*hm->terrainscale;
|
|
|
|
maxs[0] = (x+1)*subsize*hm->terrainscale;
|
2005-08-26 22:49:36 +00:00
|
|
|
for (y = 0; y < hm->numsegs; y++)
|
|
|
|
{
|
2011-05-20 04:10:46 +00:00
|
|
|
mins[1] = (y+0)*subsize*hm->terrainscale;
|
|
|
|
maxs[1] = (y+1)*subsize*hm->terrainscale;
|
2005-08-26 22:49:36 +00:00
|
|
|
|
2011-05-20 04:10:46 +00:00
|
|
|
mesh = &hm->mesh[x+y*SECTIONS];
|
|
|
|
if (hm->modified[x+y*SECTIONS])
|
2005-08-26 22:49:36 +00:00
|
|
|
{
|
2011-05-20 04:10:46 +00:00
|
|
|
minx = x*subsize;
|
|
|
|
miny = y*subsize;
|
|
|
|
|
|
|
|
hm->modified[x+y*SECTIONS] = false;
|
|
|
|
|
|
|
|
hm->mins[x+y*SECTIONS] = 65536 * hm->heightscale;
|
|
|
|
hm->maxs[x+y*SECTIONS] = 0;
|
|
|
|
|
|
|
|
if (!mesh->xyz_array)
|
|
|
|
mesh->xyz_array = BZ_Malloc(sizeof(vecV_t) * (subsize+1)*(subsize+1));
|
|
|
|
if (!mesh->st_array)
|
|
|
|
mesh->st_array = BZ_Malloc(sizeof(vec2_t) * (subsize+1)*(subsize+1));
|
|
|
|
if (!mesh->lmst_array)
|
|
|
|
mesh->lmst_array = BZ_Malloc(sizeof(vec2_t) * (subsize+1)*(subsize+1));
|
|
|
|
mesh->numvertexes = 0;
|
|
|
|
/*64 quads across requires 65 verticies*/
|
|
|
|
for (vx = 0; vx <= subsize; vx++)
|
2005-08-26 22:49:36 +00:00
|
|
|
{
|
2011-05-20 04:10:46 +00:00
|
|
|
for (vy = 0; vy <= subsize; vy++)
|
|
|
|
{
|
|
|
|
v = mesh->numvertexes++;
|
|
|
|
mesh->xyz_array[v][0] = (vx+minx)*hm->terrainscale;
|
|
|
|
mesh->xyz_array[v][1] = (vy+miny)*hm->terrainscale;
|
|
|
|
mesh->xyz_array[v][2] = hm->heights[(vx+minx) + (vy+miny)*hm->terrainsize]*hm->heightscale;
|
2005-08-26 22:49:36 +00:00
|
|
|
|
2011-05-20 04:10:46 +00:00
|
|
|
if (hm->maxs[x+y*SECTIONS] < mesh->xyz_array[v][2])
|
|
|
|
hm->maxs[x+y*SECTIONS] = mesh->xyz_array[v][2];
|
|
|
|
if (hm->mins[x+y*SECTIONS] > mesh->xyz_array[v][2])
|
|
|
|
hm->mins[x+y*SECTIONS] = mesh->xyz_array[v][2];
|
2005-08-26 22:49:36 +00:00
|
|
|
|
2011-05-20 04:10:46 +00:00
|
|
|
mesh->st_array[v][0] = mesh->xyz_array[v][0] / 64;
|
|
|
|
mesh->st_array[v][1] = mesh->xyz_array[v][1] / 64;
|
2005-09-09 23:40:55 +00:00
|
|
|
|
2011-05-20 04:10:46 +00:00
|
|
|
mesh->lmst_array[v][0] = mesh->xyz_array[v][0] / 64;
|
|
|
|
mesh->lmst_array[v][1] = mesh->xyz_array[v][1] / 64;
|
2005-08-26 22:49:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-20 04:10:46 +00:00
|
|
|
if (!mesh->indexes)
|
|
|
|
mesh->indexes = BZ_Malloc(sizeof(index_t) * subsize*subsize*6);
|
2005-08-26 22:49:36 +00:00
|
|
|
|
2011-05-20 04:10:46 +00:00
|
|
|
mesh->numindexes = 0;
|
|
|
|
for (vx = 0; vx < subsize; vx++)
|
|
|
|
{
|
|
|
|
for (vy = 0; vy < subsize; vy++)
|
2005-08-26 22:49:36 +00:00
|
|
|
{
|
2011-05-20 04:10:46 +00:00
|
|
|
v = vx + vy*(subsize+1);
|
|
|
|
mesh->indexes[mesh->numindexes++] = v+0;
|
|
|
|
mesh->indexes[mesh->numindexes++] = v+1;
|
|
|
|
mesh->indexes[mesh->numindexes++] = v+subsize+1;
|
|
|
|
mesh->indexes[mesh->numindexes++] = v+1;
|
|
|
|
mesh->indexes[mesh->numindexes++] = v+1+subsize+1;
|
|
|
|
mesh->indexes[mesh->numindexes++] = v+subsize+1;
|
2005-08-26 22:49:36 +00:00
|
|
|
}
|
|
|
|
}
|
2011-05-20 04:10:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
//GL_BuildVBO();
|
2005-08-26 22:49:36 +00:00
|
|
|
}
|
2011-05-20 04:10:46 +00:00
|
|
|
|
|
|
|
mins[2] = hm->mins[x+y*SECTIONS];
|
|
|
|
maxs[2] = hm->maxs[x+y*SECTIONS];
|
|
|
|
|
|
|
|
if (!BoundsIntersect(mins, maxs, r_refdef.vieworg, r_refdef.vieworg))
|
|
|
|
if (R_CullBox(mins, maxs))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
b = BE_GetTempBatch();
|
|
|
|
if (!b)
|
|
|
|
continue;
|
|
|
|
b->ent = e;
|
|
|
|
b->shader = hm->shader;
|
|
|
|
b->flags = 0;
|
|
|
|
b->mesh = &hm->amesh[x+y*SECTIONS];
|
|
|
|
b->mesh[0] = mesh;
|
|
|
|
b->meshes = 1;
|
|
|
|
b->buildmeshes = NULL;
|
|
|
|
b->skin = &b->shader->defaulttextures;
|
|
|
|
b->texture = NULL;
|
|
|
|
// vbo = b->vbo = hm->vbo[x+y*SECTIONS];
|
|
|
|
b->vbo = NULL;
|
|
|
|
|
|
|
|
b->next = batches[b->shader->sort];
|
|
|
|
batches[b->shader->sort] = b;
|
2005-08-26 22:49:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-05-25 22:16:29 +00:00
|
|
|
|
2006-03-04 20:43:48 +00:00
|
|
|
unsigned int Heightmap_PointContentsHM(heightmap_t *hm, float clipmipsz, vec3_t org)
|
2005-08-26 22:49:36 +00:00
|
|
|
{
|
|
|
|
float x, y;
|
|
|
|
float z, tz;
|
|
|
|
int sx, sy;
|
|
|
|
|
|
|
|
x = org[0]/hm->terrainscale;
|
|
|
|
y = org[1]/hm->terrainscale;
|
|
|
|
z = (org[2]+clipmipsz)/hm->heightscale;
|
|
|
|
|
|
|
|
if (z < 0)
|
|
|
|
return FTECONTENTS_SOLID;
|
|
|
|
if (z > 65535)
|
|
|
|
{
|
|
|
|
if (z > 65535+64 || clipmipsz) //top 64 units are sky
|
|
|
|
return FTECONTENTS_SOLID;
|
|
|
|
else
|
|
|
|
return FTECONTENTS_SKY;
|
|
|
|
}
|
|
|
|
if (x < 0)
|
|
|
|
{
|
|
|
|
if (x <= -1 || clipmipsz)
|
|
|
|
return FTECONTENTS_SOLID;
|
|
|
|
else
|
|
|
|
return FTECONTENTS_SKY;
|
|
|
|
}
|
|
|
|
if (y < 0)
|
|
|
|
{
|
|
|
|
if (x <= -1 || clipmipsz)
|
|
|
|
return FTECONTENTS_SOLID;
|
|
|
|
else
|
|
|
|
return FTECONTENTS_SKY;
|
|
|
|
}
|
|
|
|
if (x >= hm->terrainsize-1)
|
|
|
|
{
|
|
|
|
if (x >= hm->terrainsize || clipmipsz)
|
|
|
|
return FTECONTENTS_SOLID;
|
|
|
|
else
|
|
|
|
return FTECONTENTS_SKY;
|
|
|
|
}
|
|
|
|
if (y >= hm->terrainsize-1)
|
|
|
|
{
|
|
|
|
if (y >= hm->terrainsize || clipmipsz)
|
|
|
|
return FTECONTENTS_SOLID;
|
|
|
|
else
|
|
|
|
return FTECONTENTS_SKY;
|
|
|
|
}
|
|
|
|
|
|
|
|
sx = x; x-=sx;
|
|
|
|
sy = y; y-=sy;
|
|
|
|
|
|
|
|
//made of two triangles:
|
|
|
|
#if 1
|
|
|
|
if (x+y>1) //the 1, 1 triangle
|
|
|
|
{
|
|
|
|
float v1, v2, v3;
|
|
|
|
v3 = 1-y;
|
|
|
|
v2 = x+y-1;
|
|
|
|
v1 = 1-x;
|
|
|
|
//0, 1
|
|
|
|
//1, 1
|
|
|
|
//1, 0
|
|
|
|
tz = (hm->heights[(sx+0)+(sy+1)*hm->terrainsize]*v1 +
|
|
|
|
hm->heights[(sx+1)+(sy+1)*hm->terrainsize]*v2 +
|
|
|
|
hm->heights[(sx+1)+(sy+0)*hm->terrainsize]*v3);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
float v1, v2, v3;
|
|
|
|
v1 = y;
|
|
|
|
v2 = x;
|
|
|
|
v3 = 1-y-x;
|
|
|
|
|
|
|
|
//0, 1
|
|
|
|
//1, 0
|
|
|
|
//0, 0
|
|
|
|
tz = (hm->heights[(sx+0)+(sy+1)*hm->terrainsize]*v1 +
|
|
|
|
hm->heights[(sx+1)+(sy+0)*hm->terrainsize]*v2 +
|
|
|
|
hm->heights[(sx+0)+(sy+0)*hm->terrainsize]*v3);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
{
|
|
|
|
float t, b;
|
|
|
|
//square?
|
|
|
|
//:(
|
|
|
|
|
|
|
|
t = (hm->heights[sx+sy*hm->terrainsize]*(1-x) + hm->heights[sx+1+sy*hm->terrainsize]*x);
|
|
|
|
b = (hm->heights[sx+(sy+1)*hm->terrainsize]*(1-x) + hm->heights[sx+1+(sy+1)*hm->terrainsize]*x);
|
|
|
|
tz = t*(1-y) + b*y;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
if (z <= tz)
|
|
|
|
return FTECONTENTS_SOLID; //contained within
|
|
|
|
return FTECONTENTS_EMPTY;
|
|
|
|
}
|
|
|
|
|
2010-08-28 17:14:38 +00:00
|
|
|
unsigned int Heightmap_PointContents(model_t *model, vec3_t axis[3], vec3_t org)
|
2005-08-26 22:49:36 +00:00
|
|
|
{
|
|
|
|
heightmap_t *hm = model->terrain;
|
|
|
|
return Heightmap_PointContentsHM(hm, 0, org);
|
|
|
|
}
|
2010-08-28 17:14:38 +00:00
|
|
|
unsigned int Heightmap_NativeBoxContents(model_t *model, int hulloverride, int frame, vec3_t axis[3], vec3_t org, vec3_t mins, vec3_t maxs)
|
2006-03-06 01:41:09 +00:00
|
|
|
{
|
|
|
|
heightmap_t *hm = model->terrain;
|
|
|
|
return Heightmap_PointContentsHM(hm, mins[2], org);
|
|
|
|
}
|
2005-08-26 22:49:36 +00:00
|
|
|
|
2005-09-21 01:21:35 +00:00
|
|
|
void Heightmap_Normal(heightmap_t *hm, vec3_t org, vec3_t norm)
|
2005-08-26 22:49:36 +00:00
|
|
|
{
|
|
|
|
float x, y;
|
2005-09-21 01:21:35 +00:00
|
|
|
float z;
|
2005-08-26 22:49:36 +00:00
|
|
|
int sx, sy;
|
2011-05-20 04:10:46 +00:00
|
|
|
vec3_t d1, d2;
|
2005-08-26 22:49:36 +00:00
|
|
|
|
|
|
|
x = org[0]/hm->terrainscale;
|
|
|
|
y = org[1]/hm->terrainscale;
|
|
|
|
z = org[2];
|
|
|
|
|
|
|
|
sx = x; x-=sx;
|
|
|
|
sy = y; y-=sy;
|
|
|
|
|
|
|
|
if (x+y>1) //the 1, 1 triangle
|
|
|
|
{
|
|
|
|
//0, 1
|
|
|
|
//1, 1
|
|
|
|
//1, 0
|
2011-05-20 04:10:46 +00:00
|
|
|
d1[0] = hm->terrainscale;
|
|
|
|
d1[1] = 0;
|
|
|
|
d1[2] = hm->heights[(sx+1)+(sy+1)*hm->terrainsize] - hm->heights[(sx+0)+(sy+1)*hm->terrainsize];
|
|
|
|
d2[0] = 0;
|
|
|
|
d2[1] = hm->terrainscale;
|
|
|
|
d2[2] = hm->heights[(sx+1)+(sy+1)*hm->terrainsize] - hm->heights[(sx+1)+(sy+0)*hm->terrainsize];
|
2005-08-26 22:49:36 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//0, 1
|
|
|
|
//1, 0
|
|
|
|
//0, 0
|
2011-05-20 04:10:46 +00:00
|
|
|
d1[0] = hm->terrainscale;
|
|
|
|
d1[1] = 0;
|
|
|
|
d1[2] = hm->heights[(sx+0)+(sy+1)*hm->terrainsize] - hm->heights[(sx+0)+(sy+0)*hm->terrainsize];
|
|
|
|
d2[0] = 0;
|
|
|
|
d2[1] = hm->terrainscale;
|
|
|
|
d2[2] = hm->heights[(sx+1)+(sy+0)*hm->terrainsize] - hm->heights[(sx+0)+(sy+0)*hm->terrainsize];
|
2005-08-26 22:49:36 +00:00
|
|
|
}
|
|
|
|
|
2011-05-20 04:10:46 +00:00
|
|
|
CrossProduct(d1, d2, norm);
|
2005-08-26 22:49:36 +00:00
|
|
|
VectorNormalize(norm);
|
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
typedef struct {
|
|
|
|
vec3_t start;
|
|
|
|
vec3_t end;
|
|
|
|
vec3_t mins;
|
|
|
|
vec3_t maxs;
|
|
|
|
vec3_t impact;
|
|
|
|
heightmap_t *hm;
|
|
|
|
int contents;
|
|
|
|
} hmtrace_t;
|
|
|
|
#define Closestf(res,n,min,max) res = ((n>0)?min:max)
|
|
|
|
#define Closest(res,n,min,max) Closestf(res[0],n[0],min[0],max[0]);Closestf(res[1],n[1],min[1],max[1]);Closestf(res[2],n[2],min[2],max[2])
|
|
|
|
void Heightmap_Trace_Square(hmtrace_t *tr, int sx, int sy)
|
|
|
|
{
|
|
|
|
float normf = 0.70710678118654752440084436210485;
|
|
|
|
float pd, sd, ed, bd;
|
|
|
|
int tris, x, y;
|
|
|
|
vec3_t closest;
|
|
|
|
vec3_t point;
|
|
|
|
|
|
|
|
pd = normf*(x+y);
|
|
|
|
sd = normf*tr->start[0]+normf*tr->start[1];
|
|
|
|
ed = normf*tr->end[0]+normf*tr->end[1];
|
|
|
|
bd = normf*tr->maxs[0]+normf*tr->maxs[1]; //assume mins is this but negative
|
|
|
|
//see which of the two triangles in the square it travels over.
|
|
|
|
|
|
|
|
tris = sd<=pd || ed<=pd;
|
|
|
|
if (sd>=pd || ed>=pd)
|
|
|
|
tris |= 2;
|
|
|
|
|
|
|
|
point[0] = sx+1;
|
|
|
|
point[1] = sy;
|
|
|
|
point[2] = tr->hm->heights[sx+1+sy*tr->hm->terrainsize];
|
|
|
|
|
|
|
|
if (tris & 1)
|
|
|
|
{ //triangle with 0, 0
|
|
|
|
vec3_t norm;
|
|
|
|
float d1, d2, dc;
|
|
|
|
|
|
|
|
x = tr->hm->heights[(sx+1)+(sy+0)*tr->hm->terrainsize] - tr->hm->heights[(sx+0)+(sy+0)*tr->hm->terrainsize];
|
|
|
|
y = tr->hm->heights[(sx+0)+(sy+1)*tr->hm->terrainsize] - tr->hm->heights[(sx+0)+(sy+0)*tr->hm->terrainsize];
|
|
|
|
|
|
|
|
norm[0] = (-x*tr->hm->heightscale)/tr->hm->terrainscale;
|
|
|
|
norm[1] = (-y*tr->hm->heightscale)/tr->hm->terrainscale;
|
|
|
|
norm[2] = 1.0f/(float)sqrt(norm[0]*norm[0] + norm[1]*norm[1] + 1);
|
|
|
|
Closest(closest, norm, tr->mins, tr->maxs);
|
|
|
|
dc = DotProduct(norm, closest) - DotProduct(norm, point);
|
|
|
|
d1 = DotProduct(norm, tr->start) + dc;
|
|
|
|
d2 = DotProduct(norm, tr->end) + dc;
|
|
|
|
|
|
|
|
if (d1>=0 && d2<=0)
|
|
|
|
{ //intersects
|
|
|
|
tr->contents = FTECONTENTS_SOLID;
|
|
|
|
|
|
|
|
d1 = (d1-d2)/(d1+d2);
|
|
|
|
d2 = 1-d1;
|
|
|
|
|
|
|
|
tr->impact[0] = tr->end[0]*d1+tr->start[0]*d2;
|
|
|
|
tr->impact[1] = tr->end[1]*d1+tr->start[1]*d2;
|
|
|
|
tr->impact[2] = tr->end[2]*d1+tr->start[2]*d2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (tris & 2)
|
|
|
|
{ //triangle with 1, 1
|
|
|
|
vec3_t norm;
|
|
|
|
float d1, d2, dc;
|
|
|
|
norm[0] = (-x*tr->hm->heightscale)/tr->hm->terrainscale;
|
|
|
|
norm[1] = (-y*tr->hm->heightscale)/tr->hm->terrainscale;
|
|
|
|
norm[2] = 1.0f/(float)sqrt(norm[0]*norm[0] + norm[1]*norm[1] + 1);
|
|
|
|
Closest(closest, norm, tr->mins, tr->maxs);
|
|
|
|
dc = DotProduct(norm, closest) - DotProduct(norm, point);
|
|
|
|
d1 = DotProduct(norm, tr->start) + dc;
|
|
|
|
d2 = DotProduct(norm, tr->end) + dc;
|
|
|
|
|
|
|
|
if (d1>=0 && d2<=0)
|
|
|
|
{ //intersects
|
|
|
|
tr->contents = FTECONTENTS_SOLID;
|
|
|
|
|
|
|
|
d1 = (d1-d2)/(d1+d2);
|
|
|
|
d2 = 1-d1;
|
|
|
|
|
|
|
|
tr->impact[0] = tr->end[0]*d1+tr->start[0]*d2;
|
|
|
|
tr->impact[1] = tr->end[1]*d1+tr->start[1]*d2;
|
|
|
|
tr->impact[2] = tr->end[2]*d1+tr->start[2]*d2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void Heightmap_Trace_Y(hmtrace_t *tr, int x, int min, int max)
|
|
|
|
{
|
|
|
|
int mid;
|
|
|
|
if (min == max)
|
|
|
|
{ //end
|
|
|
|
Heightmap_Trace_Square(tr, x, min);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mid = ((max-min)>>1)+min;
|
|
|
|
if (tr->start[1] < min+tr->mins[1] && tr->end[1] < min+tr->mins[1])
|
|
|
|
{ //both on one size.
|
|
|
|
Heightmap_Trace_Y(tr, x, min, mid);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (tr->start[1] > max+tr->maxs[1] && tr->end[1] > max+tr->maxs[1])
|
|
|
|
{ //both on one size.
|
|
|
|
Heightmap_Trace_Y(tr, x, mid, max);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
//crosses this line.
|
|
|
|
if (tr->start[1] > tr->end[1])
|
|
|
|
{
|
|
|
|
Heightmap_Trace_Y(tr, x, min, mid);
|
|
|
|
if (!tr->contents)
|
|
|
|
Heightmap_Trace_Y(tr, x, mid, max);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Heightmap_Trace_Y(tr, x, mid, max);
|
|
|
|
if (!tr->contents)
|
|
|
|
Heightmap_Trace_Y(tr, x, min, mid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void Heightmap_Trace_X(hmtrace_t *tr, int min, int max)
|
|
|
|
{
|
|
|
|
int mid;
|
|
|
|
if (min == max)
|
|
|
|
{ //end
|
|
|
|
//FIXME: we don't have to check ALL squares like this, we could use a much smaller range.
|
|
|
|
Heightmap_Trace_Y(tr, min, 0, tr->hm->terrainsize);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mid = ((max-min)>>1)+min;
|
|
|
|
if (tr->start[0] < min+tr->mins[0] && tr->end[0] < min+tr->mins[0])
|
|
|
|
{ //both on one size.
|
|
|
|
Heightmap_Trace_X(tr, min, mid);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (tr->start[0] > max+tr->maxs[0] && tr->end[0] > max+tr->maxs[0])
|
|
|
|
{ //both on one size.
|
|
|
|
Heightmap_Trace_X(tr, mid, max);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
//crosses this line.
|
|
|
|
if (tr->start[0] > tr->end[0])
|
|
|
|
{
|
|
|
|
Heightmap_Trace_X(tr, min, mid);
|
|
|
|
if (!tr->contents)
|
|
|
|
Heightmap_Trace_X(tr, mid, max);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Heightmap_Trace_X(tr, mid, max);
|
|
|
|
if (!tr->contents)
|
|
|
|
Heightmap_Trace_X(tr, min, mid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
Heightmap_TraceRecurse
|
|
|
|
Traces an arbitary box through a heightmap. (interface with outside)
|
|
|
|
|
|
|
|
Why is recursion good?
|
|
|
|
1: it is consistant with bsp models. :)
|
|
|
|
2: it allows us to use any size model we want
|
|
|
|
3: we don't have to work out the height of the terrain every X units, but can be more precise.
|
|
|
|
|
|
|
|
Obviously, we don't care all that much about 1
|
|
|
|
*/
|
|
|
|
qboolean Heightmap_Trace(model_t *model, int forcehullnum, int frame, vec3_t start, vec3_t end, vec3_t mins, vec3_t maxs, trace_t *trace)
|
|
|
|
{
|
|
|
|
hmtrace_t hmtrace;
|
|
|
|
hmtrace.hm = model->terrain;
|
|
|
|
|
|
|
|
hmtrace.start[0] = start[0]/hmtrace.hm->terrainscale;
|
|
|
|
hmtrace.start[1] = start[1]/hmtrace.hm->terrainscale;
|
|
|
|
hmtrace.start[2] = (start[2])/hmtrace.hm->heightscale;
|
|
|
|
hmtrace.end[0] = end[0]/hmtrace.hm->terrainscale;
|
|
|
|
hmtrace.end[1] = end[1]/hmtrace.hm->terrainscale;
|
|
|
|
hmtrace.end[2] = (end[2])/hmtrace.hm->heightscale;
|
|
|
|
hmtrace.mins[0] = mins[0]/hmtrace.hm->terrainscale;
|
|
|
|
hmtrace.mins[1] = mins[1]/hmtrace.hm->terrainscale;
|
|
|
|
hmtrace.mins[2] = (mins[2])/hmtrace.hm->heightscale;
|
|
|
|
hmtrace.maxs[0] = maxs[0]/hmtrace.hm->terrainscale;
|
|
|
|
hmtrace.maxs[1] = maxs[1]/hmtrace.hm->terrainscale;
|
|
|
|
hmtrace.maxs[2] = (maxs[2])/hmtrace.hm->heightscale;
|
|
|
|
|
|
|
|
//FIXME: we don't have to check ALL squares like this, we could use a much smaller range.
|
|
|
|
Heightmap_Trace_X(&hmtrace, 0, hmtrace.hm->terrainsize);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
/*
|
|
|
|
Heightmap_Trace
|
|
|
|
Traces a line through a heightmap, sampling the terrain at various different positions.
|
|
|
|
This is inprecise, only supports points (or vertical lines), and can often travel though sticky out bits of terrain.
|
|
|
|
*/
|
2012-01-17 07:57:46 +00:00
|
|
|
qboolean Heightmap_Trace(model_t *model, int forcehullnum, int frame, vec3_t axis[3], vec3_t start, vec3_t end, vec3_t mins, vec3_t maxs, unsigned int contentmask, trace_t *trace)
|
2005-08-26 22:49:36 +00:00
|
|
|
{
|
|
|
|
vec3_t org;
|
|
|
|
vec3_t dir;
|
2011-05-20 04:10:46 +00:00
|
|
|
float distleft;
|
2005-08-26 22:49:36 +00:00
|
|
|
float dist;
|
|
|
|
heightmap_t *hm = model->terrain;
|
|
|
|
memset(trace, 0, sizeof(trace_t));
|
|
|
|
|
|
|
|
if (Heightmap_PointContentsHM(hm, mins[2], start) == FTECONTENTS_SOLID)
|
|
|
|
{
|
|
|
|
trace->fraction = 0;
|
|
|
|
trace->startsolid = true;
|
|
|
|
trace->allsolid = true;
|
|
|
|
VectorCopy(start, trace->endpos);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
VectorCopy(start, org);
|
|
|
|
VectorSubtract(end, start, dir);
|
|
|
|
dist = VectorNormalize(dir);
|
2011-05-20 04:10:46 +00:00
|
|
|
if (dist < 10 && dist)
|
2005-08-26 22:49:36 +00:00
|
|
|
{ //if less than 10 units, do at least 10 steps
|
2011-05-20 04:10:46 +00:00
|
|
|
VectorScale(dir, 1/10.0f, dir);
|
2005-08-26 22:49:36 +00:00
|
|
|
dist = 10;
|
2011-05-20 04:10:46 +00:00
|
|
|
}
|
2005-08-26 22:49:36 +00:00
|
|
|
distleft = dist;
|
|
|
|
|
2011-05-20 04:10:46 +00:00
|
|
|
while(distleft>0)
|
2005-08-26 22:49:36 +00:00
|
|
|
{
|
|
|
|
VectorAdd(org, dir, org);
|
|
|
|
if (Heightmap_PointContentsHM(hm, mins[2], org) == FTECONTENTS_SOLID)
|
|
|
|
{ //go back to the previous safe spot
|
|
|
|
VectorSubtract(org, dir, org);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
distleft--;
|
|
|
|
}
|
|
|
|
|
|
|
|
trace->contents = Heightmap_PointContentsHM(hm, mins[2], end);
|
|
|
|
|
2011-05-20 04:10:46 +00:00
|
|
|
if (distleft <= 0 && trace->contents != FTECONTENTS_SOLID)
|
2005-08-26 22:49:36 +00:00
|
|
|
{ //all the way
|
|
|
|
trace->fraction = 1;
|
|
|
|
VectorCopy(end, trace->endpos);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{ //we didn't get all the way there. :(
|
|
|
|
VectorSubtract(org, start, dir);
|
|
|
|
trace->fraction = Length(dir)/dist;
|
|
|
|
if (trace->fraction > 1)
|
|
|
|
trace->fraction = 1;
|
|
|
|
VectorCopy(org, trace->endpos);
|
|
|
|
}
|
|
|
|
|
|
|
|
trace->plane.normal[0] = 0;
|
|
|
|
trace->plane.normal[1] = 0;
|
|
|
|
trace->plane.normal[2] = 1;
|
|
|
|
Heightmap_Normal(model->terrain, trace->endpos, trace->plane.normal);
|
|
|
|
|
|
|
|
return trace->fraction != 1;
|
|
|
|
}
|
2006-03-06 01:41:09 +00:00
|
|
|
|
2005-08-26 22:49:36 +00:00
|
|
|
#endif
|
2009-07-11 18:23:57 +00:00
|
|
|
unsigned int Heightmap_FatPVS (model_t *mod, vec3_t org, qbyte *pvsbuffer, unsigned int pvssize, qboolean add)
|
2005-08-26 22:49:36 +00:00
|
|
|
{
|
2009-07-11 18:23:57 +00:00
|
|
|
return 0;
|
2005-08-26 22:49:36 +00:00
|
|
|
}
|
|
|
|
|
2007-08-30 18:27:39 +00:00
|
|
|
#ifndef CLIENTONLY
|
2010-07-11 02:22:39 +00:00
|
|
|
qboolean Heightmap_EdictInFatPVS (model_t *mod, struct pvscache_s *edict, qbyte *pvsdata)
|
2005-08-26 22:49:36 +00:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-07-11 02:22:39 +00:00
|
|
|
void Heightmap_FindTouchedLeafs (model_t *mod, pvscache_t *ent, float *mins, float *maxs)
|
2005-08-26 22:49:36 +00:00
|
|
|
{
|
|
|
|
}
|
2007-08-30 18:27:39 +00:00
|
|
|
#endif
|
2005-08-26 22:49:36 +00:00
|
|
|
|
2006-09-17 00:59:22 +00:00
|
|
|
void Heightmap_LightPointValues (model_t *mod, vec3_t point, vec3_t res_diffuse, vec3_t res_ambient, vec3_t res_dir)
|
2005-08-26 22:49:36 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
void Heightmap_StainNode (mnode_t *node, float *parms)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
void Heightmap_MarkLights (dlight_t *light, int bit, mnode_t *node)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2009-07-11 18:23:57 +00:00
|
|
|
qbyte *Heightmap_LeafnumPVS (model_t *model, int num, qbyte *buffer, unsigned int buffersize)
|
2005-08-26 22:49:36 +00:00
|
|
|
{
|
|
|
|
static qbyte heightmappvs = 255;
|
|
|
|
return &heightmappvs;
|
|
|
|
}
|
|
|
|
int Heightmap_LeafForPoint (model_t *model, vec3_t point)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-03-06 01:41:09 +00:00
|
|
|
//Heightmap_NativeBoxContents
|
|
|
|
|
2011-05-20 04:10:46 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
ter_reload,
|
|
|
|
ter_save,
|
|
|
|
ter_set,
|
|
|
|
ter_smooth,
|
|
|
|
ter_raise,
|
|
|
|
ter_lower
|
|
|
|
};
|
|
|
|
qboolean Heightmap_Edit(model_t *mod, int action, float *pos, float radius, float quant)
|
|
|
|
{
|
|
|
|
unsigned short *tmp;
|
|
|
|
heightmap_t *hm = mod->terrain;
|
|
|
|
int size;
|
|
|
|
int x, y, min[2], max[2];
|
|
|
|
float xd, yd, w;
|
|
|
|
vec2_t sc;
|
|
|
|
if (mod->type != mod_heightmap)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
size = hm->terrainsize;
|
|
|
|
|
|
|
|
if (radius < 0.05)
|
|
|
|
radius = 0.05;
|
|
|
|
|
|
|
|
sc[0] = pos[0] / hm->terrainscale;
|
|
|
|
sc[1] = pos[1] / hm->terrainscale;
|
|
|
|
radius = radius / hm->terrainscale;
|
|
|
|
quant /= hm->heightscale;
|
|
|
|
|
|
|
|
min[0] = sc[0] - radius;
|
|
|
|
min[1] = sc[1] - radius;
|
|
|
|
max[0] = sc[0] + radius;
|
|
|
|
max[1] = sc[1] + radius;
|
|
|
|
|
|
|
|
if (min[0] < 0)
|
|
|
|
min[0] = 0;
|
|
|
|
if (min[1] < 0)
|
|
|
|
min[1] = 0;
|
|
|
|
|
|
|
|
if (max[0] > size)
|
|
|
|
max[0] = size;
|
|
|
|
if (max[1] < size)
|
|
|
|
max[1] = size;
|
|
|
|
|
|
|
|
switch(action)
|
|
|
|
{
|
|
|
|
case ter_reload:
|
|
|
|
tmp = (unsigned short*)COM_LoadTempFile(hm->hmapname);
|
|
|
|
if (tmp)
|
|
|
|
x = com_filesize/2;
|
|
|
|
else
|
|
|
|
x = 0;
|
|
|
|
if (x > size*size)
|
|
|
|
x = size*size;
|
|
|
|
while (x-- > 0)
|
|
|
|
{
|
|
|
|
hm->heights[x] = LittleShort(tmp[x]);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ter_save:
|
|
|
|
tmp = Hunk_TempAlloc(size*size*2);
|
|
|
|
for (x = 0; x < size*size; x++)
|
|
|
|
{
|
|
|
|
tmp[x] = LittleShort(hm->heights[x]);
|
|
|
|
}
|
|
|
|
COM_WriteFile(hm->hmapname, tmp, size*size*2);
|
|
|
|
break;
|
|
|
|
case ter_set:
|
|
|
|
for (x = min[0]; x < max[0]; x++)
|
|
|
|
{
|
|
|
|
for (y = min[1]; y < max[1]; y++)
|
|
|
|
{
|
|
|
|
xd = sc[0] - x;
|
|
|
|
yd = sc[1] - y;
|
|
|
|
if (sqrt(xd*xd+yd*yd) < radius)
|
|
|
|
{
|
|
|
|
hm->heights[x + y*size] = quant;
|
|
|
|
hm->modified[(int)(x/(hm->terrainscale)) + (int)(y/(hm->terrainscale))*SECTIONS] = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ter_smooth:
|
|
|
|
case ter_raise:
|
|
|
|
for (x = min[0]; x < max[0]; x++)
|
|
|
|
{
|
|
|
|
for (y = min[1]; y < max[1]; y++)
|
|
|
|
{
|
|
|
|
xd = sc[0] - x;
|
|
|
|
yd = sc[1] - y;
|
|
|
|
w = sqrt(radius*radius - (xd*xd+yd*yd));
|
|
|
|
if (w > 0)
|
|
|
|
{
|
|
|
|
w *= quant/radius;
|
|
|
|
hm->heights[x + y*size] += w;
|
|
|
|
hm->modified[(int)(x/(hm->terrainscale)) + (int)(y/(hm->terrainscale))*SECTIONS] = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ter_lower:
|
|
|
|
for (x = min[0]; x < max[0]; x++)
|
|
|
|
{
|
|
|
|
for (y = min[1]; y < max[1]; y++)
|
|
|
|
{
|
|
|
|
xd = sc[0] - x;
|
|
|
|
yd = sc[1] - y;
|
|
|
|
w = sqrt(radius*radius - (xd*xd+yd*yd));
|
|
|
|
if (w > 0)
|
|
|
|
{
|
|
|
|
w *= quant/radius;
|
|
|
|
/*don't drop below 0*/
|
|
|
|
if (hm->heights[x + y*size]-w < 0)
|
|
|
|
hm->heights[x + y*size] = 0;
|
|
|
|
else
|
|
|
|
hm->heights[x + y*size] -= w;
|
|
|
|
hm->modified[(int)(x/(hm->terrainscale)) + (int)(y/(hm->terrainscale))*SECTIONS] = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2006-03-12 09:19:31 +00:00
|
|
|
qboolean GL_LoadHeightmapModel (model_t *mod, void *buffer)
|
2005-08-26 22:49:36 +00:00
|
|
|
{
|
|
|
|
heightmap_t *hm;
|
|
|
|
unsigned short *heightmap;
|
|
|
|
int size;
|
2011-05-20 04:10:46 +00:00
|
|
|
int x, y;
|
2005-08-26 22:49:36 +00:00
|
|
|
|
2005-10-15 20:06:34 +00:00
|
|
|
float skyrotate;
|
|
|
|
vec3_t skyaxis;
|
2005-08-26 22:49:36 +00:00
|
|
|
char heightmapname[MAX_QPATH];
|
|
|
|
char detailtexname[MAX_QPATH];
|
|
|
|
char basetexname[MAX_QPATH];
|
|
|
|
char exttexname[MAX_QPATH];
|
|
|
|
char entfile[MAX_QPATH];
|
2005-10-15 20:06:34 +00:00
|
|
|
char skyname[MAX_QPATH];
|
2005-08-26 22:49:36 +00:00
|
|
|
float worldsize = 64;
|
|
|
|
float heightsize = 1/16;
|
|
|
|
int numsegs = 1;
|
|
|
|
|
|
|
|
*heightmapname = '\0';
|
|
|
|
*detailtexname = '\0';
|
|
|
|
*basetexname = '\0';
|
|
|
|
*exttexname = '\0';
|
|
|
|
*entfile = '\0';
|
2005-10-15 20:06:34 +00:00
|
|
|
strcpy(skyname, "night");
|
|
|
|
|
|
|
|
skyrotate = 0;
|
|
|
|
skyaxis[0] = 0;
|
|
|
|
skyaxis[1] = 0;
|
|
|
|
skyaxis[2] = 0;
|
2005-08-26 22:49:36 +00:00
|
|
|
|
|
|
|
buffer = COM_Parse(buffer);
|
|
|
|
if (strcmp(com_token, "terrain"))
|
2006-03-12 09:19:31 +00:00
|
|
|
{
|
2007-09-23 15:28:06 +00:00
|
|
|
Con_Printf(CON_ERROR "%s wasn't terrain map\n", mod->name); //shouldn't happen
|
2006-03-12 09:19:31 +00:00
|
|
|
return false;
|
|
|
|
}
|
2007-05-25 22:16:29 +00:00
|
|
|
|
|
|
|
if (qrenderer != QR_OPENGL)
|
|
|
|
return false;
|
|
|
|
|
2005-08-26 22:49:36 +00:00
|
|
|
for(;;)
|
|
|
|
{
|
|
|
|
buffer = COM_Parse(buffer);
|
|
|
|
if (!buffer)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (!strcmp(com_token, "heightmap"))
|
|
|
|
{
|
|
|
|
buffer = COM_Parse(buffer);
|
|
|
|
Q_strncpyz(heightmapname, com_token, sizeof(heightmapname));
|
|
|
|
}
|
|
|
|
else if (!strcmp(com_token, "detail"))
|
|
|
|
{
|
|
|
|
buffer = COM_Parse(buffer);
|
|
|
|
Q_strncpyz(detailtexname, com_token, sizeof(detailtexname));
|
|
|
|
}
|
|
|
|
else if (!strcmp(com_token, "texturegridbase"))
|
|
|
|
{
|
|
|
|
buffer = COM_Parse(buffer);
|
|
|
|
Q_strncpyz(basetexname, com_token, sizeof(basetexname));
|
|
|
|
}
|
|
|
|
else if (!strcmp(com_token, "texturegridext"))
|
|
|
|
{
|
|
|
|
buffer = COM_Parse(buffer);
|
|
|
|
Q_strncpyz(exttexname, com_token, sizeof(exttexname));
|
|
|
|
}
|
|
|
|
else if (!strcmp(com_token, "gridsize"))
|
|
|
|
{
|
|
|
|
buffer = COM_Parse(buffer);
|
|
|
|
worldsize = atof(com_token);
|
|
|
|
}
|
|
|
|
else if (!strcmp(com_token, "heightsize"))
|
|
|
|
{
|
|
|
|
buffer = COM_Parse(buffer);
|
|
|
|
heightsize = atof(com_token);
|
|
|
|
}
|
|
|
|
else if (!strcmp(com_token, "entfile"))
|
|
|
|
{
|
|
|
|
buffer = COM_Parse(buffer);
|
|
|
|
Q_strncpyz(entfile, com_token, sizeof(entfile));
|
|
|
|
}
|
2005-10-15 20:06:34 +00:00
|
|
|
else if (!strcmp(com_token, "skybox"))
|
|
|
|
{
|
|
|
|
buffer = COM_Parse(buffer);
|
|
|
|
Q_strncpyz(skyname, com_token, sizeof(skyname));
|
|
|
|
}
|
|
|
|
else if (!strcmp(com_token, "skyrotate"))
|
|
|
|
{
|
|
|
|
buffer = COM_Parse(buffer);
|
|
|
|
skyaxis[0] = atof(com_token);
|
|
|
|
buffer = COM_Parse(buffer);
|
|
|
|
skyaxis[1] = atof(com_token);
|
|
|
|
buffer = COM_Parse(buffer);
|
|
|
|
skyaxis[2] = atof(com_token);
|
|
|
|
skyrotate = VectorNormalize(skyaxis);
|
|
|
|
}
|
2005-08-26 22:49:36 +00:00
|
|
|
else if (!strcmp(com_token, "texturesegments"))
|
|
|
|
{
|
|
|
|
buffer = COM_Parse(buffer);
|
|
|
|
numsegs = atoi(com_token);
|
|
|
|
}
|
|
|
|
else
|
2006-03-12 09:19:31 +00:00
|
|
|
{
|
2007-09-23 15:28:06 +00:00
|
|
|
Con_Printf(CON_ERROR "%s, unrecognised token in terrain map\n", mod->name);
|
2006-03-12 09:19:31 +00:00
|
|
|
return false;
|
|
|
|
}
|
2005-08-26 22:49:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (numsegs > SECTIONS)
|
2006-03-12 09:19:31 +00:00
|
|
|
{
|
2007-09-23 15:28:06 +00:00
|
|
|
Con_Printf(CON_ERROR "%s, heightmap uses too many sections max is %i\n", mod->name, SECTIONS);
|
2006-03-12 09:19:31 +00:00
|
|
|
return false;
|
|
|
|
}
|
2005-08-26 22:49:36 +00:00
|
|
|
|
|
|
|
|
|
|
|
mod->type = mod_heightmap;
|
|
|
|
|
|
|
|
heightmap = (unsigned short*)COM_LoadTempFile(heightmapname);
|
2011-05-20 04:10:46 +00:00
|
|
|
if (!heightmap)
|
|
|
|
{
|
|
|
|
size = 1024;
|
|
|
|
heightmap = Hunk_TempAlloc(size*size*2);
|
2005-08-26 22:49:36 +00:00
|
|
|
|
2011-05-20 04:10:46 +00:00
|
|
|
for (x = 0; x < size; x++)
|
|
|
|
for (y = 0; y < size; y++)
|
|
|
|
{
|
|
|
|
heightmap[x+y*size] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2006-03-12 09:19:31 +00:00
|
|
|
{
|
2011-05-20 04:10:46 +00:00
|
|
|
size = sqrt(com_filesize/2);
|
|
|
|
if (size % numsegs)
|
|
|
|
{
|
|
|
|
Con_Printf(CON_ERROR "%s, heightmap is not a multiple of %i\n", mod->name, numsegs);
|
|
|
|
return false;
|
|
|
|
}
|
2006-03-12 09:19:31 +00:00
|
|
|
}
|
2005-08-26 22:49:36 +00:00
|
|
|
|
2011-05-20 04:10:46 +00:00
|
|
|
hm = Hunk_Alloc(sizeof(*hm) + size*size*2);
|
2005-08-26 22:49:36 +00:00
|
|
|
memset(hm, 0, sizeof(*hm));
|
2011-05-20 04:10:46 +00:00
|
|
|
Q_strncpyz(hm->hmapname, heightmapname, sizeof(hm->hmapname));
|
2005-08-26 22:49:36 +00:00
|
|
|
hm->heights = (unsigned short*)(hm+1);
|
|
|
|
for (x = 0; x < size*size; x++)
|
|
|
|
{
|
|
|
|
hm->heights[x] = LittleShort(heightmap[x]);
|
|
|
|
}
|
|
|
|
hm->terrainsize = size;
|
|
|
|
hm->terrainscale = worldsize;
|
|
|
|
hm->heightscale = heightsize;
|
|
|
|
hm->numsegs = numsegs;
|
|
|
|
|
2011-05-20 04:10:46 +00:00
|
|
|
hm->shader = R_RegisterShader(basetexname,
|
|
|
|
"{\n"
|
|
|
|
"{\n"
|
|
|
|
"map maps/test/ground.jpg\n"
|
|
|
|
"}\n"
|
|
|
|
"}\n"
|
|
|
|
);
|
|
|
|
|
|
|
|
hm->skyshader = R_RegisterCustom(va("skybox_%s", skyname), Shader_DefaultSkybox, NULL);
|
|
|
|
|
|
|
|
|
2005-08-26 22:49:36 +00:00
|
|
|
mod->entities = COM_LoadHunkFile(entfile);
|
|
|
|
|
2010-02-06 01:25:04 +00:00
|
|
|
if (qrenderer != QR_NONE)
|
2005-08-26 22:49:36 +00:00
|
|
|
{
|
2009-11-04 21:16:50 +00:00
|
|
|
hm->detailtexture = R_LoadHiResTexture(detailtexname, "", IF_NOGAMMA);
|
2007-10-06 15:33:38 +00:00
|
|
|
|
2009-11-04 21:16:50 +00:00
|
|
|
for (x = 0; x < numsegs; x++)
|
2005-08-26 22:49:36 +00:00
|
|
|
{
|
2009-11-04 21:16:50 +00:00
|
|
|
int y;
|
|
|
|
|
|
|
|
for (y = 0; y < numsegs; y++)
|
|
|
|
{
|
|
|
|
hm->textures[x+y*SECTIONS] = R_LoadHiResTexture(va("%s%02ix%02i%s", basetexname, x, y, exttexname), "", IF_CLAMP|IF_NOGAMMA);
|
2011-05-20 04:10:46 +00:00
|
|
|
hm->modified[x+y*SECTIONS] = true;
|
2009-11-04 21:16:50 +00:00
|
|
|
}
|
2005-08-26 22:49:36 +00:00
|
|
|
}
|
|
|
|
}
|
2005-10-15 20:06:34 +00:00
|
|
|
|
2012-01-17 07:57:46 +00:00
|
|
|
mod->funcs.NativeTrace = Heightmap_Trace;
|
2005-08-26 22:49:36 +00:00
|
|
|
mod->funcs.PointContents = Heightmap_PointContents;
|
2006-03-06 01:41:09 +00:00
|
|
|
|
|
|
|
mod->funcs.NativeContents = Heightmap_NativeBoxContents;
|
|
|
|
|
2005-08-26 22:49:36 +00:00
|
|
|
mod->funcs.LightPointValues = Heightmap_LightPointValues;
|
|
|
|
mod->funcs.StainNode = Heightmap_StainNode;
|
|
|
|
mod->funcs.MarkLights = Heightmap_MarkLights;
|
|
|
|
|
|
|
|
mod->funcs.LeafnumForPoint = Heightmap_LeafForPoint;
|
|
|
|
mod->funcs.LeafPVS = Heightmap_LeafnumPVS;
|
|
|
|
|
|
|
|
#ifndef CLIENTONLY
|
2010-07-11 02:22:39 +00:00
|
|
|
mod->funcs.FindTouchedLeafs = Heightmap_FindTouchedLeafs;
|
2005-08-26 22:49:36 +00:00
|
|
|
mod->funcs.EdictInFatPVS = Heightmap_EdictInFatPVS;
|
|
|
|
mod->funcs.FatPVS = Heightmap_FatPVS;
|
|
|
|
#endif
|
|
|
|
/* mod->hulls[0].funcs.HullPointContents = Heightmap_PointContents;
|
|
|
|
mod->hulls[1].funcs.HullPointContents = Heightmap_PointContents;
|
|
|
|
mod->hulls[2].funcs.HullPointContents = Heightmap_PointContents;
|
|
|
|
mod->hulls[3].funcs.HullPointContents = Heightmap_PointContents;
|
|
|
|
*/
|
|
|
|
|
|
|
|
mod->terrain = hm;
|
2006-03-12 09:19:31 +00:00
|
|
|
|
|
|
|
return true;
|
2005-08-26 22:49:36 +00:00
|
|
|
}
|
|
|
|
#endif
|