Skip to main content
reversed drag direction in manual lerp calculation
Source Link
Jon
  • 3.7k
  • 1
  • 13
  • 23

Re:

"It Works great, Thank you. There is one little issue i'm trying to solve, and its how to get a full line in case we have quick movements (saw some examples online, non of them work but using an array of brushes and drawing them, which kills the CPU), it's in the example i gave in the comments above. How did u solve it?"

I use a different language and software, so the code below is more psuedocode, than code. You will need to properly type the position parameter of doIt, etc. The idea should be "gettable"; if not, let me know. initialPoint is set to true in the TouchDown callback (or possibly TouchUp).

Consider:

void doIt(position)
{
  brush->setPosition(position);
  brush->setVisible(true);
  brush->visit(); 
  brush->setVisible(false);
}
void PaintingScene::ccTouchesMoved(CCSet* touches, CCEvent* event)
{
   RT_currentSession->begin(); //RT_currentSession : CCRenderTexture
   touchLocation = touch->getLocation();
   if (initialPoint)
   {
     previousTouchLocation = touchLocation;
     initialPoint = false;
   }
   dragDistance = distance(touchLocation - previousTouchLocation);
   for (i = 0; i <= dragDistance; i++)
   {
     //doIt(previousTouchLocation + ((previousTouchLocationtouchLocation - touchLocationpreviousTouchLocation) * (float)i / dragDistance)));
     //doIt(lerp(previousTouchLocation, touchLocation, (float)i / dragDistance));
     doIt(lerp(previousTouchLocation, touchLocation, i, dragDistance));
     //Linearly interpolate between previousTouchLocation and touchLocation
     //turning on each pixel along the way
   }
   RT_currentSession->end();
   previousTouchLocation = touchLocation;
}

Re:

"It Works great, Thank you. There is one little issue i'm trying to solve, and its how to get a full line in case we have quick movements (saw some examples online, non of them work but using an array of brushes and drawing them, which kills the CPU), it's in the example i gave in the comments above. How did u solve it?"

I use a different language and software, so the code below is more psuedocode, than code. You will need to properly type the position parameter of doIt, etc. The idea should be "gettable"; if not, let me know. initialPoint is set to true in the TouchDown callback (or possibly TouchUp).

Consider:

void doIt(position)
{
  brush->setPosition(position);
  brush->setVisible(true);
  brush->visit(); 
  brush->setVisible(false);
}
void PaintingScene::ccTouchesMoved(CCSet* touches, CCEvent* event)
{
   RT_currentSession->begin(); //RT_currentSession : CCRenderTexture
   touchLocation = touch->getLocation();
   if (initialPoint)
   {
     previousTouchLocation = touchLocation;
     initialPoint = false;
   }
   dragDistance = distance(touchLocation - previousTouchLocation);
   for (i = 0; i <= dragDistance; i++)
   {
     //doIt(previousTouchLocation + ((previousTouchLocation - touchLocation) * (float)i / dragDistance)));
     //doIt(lerp(previousTouchLocation, touchLocation, (float)i / dragDistance));
     doIt(lerp(previousTouchLocation, touchLocation, i, dragDistance));
     //Linearly interpolate between previousTouchLocation and touchLocation
     //turning on each pixel along the way
   }
   RT_currentSession->end();
   previousTouchLocation = touchLocation;
}

Re:

"It Works great, Thank you. There is one little issue i'm trying to solve, and its how to get a full line in case we have quick movements (saw some examples online, non of them work but using an array of brushes and drawing them, which kills the CPU), it's in the example i gave in the comments above. How did u solve it?"

I use a different language and software, so the code below is more psuedocode, than code. You will need to properly type the position parameter of doIt, etc. The idea should be "gettable"; if not, let me know. initialPoint is set to true in the TouchDown callback (or possibly TouchUp).

Consider:

void doIt(position)
{
  brush->setPosition(position);
  brush->setVisible(true);
  brush->visit(); 
  brush->setVisible(false);
}
void PaintingScene::ccTouchesMoved(CCSet* touches, CCEvent* event)
{
   RT_currentSession->begin(); //RT_currentSession : CCRenderTexture
   touchLocation = touch->getLocation();
   if (initialPoint)
   {
     previousTouchLocation = touchLocation;
     initialPoint = false;
   }
   dragDistance = distance(touchLocation - previousTouchLocation);
   for (i = 0; i <= dragDistance; i++)
   {
     //doIt(previousTouchLocation + ((touchLocation - previousTouchLocation) * (float)i / dragDistance)));
     //doIt(lerp(previousTouchLocation, touchLocation, (float)i / dragDistance));
     doIt(lerp(previousTouchLocation, touchLocation, i, dragDistance));
     //Linearly interpolate between previousTouchLocation and touchLocation
     //turning on each pixel along the way
   }
   RT_currentSession->end();
   previousTouchLocation = touchLocation;
}
deleted 4 characters in body
Source Link
Jon
  • 3.7k
  • 1
  • 13
  • 23

Re:

"It Works great, Thank you. There is one little issue i'm trying to solve, and its how to get a full line in case we have quick movements (saw some examples online, non of them work but using an array of brushes and drawing them, which kills the CPU), it's in the example i gave in the comments above. How did u solve it?"

I use a different language and software, so the code below is more psuedocode, than code. You will need to properly type the position parameter of doIt, etc. The idea should be "gettable"; if not, let me know. initialPoint is set to true in the TouchDown callback (or possibly TouchUp).

