Hi All,
Hope you all doing great
I am trying to improve part of my code as the current one causing memory leaks in some of the device (older ones), not only that but I did not make use of code best practice.
Basically I have a method that tracks the location (x,y) of your finger on the screen and it works fine. The x and y coordinates are float numbers in the range [-1,1].
I am currently drawing the circle at the finger location as follows:
This 'onDrawFrame' method is constantly called by the system and the result on the screen is a circle following your finger BUT there's lot going in the constructor and calling it several times in a loop like this can only cause problems.
What I have done now is to only instantiate this circle at initialization and use a translate matrix to project/move this circle around.
Here's what I have now:
This new approach works well and seems to solve the memory leak issue but I have another proplem I am trying to solve now. It's an algorithmic problem. First to make things simple I have not posted the definition of the constructor and the positionCircle method. If you don't mind let's assume the above method works fine.
Here's the problem:
The circle is constantly translated given that the 'onDrawFrame' is continuously called (not sure maybe 60fps or less). The initial position of the circle is the center of the screen (0.0f, 0.0f).
I need help deriving an algorithm solving this. It should be pretty simple but as you know the smallest thing can mess up you mind sometimes.
Let's say you drag your finger/circle from (0,0) to (3,5). I am using integers here to make the reasoning simple.
The 'CurrentFingerPosition.x' will have values: 0,1,2,3 and CurrentFingerPosition.y values: 0,1,2,3,4,5.
That means when the 'positionCircle' method is called the circle will be translated by those value and will keep translating them by (3,5) till a new (x,y) value of 'CurrentFingerPosition' is detected when I drag the circle again.
What I would want in the above example is once the circle is in the new location (3,5) it should stay there until I move it again in a new location. The circle should follow the location of your finger (CurrentFingerPosition.x, CurrentFingerPosition.y).
The first approach was simple as I was re-setting the circle location before a new translation.
I guess I need to use a similar one.
I have talked enough! I can give more details if needed.
Any help/comment will be appreciated!
Eric
Hope you all doing great
I am trying to improve part of my code as the current one causing memory leaks in some of the device (older ones), not only that but I did not make use of code best practice.
Basically I have a method that tracks the location (x,y) of your finger on the screen and it works fine. The x and y coordinates are float numbers in the range [-1,1].
I am currently drawing the circle at the finger location as follows:
Code:
Circle circle;
@Override
public void onDrawFrame(GL10 gl)
{
...
circle = new Circle(CurrentFingerPosition.x, CurrentFingerPosition.y);
circle.draw();
...
}
What I have done now is to only instantiate this circle at initialization and use a translate matrix to project/move this circle around.
Here's what I have now:
Code:
Circle circle;
@Override
public void onSurfaceCreated(GL10 gl, EGLConfig config)
{
//...
circle = new Circle();
//...
}
@Override
public void onDrawFrame(GL10 gl)
{
//...
positionCircle(CurrentFingerPosition.x, CurrentFingerPosition.y); // this returns 'modelMatrix'
circle.draw(modelMatrix);
//...
}
Here's the problem:
The circle is constantly translated given that the 'onDrawFrame' is continuously called (not sure maybe 60fps or less). The initial position of the circle is the center of the screen (0.0f, 0.0f).
I need help deriving an algorithm solving this. It should be pretty simple but as you know the smallest thing can mess up you mind sometimes.
Let's say you drag your finger/circle from (0,0) to (3,5). I am using integers here to make the reasoning simple.
The 'CurrentFingerPosition.x' will have values: 0,1,2,3 and CurrentFingerPosition.y values: 0,1,2,3,4,5.
That means when the 'positionCircle' method is called the circle will be translated by those value and will keep translating them by (3,5) till a new (x,y) value of 'CurrentFingerPosition' is detected when I drag the circle again.
What I would want in the above example is once the circle is in the new location (3,5) it should stay there until I move it again in a new location. The circle should follow the location of your finger (CurrentFingerPosition.x, CurrentFingerPosition.y).
The first approach was simple as I was re-setting the circle location before a new translation.
I guess I need to use a similar one.
I have talked enough! I can give more details if needed.
Any help/comment will be appreciated!
Eric
Last edited: