Sign in to follow this  
MARS_999

Not sure how to go about allowing points on a grid to talk to each other?

Recommended Posts

MARS_999    1627
I have a grid setup and need to draw squares on it, which I am currently doing... But the problem is I only allow the user to select two points per turn and that should draw a line and it does.

Now the problem starts...
e.g.
Player selects top two points, and bottom two points, I end up rendering a square when the player has only selected the top and bottom lines, and they still need to select the right and left sides also before they gain the whole square.

I don't know what kind of data structure would work best for this, but I am using vectors and a 2D array to get the data setup so far... Seems like a simple problem but now sure about the logic on what I am missing to fix this issue. Do I need to have each square with its own 4 points? If so then each square needs to talk to each other square next to it to see if those points have been taken and if not allow them to be claimed or denied....

Thanks

Share this post


Link to post
Share on other sites
coderWalker    127
Your problem is most likely that you are drawing a line to every position in the array like so:
[code]
for (int i;i<size-1;i++)
{
draw_line(array[i].x,array[i].y,array[i].x+1,array[i].y+1);
}
[/code]
When it should be doing like this:
[code]
for (int i;i<size-2;i+=2)
{
draw_line(array[i].x,array[i].y,array[i].x+2,array[i].y+2);
}
[/code]

If you are using OpenGL your problem could be you are using
GL_LINE_STRIP

instead of:
GL_LINES

[quote]Do I need to have each square with its own 4 points?[/quote]
This is up to you, a program can do whatever you want it to.

If this was helpful please Thumbs up it.

i+=2
[img]http://blog.jayway.com/wordpress/wp-content/uploads/2009/11/Gl_lines.jpg[/img]
i++
[img]http://blog.jayway.com/wordpress/wp-content/uploads/2009/11/Gl_line_strip.jpg[/img]


Good Luck,
Coder Walker

Share this post


Link to post
Share on other sites
MARS_999    1627
[quote name='coderWalker' timestamp='1306109226' post='4814381']
Your problem is most likely that you are drawing a line to every position in the array like so:
[code]
for (int i;i<size-1;i++)
{
draw_line(array[i].x,array[i].y,array[i].x+1,array[i].y+1);
}
[/code]
When it should be doing like this:
[code]
for (int i;i<size-2;i+=2)
{
draw_line(array[i].x,array[i].y,array[i].x+2,array[i].y+2);
}
[/code]

If you are using OpenGL your problem could be you are using
GL_LINE_STRIP

instead of:
GL_LINES

[quote]Do I need to have each square with its own 4 points?[/quote]
This is up to you, a program can do whatever you want it to.

If this was helpful please Thumbs up it.

i+=2
[img]http://blog.jayway.com/wordpress/wp-content/uploads/2009/11/Gl_lines.jpg[/img]
i++
[img]http://blog.jayway.com/wordpress/wp-content/uploads/2009/11/Gl_line_strip.jpg[/img]


Good Luck,
Coder Walker
[/quote]


Thanks for the reply Coderwalker, what I ended up having to do is, instead of having a conditional variable for each point, I moved it to each line segment and that solved my issue. But I understand your point and will keep that in mind if I run into that issue. Thanks!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this