[request] link two vec3_t with a color line


(kikujiro) #1

how can i link two vec3_t with a color line ?

i must use the function ‘debugline’ ? if is that … how can i set the vars ‘r_debugSurface’ to ‘2’?


(Rain) #2

You can use CG_RailTrail/CG_RailTrail2.


(mod3m) #3

use the rail from the last reply. if you’re wondering about how to get corners, let’s say min/max are your vec3_ts. this would be your box.

min[0] min[1] min[2]
min[0] min[1] max[2]
min[0] max[1] max[2]
min[0] max[1] min[2]
max[0] min[1] min[2]
max[0] min[1] max[2]
max[0] max[1] max[2]
max[0] max[1] min[2]


(Magik) #4

You can set r_debugSurface if you switch to “dev-mode” by typing “devmap <mapname>” on console. But I tried DebugLine() and I cannot get it working. I don’t want to use CG_RailTrail() as I try to stay server side only. Someone got any other ideas how to draw a line or maybe how to get DebugLine() working?


(Rain) #5

You can cause the client to call CG_RailTrail() via an EV_RAILTRAIL (look at the g_debugBullets code to see how this is done.)
Beware that G_TempEntity() snaps the origin (which may or may not be what you want.)


(Magik) #6

Thanks. :slight_smile:


(Magik) #7

Ok, i have given up the “server-side only” paradigm and I am using part of the code from CG_RailTrail2() to draw my lines.

The problem I have now is I need to draw some sort of “permanent” lines, where permanent means at least until the map is restarted or something like that.

Although I theoretically could use CG_RailTrail with increased endtime I have the problem that this approach uses local entities, which are designed to be temporary objects and I need to draw a lot of lines (500 to 1000), so I would permanently lock nearly all localEntities available. Of course I could increase the limit for local entities as well but I think there must be a better way to do this.

Maybe somewhere in the client code is a function or entity type already prepared for stuff like that I overlooked. So if somebody could point me at the right direction that would be a great help.


(mod3m) #8

are you using g_tempentity? :]


(Magik) #9

No, I coded a special server command into the client, which I call from my game stuff and the command uses a slightly modified version of the CG_RailTrail2() code to display a line between to vecs.


(Rain) #10

This is the basic line-drawing function we use in etpro (zinx made it use polybuffers, so it won’t eat up localents or refents.) You will need to add the line once every frame, because no persistent data is kept here. (It’s easy enough to keep your own list to do that, though.)

One other thing you should keep in mind is that these lines will be drawn regardless of whether they can be seen–you might want to use trap_R_inPVS() to determine which lines you want to draw.

Finally, if you’re going to be drawing a lot of lines, you may want to pass the byte versions of the colors (0-255) directly, because the float->int cast isn’t terribly cheap.

#define ADDLINE_WIDTH	1.5f

void etpro_DrawLine(vec3_t start, vec3_t end, vec4_t color, qhandle_t shader)
{
	polyBuffer_t *pb;
	int vert;
	byte bcolor[4];

	vec3_t dir, diff, up;

	pb = CG_PB_FindFreePolyBuffer( shader, 4, 6 );
	if (!pb) return;

	bcolor[0] = color[0] * 255.f;
	bcolor[1] = color[1] * 255.f;
	bcolor[2] = color[2] * 255.f;
	bcolor[3] = color[3] * 255.f;

	vert = pb->numVerts;

	VectorSubtract(start, end, dir);
	VectorNormalizeFast(dir);
	
	// start points
	VectorSubtract(start, cg.refdef_current->vieworg, diff);
	CrossProduct(dir, diff, up);
	VectorNormalizeFast(up);
	VectorScale(up, ADDLINE_WIDTH*.5f, up);

	VectorAdd(start, up, pb->xyz[vert+0]);
	Vector2Set(pb->st[vert+0], 0.0, 0.0);
	memcpy(pb->color[vert+0], bcolor, sizeof(*pb->color));

	VectorSubtract(start, up, pb->xyz[vert+1]);
	Vector2Set(pb->st[vert+1], 0.0, 1.0);
	memcpy(pb->color[vert+1], bcolor, sizeof(*pb->color));

	// end points
	VectorSubtract(end, cg.refdef_current->vieworg, diff);
	CrossProduct(dir, diff, up);
	VectorNormalizeFast(up);
	VectorScale(up, ADDLINE_WIDTH*.5f, up);

	VectorAdd(end, up, pb->xyz[vert+2]);
	Vector2Set(pb->st[vert+2], 1.0, 0.0);
	memcpy(pb->color[vert+2], bcolor, sizeof(*pb->color));

	VectorSubtract(end, up, pb->xyz[vert+3]);
	Vector2Set(pb->st[vert+3], 1.0, 1.0);
	memcpy(pb->color[vert+3], bcolor, sizeof(*pb->color));

	pb->numVerts = vert+4;

	pb->indicies[pb->numIndicies++] = vert+2;
	pb->indicies[pb->numIndicies++] = vert+0;
	pb->indicies[pb->numIndicies++] = vert+1;

	pb->indicies[pb->numIndicies++] = vert+1;
	pb->indicies[pb->numIndicies++] = vert+3;
	pb->indicies[pb->numIndicies++] = vert+2;
}

(Magik) #11

Thank you very much! :slight_smile: