|
I am using doubles in the function. The problem is I can't move the panel(ball) anything less then 1 pixel. Maybe move the ball 1pixel over a couple of frames? I'm not sure how to do that.
Here is the code.
int speed=Ball_List[b]->speed;
int paddle_center = Player->Location.X + Player->Width / 2;
int ball_center = Ball_List[b]->gameBall->Location.X + Ball_List[b]->gameBall->Width / 2;
int paddle_location = ball_center - paddle_center;
double a=(90-paddle_location);
double angle = (Math::PI / 180) * a;
Ball_List[b]->xVel = speed*Math::Cos(angle);
Ball_List[b]->yVel = -speed*Math::Sin(angle);
Ball_List[b]->gameBall->Top = Player->Location.Y - 16;
Thanks
|
|
|
|
|
All of that could have been floats or doubles; it is only when painting that it eventually needs to be rounded to pixels, hence integers.
Luc Pattyn [My Articles] Nil Volentibus Arduum
The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Please use <PRE> tags for code snippets, they improve readability. CP Vanity has been updated to V2.4
|
|
|
|
|
so there's no solution then?
|
|
|
|
|
You might want to check out this site[Physics engines for dummies] for an easy introduction into the basics of vector algebra used to emulate quasi-physical simulations. You will find that in stead of angles and sinus/cosinus it explains the calculations needed for reflections with the help of vector algebra. Although the code is not C/C++ it should be easy enough to translate the relevant code for your problems.
|
|
|
|
|
Hello,
In several posts I have read that Garbage Collector and Reference counter are not same? I wanted to know how?
Regards
|
|
|
|
|
|
Reference counting is one (of many) mechanisms to implement garbage collection.
Watched code never compiles.
|
|
|
|
|
Strictly speaking, reference counting is a technique for implementing garbage collection.
In practice, term "Garbage Collector" usually implies non-deterministic cleanup and that rules out reference counting. In other words, with (automatic) reference counting there is no garbage to be collected: an object gets released at the moment the last reference to it goes out of scope.
|
|
|
|
|
GC is a form of global memory management that keeps track of memory resources and returns freed memory at undefined intervals. For performance reasons, GC often does not immediately return freed memory, but instead just marks it as freed later.
RC is a method to locally ensure that an object is freed as soon as it isn't needed anymore. It determines this by keeping count of the references to the object that have been handed out.
In a way you coud consider RC as a very localized GC. Also, as has been pointed out, RC is often used to implement a GC and find out which memory blocks may be released.
GC has better overall performance, but may lead to heavier use of memory. Using only RC keeps the memory footprint at a minimum, but is somewhat slower.
|
|
|
|
|
Hello,
I wanted to know what is difference between Unicode and Multi-byte character.
Regards
|
|
|
|
|
If you want to know something, you come up with a good subject line (you have), and then give that to Google. It will provide you with good answers.
Luc Pattyn [My Articles] Nil Volentibus Arduum
The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Please use <PRE> tags for code snippets, they improve readability. CP Vanity has been updated to V2.3
|
|
|
|
|
I googled on this topic. I got programming example. But I want theoretical topic or at least one line which shows difference between Unicode and Multibye.
|
|
|
|
|
Multibyte, or wide character, refers to the size of the datatype in memory, not how each value is defined. Unicode, however, is a character set that provides that definition.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Some people are making such thorough preparation for rainy days that they aren't enjoying today's sunshine." - William Feather
|
|
|
|
|
|
This is OK. But it doesn't show difference between Unicode and Multi-byte char.
|
|
|
|
|
Character sets descended from ASCII that are described in the "A Historical Perspective" section are multi-byte.
|
|
|
|
|
Lots of detail about this can be found in this white paper[^].
The best things in life are not things.
|
|
|
|
|
Unicode is a vast specification covering many things. Encluding serveral representations of some very broad (many natural languages) character sets.
There are also associated encodings for those character sets.
Some encodings have a fixed size and some are variable.
A variable size encoding has some byte sequences which represent specific characters and other byte sequences which are used as flags to indicate that additional bytes are needed to determine the actual character.
A multi-byte character set might either mean a fixed size representation of a character set but normally means a variable sized encoding which started with a single byte for the initial encoding. UTF8 is a variable sized encoding and can thus also be considered a multibyte character set.
For coverage of this specific point see the following
http://en.wikipedia.org/wiki/Multi-byte_character_set#Unicode_variable-width_encodings[^]
|
|
|
|
|
I have to develop an application that captures a portion of the desktop every 30 seconds, after viewing the captured image in the window of application, should find (and then highlight) which regions of the new image have changed compared to the previous image.
Ok, so:
HDC memDC;
memDC = CreateCompatibleDC( GetDC(hWnd) );
WM_TIMER:
InvalidateRect(...)
WM_PAINT:
hdc = BeginPaint(...);
screenDC = GetDC(0);
hBmp = CreateCompatibleBitmap(hdc, nWidth, nHeight );
hPrevBmp = SelectObject(memDC,hBmp);
BitBlt(memDC, ..., screenDC, ...);
BitBlt(hdc, ..., memDC, ...);
How can i compare the two image?
|
|
|
|
|
Member 2965471 wrote: How can i compare the two image?
Read here.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Some people are making such thorough preparation for rainy days that they aren't enjoying today's sunshine." - William Feather
|
|
|
|
|
I've only understand i've to perform a XORing operation between the two image, but how can i do that? and then how can i highlight rectangular region modified? using GetPixel?
|
|
|
|
|
Hi all,
I am trying to find floppy drive in logical drives.
I am using GetDriveType() function, but it is returning DRIVE_REMOVABLE which for both flash drives and floppy drives.
How can i find this??
Thanks in advance
|
|
|
|
|
How To Getting Floppy Drive Type Information->[^]
"Every Little Smile can touch Somebody's Heart...
May we find Hundreds of Reasons to Smile Everyday... and
May WE be the Reason for someone else to smile always!" (ICAN)
"Your thoughts are the architects of your destiny."
|
|
|
|
|
VCProgrammer wrote: How can i find this??
How about something like:
bool isFloppyDevice( LPCTSTR lpszDevice )
{
TCHAR szBuffer[MAX_PATH];
bool bIsFloppy = false;
if (QueryDosDevice(lpszDevice, szBuffer, MAX_PATH) > 0)
bIsFloppy = (_tcsstr(_T("device\\floppy"), szBuffer) != NULL);
return bIsFloppy;
} A slightly longer way, although I cannot test it, might be:
bool isFloppyDevice( void )
{
bool bIsFloppy = false;
HANDLE hDevice = CreateFile(_T("\\\\.\\A:"),
0,
0,
NULL,
OPEN_EXISTING,
0,
NULL);
if (hDevice != INVALID_HANDLE_VALUE)
{
DISK_GEOMETRY dg;
DWORD dwBytesReturned;
bIsFloppy = (DeviceIoControl(hDevice,
IOCTL_DISK_GET_DRIVE_GEOMETRY,
NULL,
0,
&dg,
sizeof(dg),
&dwBytesReturned,
NULL) != FALSE);
CloseHandle(hDevice);
}
return bIsFloppy;
}
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Some people are making such thorough preparation for rainy days that they aren't enjoying today's sunshine." - William Feather
|
|
|
|
|
Hi:
I have a socket client running which has a char array of size 512 mentioned. I have a loop to receive the message from the server, when the loop exits I am getting the following error.
I also confirmed that the message I am receiving from the server is less than 200 characters in length.
Environment:
Windows 64bit.
VS 2010
Run-Time check failure #2 - Stack around the variable 'recMessage' was corrupted.
int STRLEN = 512;
char recMessage[STRLEN] = "0";
ClientSocket sockClient;
sockClient.ConnectToServer( ipAddress.c_str(), port );
sockClient.SendData("L|100=some_value;101=some_value\n");
sockClient.RecvData( recMessage, STRLEN );
int counter = 0
while(counter <= 10){
sockClient.RecvData( recMessage, STRLEN );
cout << recMessage << endl;
counter++;
}
memset(recMessage,0,sizeof(char)*STRLEN);
sockClient.CloseConnection();
</pre>
|
|
|
|