Grid tile highlighting?

Posted By: DJBMASTER

Grid tile highlighting? - 03/05/10 01:11

Hi guys, I'm working on something for a level editor and i'm just throwing ideas together.

I'm trying to achieve individual tile highlighting on my grid. I've sort of got it to work, by tracing through the 3D mouse onto my grid and setting a position, but it seems to be a little inaccurate and I can't reach every position on the grid.



If anyone would be so kind as to take a look and help me see where I can improve my code, or give another solution then i'd be very grateful.

Thanks, DJB.
Posted By: Quad

Re: Grid tile highlighting? - 03/05/10 07:59

q auick try:

tile.x = hit.x- (hit.x% grid_size) + grid_size/2;
tile.y = hit.y- (hit.y% grid_size) - grid_size/2;

(only this 2 lines in if changed)
Posted By: Joozey

Re: Grid tile highlighting? - 03/05/10 09:45

I have been playing around a bit but I couldn't find a solution that's significantly better. vec_set( mouse_cursor, mouse_pos ) strikes me as odd though. It should be the other way around. But nothing improves with that.
Posted By: DJBMASTER

Re: Grid tile highlighting? - 03/05/10 15:41

@Joozey, yeh that was a mistake, but like you said it doesn't seem to change anything.

@Quadraxas, thanks that seems to improve it. I can reach any part of the grid now. The only problem is that it only works if I don't move the camera, but only rotate it. From the start position, the tile seems to keep in sync with the mouse position, but if I change the camera position then it starts to become offset from it.

I guess this is dependent on the distance from the plane, so any ideas how I can use the result from the c_trace, to make the dragging proportional?

Thanks again guys.
Posted By: Quad

Re: Grid tile highlighting? - 03/05/10 17:55

oh, i'll also look in to that.
Posted By: Quad

Re: Grid tile highlighting? - 03/05/10 18:32

solved:

it's actually not related the camera pos/angle, it's related to hit.x or hit.y being negative or positive.

tile.x = hit.x - (hit.x% grid_size) + (grid_size/2) * sign(hit.x);
tile.y = hit.y - (hit.y% grid_size) + (grid_size/2) * sign(hit.y);
Posted By: DJBMASTER

Re: Grid tile highlighting? - 03/05/10 19:01

Great! There's only a little bug that sometimes the highlighted tile will jump to a space outside the grid, but that can be fixed by clamping the position.

Thanks again , owe you one.
Posted By: Quad

Re: Grid tile highlighting? - 03/05/10 20:08

Anytime wink

Keep up the great work with Easy Scripter, i can't wait to get my hands on it.
Posted By: DJBMASTER

Re: Grid tile highlighting? - 03/05/10 21:35

Thanks. Hopefully with this tile editor i'm working on, it'll be something special laugh.

One thing that I'm wondering about is the performance. If each tile is a seperate entity, then adding too many tiles is going to be a big performance hit.

I'm just talking about the editor. They'll be written out as blocks when compiled.

Any advice how I can increase performance?
Posted By: Quad

Re: Grid tile highlighting? - 03/05/10 21:40

reset(ent,DYNAMIC);
Posted By: DJBMASTER

Re: Grid tile highlighting? - 03/05/10 21:47

hmm thanks, forgot about the DYNAMIC flag. What about the limit of entities I can add into a level. Setting 'max_entities' to a much higher level consumes a hell of a load of memory. I guess this is built into the core of the engine, and hardly any workaround.
© 2024 lite-C Forums