English 中文(简体)
C++ Ball Bouncing in the rhombus
原标题:C++ Ball Bouncing in the rhombus

I made a simple ball bouncing program with VC++.
the goal of this program is that ball must bounce in the rhombus. it cannot go out of rhombus.
It seems that it runs successfully, but in the left and right corner, it stuck.
How to resolve this problem? I think the condition of equlation is duplicated when the ball is going to left and right corner...
Can you suggest other algorithm for solve this problem?
i tried to make this problem like
while(!isInside(getNextPos(circle))) { updateDirectionVector(circle); }
but I cannot do like this because a random value has changed in everytime. (Used Timer to repeat)
This is algorithm of this program which is worked except at the corner.

up:
while(1) goDownSideCircle;
if(StuckOnDownSide) goto down;
down:
while(1) goUpSideCircle;
if(StuckOnUpSide) goto up;
最佳回答

Problem Solved.
Solved Algorithm:

    RandValue;
    while(1){
    DrawCircle(Center_X,Center_Y);
    Center_X+=Rand_X; Center_Y+=Rand_Y;
    check=false;
    Check_X=Center_X; Check_Y=Center_Y;
    while(BorderCheck){
    RandValue;
    Check_X+=Rand_X; Check_Y+=Rand_Y;
    check=true;}
    if(check){
    Center_X=Check_X; Center_Y=Check_Y;}}
问题回答

暂无回答




相关问题
how to reliable capture display setting changed

static void Main() { // Set the SystemEvents class to receive event notification when a user // when display settings change. SystemEvents.DisplaySettingsChanged += new ...

Why use CComBSTR instead of just passing a WCHAR*?

I m new to COM. What exactly is the advantage of replacing: L"String" with CComBSTR(L"String") I can see a changelist in the COM part of my .NET application where all strings are replaced in this ...

COM Basic links

folks can you provide me the tutorial link or .pdf for learning basic COM?. i do google it.. still i recommend answers of stackoverflow so please pass me.. Thanks

Statically linking Winsock?

I m using Winsock 1.1 in my project. I include wsock32.lib in "Additional Dependencies". I m looking at the DLL project using depends.exe and notice that the DLL depends on wsock32.dll. How can I ...

热门标签