|
I got two questions. First I'm making a brick game. I want the ball to bounce off the paddle at different angles depending on where the ball hits the paddle. If the angle variable is specified directly it bounces off in the correct angle but I'm not sure how to calculate the angle depending on where the ball hits the paddle.
double a = 135;
double angle = (Math::PI / 180) * a;
Ball_List[b]->xVel = speed*Math::Cos(angle);
Ball_List[b]->yVel = -speed*Math::Sin(angle);
Second. I want to animate a box going in a circle but I'm Not sure on the math.
Thanks in advance.
|
|
|
|
|
Cyclone_S wrote: I want the ball to bounce off the paddle at different angles depending on where the ball hits the paddle
That is pretty vague, and probably not according to normal physics.
Maybe what you want is: the outgoing angle equals the supplement of the incoming angle plus some delta, which is zero in the center and grows when the hit point is away from the center; so maybe calculate that distance and use it to add to or multiply the outgoing angle.
Cyclone_S wrote: going in a circle
the equations for a circle in two dimensional space are:
(x - xc)^2 + (y - yc)^2 = r^2
or
x = xc + r * cos(a)
y = yc + r * sin(a)
where (x,y) is a point on the circle, (xc,yc) is the center, r the radius, a an angle in radians.
I cannot believe you would not know that. Look at the equations, they say the point(x,y) is at a fixed distance r from a fixed point (xc,yc).
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
modified on Tuesday, May 31, 2011 9:17 PM
|
|
|
|
|
Luc Pattyn wrote: I cannot believe you would not know that.
Just out of curiosity, why would you assume he would know?
"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
|
|
|
|
|
Assuming he is adolescent or older, he would have learned this and much more at school, both as formula's for describing a circle, and as a geometric illustration for explaining what a sine and cosine actually are. He already was using angles, sine and cosine, in his post, so it puzzles me how he would not come up with the equations if he had ever seen and understood them.
And then there are books, and Google, and Wolfram, etc.
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
|
|
|
|
|
Thanks for the replies. Both problems are mostly solved. I have the paddle/ball equation figured out but I'm having a problem where any value less then 1 is ignored... any ideas? I need finer precision. Thanks.
|
|
|
|
|
Cyclone_S wrote: I need finer precision
then scale it all up in integers; or use floating-point arithmetic throughout.
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 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?
|
|
|
|