Beispiel #1
0
/*
===============
R_GridInsertRow
===============
*/
srfGridMesh_t *R_GridInsertRow(srfGridMesh_t *grid, int row, int column, vec3_t point, float loderror)
{
	int                   i, j;
	int                   width, height, oldheight;
	MAC_STATIC drawVert_t ctrl[MAX_GRID_SIZE][MAX_GRID_SIZE];
	float                 errorTable[2][MAX_GRID_SIZE];
	float                 lodRadius;
	vec3_t                lodOrigin;

	oldheight = 0;
	width     = grid->width;
	height    = grid->height + 1;
	if (height > MAX_GRID_SIZE)
	{
		return NULL;
	}
	for (i = 0; i < height; i++)
	{
		if (i == row)
		{
			//insert new row
			for (j = 0; j < grid->width; j++)
			{
				LerpDrawVert(&grid->verts[(i - 1) * grid->width + j], &grid->verts[i * grid->width + j], &ctrl[i][j]);
				if (j == column)
				{
					VectorCopy(point, ctrl[i][j].xyz);
				}
			}
			errorTable[1][i] = loderror;
			continue;
		}
		errorTable[1][i] = grid->heightLodError[oldheight];
		for (j = 0; j < grid->width; j++)
		{
			ctrl[i][j] = grid->verts[oldheight * grid->width + j];
		}
		oldheight++;
	}
	for (j = 0; j < grid->width; j++)
	{
		errorTable[0][j] = grid->widthLodError[j];
	}
	// put all the aproximating points on the curve
	//PutPointsOnCurve( ctrl, width, height );
	// calculate normals
	MakeMeshNormals(width, height, ctrl);

	VectorCopy(grid->lodOrigin, lodOrigin);
	lodRadius = grid->lodRadius;
	// free the old grid
	R_FreeSurfaceGridMesh(grid);
	// create a new grid
	grid            = R_CreateSurfaceGridMesh(width, height, ctrl, errorTable);
	grid->lodRadius = lodRadius;
	VectorCopy(lodOrigin, grid->lodOrigin);
	return grid;
}
Beispiel #2
0
/*
 * R_GridInsertRow
 */
