• Create Account

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

6 replies to this topic

### #1hockeyman  Members

130
Like
0Likes
Like

Posted 18 July 2012 - 08:29 AM

I am developing paint app. User can draw with mouse on my OpenGL view. He draws textured quads (textured to look like circle). But when he drags mouse faster there appears spacings between quads. So I calculate distance between previous point and current point, and if its bigger than something I need to add more quads to that distance automatically. How can I do that? I'm using vertex array.

Code:
int count = [vertices count] * 8;
GLVertices = (GLfloat *)malloc(count * sizeof(GLfloat));
int currIndex = 0;
for (NSValue *locationValuetl in vertices) {
CGPoint loc = locationValuetl.pointValue;
GLVertices[currIndex++] = loc.x;
GLVertices[currIndex++] = loc.y;

}
for (NSValue *locationValuetr in vertices) {
CGPoint loc = locationValuetr.pointValue;
GLVertices[currIndex++] = loc.x;
GLVertices[currIndex++] = loc.y;
}
for (NSValue *locationValuell in vertices) {
CGPoint loc = locationValuell.pointValue;
GLVertices[currIndex++] = loc.x;
GLVertices[currIndex++] = loc.y;
}
for (NSValue *locationValuelr in vertices) {
CGPoint loc = locationValuelr.pointValue;
GLVertices[currIndex++] = loc.x;
GLVertices[currIndex++] = loc.y;
}
int distance1 = sqrt(GLVertices[currIndex - 1]*GLVertices[currIndex - 9] + GLVertices[currIndex]*GLVertices[currIndex - 8]);
if (distance1 > brushSize/4) {
//need to do something here


Image of current result:

Can someone help me?

2042
Like
1Likes
Like

Posted 18 July 2012 - 08:47 AM

So I calculate distance between previous point and current point, and if its bigger than something I need to add more quads to that distance automatically.

Uh.....call your draw function for the space in between each brush...

You know how to draw quads. You know how to draw multiple quads. It sounds like you can draw a few more....

### #3hockeyman  Members

130
Like
0Likes
Like

Posted 19 July 2012 - 01:57 AM

I can, but I don't know how to do it in this situation. Because my vertex array object depends on user actions. I mean, points are being added wherever user drags pressed mouse. So I don't know how to tell my program where to draw these additional quads if distance is bigger than something.

If last two quads vertexes in my vertex array is
(x1,y1)[top left]
(x2,y2)[top right]
(x3,y3)[bottom right]
(x4,y4)[bottom left]


and
(x5,y5)[top left]
(x6,y6)[top right]
(x7,y7)[bottom right]
(x8,y8)[bottom left]


and distance between them is bigger than my allowed size (lets say I'm counting distance between [bottom right] points to know the distance between quads), then how to add for example 3 quads (12 vertexes) to my vertex array where they are needed (between these two quads)? I cant't know where user will be drawing, so I don't know exactly where additional quads will be needed.

Edited by hockeyman, 19 July 2012 - 01:58 AM.

2042
Like
1Likes
Like

Posted 19 July 2012 - 08:46 AM

I cant't know where user will be drawing

Based on your drawing you are trying to fill the points between the last brush position and the current. So you know where the user is drawing.

The only way to fix this is to draw a brush for each pixel in between the circles. If you use a distance bigger than that you won't get a brush stroke, you will get more of a caterpillar looking brush, like the medium drawing you posted.

### #5hockeyman  Members

130
Like
0Likes
Like

Posted 20 July 2012 - 01:25 AM

The only way to fix this is to draw a brush for each pixel in between the circles.

How to do it? Is there any tutorials or some useful documentation/information on the internet or something?

Edited by hockeyman, 20 July 2012 - 01:25 AM.

2042
Like
1Likes
Like

Posted 20 July 2012 - 10:02 AM

Simple way without using a line drawing algorithm like Bresenham:

Create a 2D vector between start and end brush.
Find the length in pixels of that line using pythagorean theorem.
float timeStep = 1.0/length in pixels
float time = 0;
for(int i = 0; i < length in pixels; i++)
{
Vec2 fillPos = start + time*brushvector;
time += timeStep;
}

When time = 1, the fill pos is the endpoint
When time = .5, the fill pos is halfway to the endpoint

Edited by dpadam450, 20 July 2012 - 10:03 AM.

### #7hockeyman  Members

130
Like
0Likes
Like

Posted 26 July 2012 - 04:10 AM

Many many thanks for you. Just met the problem that as I see vectors aren't built-in in Objective-c. Maby you can suggest any library for it? And another question. Now with your code I have path witch should be filled. How could I do it? Any openGL commands or something to tell it to draw quads in every location from point A to point B?

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.