I was reading this topic and I decided to give it a shot. To my astonishment it really seemed easier than what I am making it I guess. I have some confusion about the "DesiredPos" variable. Well at least in my implementation. I am trying to move a window around constantly and have it react like a ball when it hits the monitors edges. Like the ball in the game Pong. I have made programs like this that move the mouse, But I can't seem to get my head around this one.
This is what I have so far, I have limited experience when it comes to a lot of functions in the Windows API. Keep in mind this is a hardcore rough draft.
EDIT I haven't implemented any of the collision detection yet I just wanted to get the moving portion working.
#include <windows.h>
#include <math.h>
int newX(int oldx);
int newY(int oldy);
double SmoothMoveELX(double x);
int main()
{
int lengthInMs = 10*1000;
HWND notepad = FindWindow("Notepad",NULL);
RECT window;
SetTimer(
notepad,
NULL,
30,
(TIMERPROC)NULL
);
int startTime = GetTickCount();
int pos = elap / lengthInMs;
while(1)
{
RECT window;
GetWindowRect(notepad,&window);
int elap = (GetTickCount() - startTime);
if(elap >= lengthInMs)
{
int NEWX = NewX(window.x);
int NEWY = NewY(window.y);
MoveWindow(
notepad,
NEWX,
NEWY,
100,
100,
TRUE
);
}
}
}
int NewX(int oldx)
{
int newx = oldx*(1-SmoothMoveELX(pos))
+ 10 *SmoothMoveELX(pos));
return newx;
}
int newY(int oldy)
{
int newy = oldy*(1-SmoothMoveELX(pos))
+ 10 *SmoothMoveELX(pos));
return newy;
}
double SmoothMoveELX(double x)
{
double PI = Atan(1) * 4;
return ((cos(1 - x) * PI + 1) /2 )
}