srfGridMesh_t *
R_GridInsertRow(srfGridMesh_t *grid, int row, int column, Vec3 point, float loderror)
{
	int i, j;
	int width, height, oldheight;
	Drawvert	ctrl[MAX_GRID_SIZE][MAX_GRID_SIZE];
	float	errorTable[2][MAX_GRID_SIZE];
	float	lodRadius;
	Vec3	lodOrigin;

	oldheight	= 0;
	width	= grid->width;
	height	= grid->height + 1;
	if(height > MAX_GRID_SIZE)
		return NULL;
	for(i = 0; i < height; i++){
		if(i == row){
			/* insert new row */
			for(j = 0; j < grid->width; j++){
				LerpDrawVert(&grid->verts[(i-1) * grid->width + j],
					&grid->verts[i * grid->width + j], &ctrl[i][j]);
				if(j == column)
					copyv3(point, ctrl[i][j].xyz);
			}
			errorTable[1][i] = loderror;
			continue;
		}
		errorTable[1][i] = grid->heightLodError[oldheight];
		for(j = 0; j < grid->width; j++)
			ctrl[i][j] = grid->verts[oldheight * grid->width + j];
		oldheight++;
	}
	for(j = 0; j < grid->width; j++)
		errorTable[0][j] = grid->widthLodError[j];
	/* put all the aproximating points on the curve
	 * PutPointsOnCurve( ctrl, width, height );
	 * calculate normals */
	MakeMeshNormals(width, height, ctrl);

	copyv3(grid->lodOrigin, lodOrigin);
	lodRadius = grid->lodRadius;
	/* free the old grid */
	R_FreeSurfaceGridMesh(grid);
	/* create a new grid */
	grid = R_CreateSurfaceGridMesh(width, height, ctrl, errorTable);
	grid->lodRadius = lodRadius;
	copyv3(lodOrigin, grid->lodOrigin);
	return grid;
}
Beispiel #3
0
srfGridMesh_t *R_GridInsertRow(srfGridMesh_t *grid, int row, int column, vec3_t point, float loderror)
{
	int                  i, j;
	int                  width = grid->width, height = grid->height + 1, oldheight = 0;
	static srfVert_t     ctrl[MAX_GRID_SIZE][MAX_GRID_SIZE];
	float                errorTable[2][MAX_GRID_SIZE];
	float                lodRadius;
	vec3_t               lodOrigin;
	int                  numTriangles;
	static srfTriangle_t triangles[SHADER_MAX_TRIANGLES];

	if (height > MAX_GRID_SIZE)
	{
		return NULL;
	}
	for (i = 0; i < height; i++)
	{
		if (i == row)
		{
			//insert new row
			for (j = 0; j < grid->width; j++)
			{
				LerpSurfaceVert(&grid->verts[(i - 1) * grid->width + j], &grid->verts[i * grid->width + j], &ctrl[i][j]);
				if (j == column)
				{
					VectorCopy(point, ctrl[i][j].xyz);
				}
			}
			errorTable[1][i] = loderror;
			continue;
		}
		errorTable[1][i] = grid->heightLodError[oldheight];
		for (j = 0; j < grid->width; j++)
		{
			ctrl[i][j] = grid->verts[oldheight * grid->width + j];
		}
		oldheight++;
	}
	for (j = 0; j < grid->width; j++)
	{
		errorTable[0][j] = grid->widthLodError[j];
	}
	// put all the aproximating points on the curve
	//PutPointsOnCurve( ctrl, width, height );

	// calculate triangles
	numTriangles = MakeMeshTriangles(width, height, ctrl, triangles);

	// calculate normals
	MakeMeshNormals(width, height, ctrl);
	MakeMeshTangentVectors(width, height, ctrl, numTriangles, triangles);

	// calculate tangent spaces
	//MakeTangentSpaces(width, height, ctrl, numTriangles, triangles);

	VectorCopy(grid->lodOrigin, lodOrigin);
	lodRadius = grid->lodRadius;
	// free the old grid
	R_FreeSurfaceGridMesh(grid);
	// create a new grid
	grid            = R_CreateSurfaceGridMesh(width, height, ctrl, errorTable, numTriangles, triangles);
	grid->lodRadius = lodRadius;
	VectorCopy(lodOrigin, grid->lodOrigin);
	return grid;
}
Beispiel #4
0
void R_FreeSurfaceGridMeshAndVertexes( idSurfaceGrid* grid ) {
	R_FreeSurfaceGridMesh( grid );
	delete[] grid->vertexes;
}
Beispiel #5
0
/*
===============
R_GridInsertRow
===============
*/
srfGridMesh_t  *R_GridInsertRow( srfGridMesh_t *grid, int row, int column, vec3_t point, float loderror )
{
	int                  i, j;
	int                  width, height, oldheight;
	float                errorTable[ 2 ][ MAX_GRID_SIZE ];
	float                lodRadius;
	vec3_t               lodOrigin;
	int                  numTriangles;

	oldheight = 0;
	width = grid->width;
	height = grid->height + 1;

	if ( height > MAX_GRID_SIZE )
	{
		return nullptr;
	}

	for ( i = 0; i < height; i++ )
	{
		if ( i == row )
		{
			//insert new row
			for ( j = 0; j < grid->width; j++ )
			{
				LerpSurfaceVert( &grid->verts[( i - 1 ) * grid->width + j ], &grid->verts[ i * grid->width + j ], &gridctrl[ i ][ j ] );

				if ( j == column )
				{
					VectorCopy( point, gridctrl[ i ][ j ].xyz );
				}
			}

			errorTable[ 1 ][ i ] = loderror;
			continue;
		}

		errorTable[ 1 ][ i ] = grid->heightLodError[ oldheight ];

		for ( j = 0; j < grid->width; j++ )
		{
			gridctrl[ i ][ j ] = grid->verts[ oldheight * grid->width + j ];
		}

		oldheight++;
	}

	for ( j = 0; j < grid->width; j++ )
	{
		errorTable[ 0 ][ j ] = grid->widthLodError[ j ];
	}

	// calculate triangles
	numTriangles = MakeMeshTriangles( width, height, gridctrl, gridtriangles );

	// calculate normals
	MakeMeshNormals( width, height, gridctrl );

	VectorCopy( grid->lodOrigin, lodOrigin );
	lodRadius = grid->lodRadius;
	// free the old grid
	R_FreeSurfaceGridMesh( grid );
	// create a new grid
	grid = R_CreateSurfaceGridMesh( width, height, gridctrl, errorTable, numTriangles, gridtriangles );
	grid->lodRadius = lodRadius;
	VectorCopy( lodOrigin, grid->lodOrigin );
	return grid;
}
Beispiel #6
0
/*
===============
R_GridInsertColumn
===============
*/
srfGridMesh_t *R_GridInsertColumn(srfGridMesh_t *grid, int column, int row, vec3_t point, float loderror)
{
	int                  i, j;
	int                  width, height, oldwidth;
	srfVert_t            ctrl[MAX_GRID_SIZE][MAX_GRID_SIZE];
	float                errorTable[2][MAX_GRID_SIZE];
	float                lodRadius;
	vec3_t               lodOrigin;
	int                  numTriangles;
	static srfTriangle_t triangles[(MAX_GRID_SIZE - 1) * (MAX_GRID_SIZE - 1) * 2];

	oldwidth = 0;
	width    = grid->width + 1;
	if (width > MAX_GRID_SIZE)
	{
		return NULL;
	}
	height = grid->height;
	for (i = 0; i < width; i++)
	{
		if (i == column)
		{
			//insert new column
			for (j = 0; j < grid->height; j++)
			{
				LerpDrawVert(&grid->verts[j * grid->width + i - 1], &grid->verts[j * grid->width + i], &ctrl[j][i]);
				if (j == row)
				{
					VectorCopy(point, ctrl[j][i].xyz);
				}
			}
			errorTable[0][i] = loderror;
			continue;
		}
		errorTable[0][i] = grid->widthLodError[oldwidth];
		for (j = 0; j < grid->height; j++)
		{
			ctrl[j][i] = grid->verts[j * grid->width + oldwidth];
		}
		oldwidth++;
	}
	for (j = 0; j < grid->height; j++)
	{
		errorTable[1][j] = grid->heightLodError[j];
	}
	// put all the aproximating points on the curve
	//PutPointsOnCurve( ctrl, width, height );

	// calculate triangles
	numTriangles = MakeMeshTriangles(width, height, ctrl, triangles);

	// calculate normals
	MakeMeshNormals(width, height, ctrl);

	VectorCopy(grid->lodOrigin, lodOrigin);
	lodRadius = grid->lodRadius;
	// free the old grid
	R_FreeSurfaceGridMesh(grid);
	// create a new grid
	grid            = R_CreateSurfaceGridMesh(width, height, ctrl, errorTable, numTriangles, triangles);
	grid->lodRadius = lodRadius;
	VectorCopy(lodOrigin, grid->lodOrigin);
	return grid;
}