Consider:

void doIt(position)
{
  brush->setPosition(position);
  brush->setVisible(true);
  brush->visit(); 
  brush->setVisible(false);
}
void PaintingScene::ccTouchesMoved(CCSet* touches, CCEvent* event)
{
   RT_currentSession->begin(); //RT_currentSession : CCRenderTexture
   touchLocation = touch->getLocation();
   if (initialPoint)
   {
     previousTouchLocation = touchLocation;
     initialPoint = false;
   }
   dragDistance = distance(touchLocation - previousTouchLocation);
   for (i = 0; i <= dragDistance; i++)
   {
     //doIt(previousTouchLocation + ((previousTouchLocation - touchLocation) * (float)i / dragDistance)));
     //doIt(lerp(previousTouchLocation, touchLocation, (float)i, / dragDistance));
 - 1   doIt(lerp(previousTouchLocation, touchLocation, i, dragDistance));
     //Linearly interpolate between previousTouchLocation and touchLocation
     //turning on each pixel along the way
   }
   RT_currentSession->end();
   previousTouchLocation = touchLocation;
}

Re:

"It Works great, Thank you. There is one little issue i'm trying to solve, and its how to get a full line in case we have quick movements (saw some examples online, non of them work but using an array of brushes and drawing them, which kills the CPU), it's in the example i gave in the comments above. How did u solve it?"

I use a different language and software, so the code below is more psuedocode, than code. You will need to properly type the position parameter of doIt, etc. The idea should be "gettable"; if not, let me know. initialPoint is set to true in the TouchDown callback (or possibly TouchUp).

Consider:

void doIt(position)
{
  brush->setPosition(position);
  brush->setVisible(true);
  brush->visit(); 
  brush->setVisible(false);
}
void PaintingScene::ccTouchesMoved(CCSet* touches, CCEvent* event)
{
   RT_currentSession->begin(); //RT_currentSession : CCRenderTexture
   touchLocation = touch->getLocation();
   if (initialPoint)
   {
     previousTouchLocation = touchLocation;
     initialPoint = false;
   }
   dragDistance = distance(touchLocation - previousTouchLocation);
   for (i = 0; i <= dragDistance; i++)
   {
     doIt(lerp(previousTouchLocation, touchLocation, i, dragDistance - 1));
     //Linearly interpolate between previousTouchLocation and touchLocation
     //turning on each pixel along the way
   }
   RT_currentSession->end();
   previousTouchLocation = touchLocation;
}

Re:

"It Works great, Thank you. There is one little issue i'm trying to solve, and its how to get a full line in case we have quick movements (saw some examples online, non of them work but using an array of brushes and drawing them, which kills the CPU), it's in the example i gave in the comments above. How did u solve it?"

I use a different language and software, so the code below is more psuedocode, than code. You will need to properly type the position parameter of doIt, etc. The idea should be "gettable"; if not, let me know. initialPoint is set to true in the TouchDown callback (or possibly TouchUp).

Consider:

void doIt(position)
{
  brush->setPosition(position);
  brush->setVisible(true);
  brush->visit(); 
  brush->setVisible(false);
}
void PaintingScene::ccTouchesMoved(CCSet* touches, CCEvent* event)
{
   RT_currentSession->begin(); //RT_currentSession : CCRenderTexture
   touchLocation = touch->getLocation();
   if (initialPoint)
   {
     previousTouchLocation = touchLocation;
     initialPoint = false;
   }
   dragDistance = distance(touchLocation - previousTouchLocation);
   for (i = 0; i <= dragDistance; i++)
   {
     //doIt(previousTouchLocation + ((previousTouchLocation - touchLocation) * (float)i / dragDistance)));
     //doIt(lerp(previousTouchLocation, touchLocation, (float)i / dragDistance));
     doIt(lerp(previousTouchLocation, touchLocation, i, dragDistance));
     //Linearly interpolate between previousTouchLocation and touchLocation
     //turning on each pixel along the way
   }
   RT_currentSession->end();
   previousTouchLocation = touchLocation;
}
Source Link
Jon
  • 3.7k
  • 1
  • 13
  • 23

Re:

"It Works great, Thank you. There is one little issue i'm trying to solve, and its how to get a full line in case we have quick movements (saw some examples online, non of them work but using an array of brushes and drawing them, which kills the CPU), it's in the example i gave in the comments above. How did u solve it?"

I use a different language and software, so the code below is more psuedocode, than code. You will need to properly type the position parameter of doIt, etc. The idea should be "gettable"; if not, let me know. initialPoint is set to true in the TouchDown callback (or possibly TouchUp).

Consider:

void doIt(position)
{
  brush->setPosition(position);
  brush->setVisible(true);
  brush->visit(); 
  brush->setVisible(false);
}
void PaintingScene::ccTouchesMoved(CCSet* touches, CCEvent* event)
{
   RT_currentSession->begin(); //RT_currentSession : CCRenderTexture
   touchLocation = touch->getLocation();
   if (initialPoint)
   {
     previousTouchLocation = touchLocation;
     initialPoint = false;
   }
   dragDistance = distance(touchLocation - previousTouchLocation);
   for (i = 0; i <= dragDistance; i++)
   {
     doIt(lerp(previousTouchLocation, touchLocation, i, dragDistance - 1));
     //Linearly interpolate between previousTouchLocation and touchLocation
     //turning on each pixel along the way
   }
   RT_currentSession->end();
   previousTouchLocation = touchLocation;
}