Click here to Skip to main content
15,921,837 members
Home / Discussions / Algorithms
   

Algorithms

 
GeneralRe: Weighted Decision Pin
Mark J. Miller14-Mar-07 9:59
Mark J. Miller14-Mar-07 9:59 
GeneralRe: Weighted Decision Pin
Mark J. Miller14-Mar-07 10:18
Mark J. Miller14-Mar-07 10:18 
QuestionPi Day Pin
ricecake14-Mar-07 3:32
ricecake14-Mar-07 3:32 
AnswerRe: Pi Day Pin
Shog914-Mar-07 5:03
sitebuilderShog914-Mar-07 5:03 
GeneralRe: Pi Day Pin
ricecake14-Mar-07 5:08
ricecake14-Mar-07 5:08 
AnswerRe: Pi Day Pin
Dan Neely14-Mar-07 5:15
Dan Neely14-Mar-07 5:15 
QuestionMatlab help Pin
ashee rai11-Mar-07 14:40
ashee rai11-Mar-07 14:40 
QuestionWMP Visualization help Pin
XTAL2569-Mar-07 23:34
XTAL2569-Mar-07 23:34 
Hi, i am making a Windows Media Player Visualization and i need some help with an algorithm.
I am making a snake like curve that moves around the screen. It uses 3 point bezier curves joined together to form one long curve. The head continually grows while the end disappears. I need to make each new one connect to the old head but my code doesn't work. Here is some of the code:
typedef struct tagBezier{
    float x, y;         // Curve position
    POINTF P0, P1, P2;  // Control points
    float t, t2;        // Time variable [0-1]
} Bezier;

void CViz3D::calculateBezier(Bezier& b, float time) {
    b.t2 = b.t;  b.t = time;

    b.x = (pow(b.P0.x*(1 - b.t),2) + b.P1.x*2*b.t*(1 - b.t) + pow(b.P2.x*b.t,2));
    b.y = (pow(b.P0.y*(1 - b.t),2) + b.P1.y*2*b.t*(1 - b.t) + pow(b.P2.y*b.t,2));
}

void CViz3D::drawBezierCurve(Bezier b[CURVES]) {
    float iStart = 0, iEnd = 1;

    if (b[start].t < b[start].t2) {  // Change position if finished
        int sOld = start;   // Previous start pos
        start = (start+1)%CURVES;
        end = (end+1)%CURVES;
        float distX=b[sOld].P2.x-b[sOld].P1.x, distY=b[sOld].P2.y-b[sOld].P1.y;
        b[start].P0.x = b[sOld].P2.x;       b[start].P0.y = b[sOld].P2.y;
        b[start].P1.x = b[sOld].P2.x+distX; b[start].P1.x = b[sOld].P2.y+distY;
        b[start].P2.x = (RAND-0.5f);        b[start].P2.y = (RAND-0.5f);
    }

    for (int j = 0; j < CURVES; j++) {
        if (j == start) {  iStart = 0;  iEnd = bezTime; }
        else if (j == end){ iStart = bezTime; iEnd = 1; }
        else { iStart = 0; iEnd = 1; }

        glBegin(GL_LINE_STRIP);
        for (float i = iStart; i < iEnd; i += 0.01f) {
            calculateBezier(b[j], i);
            glVertex2f(b[j].x, b[j].y);
        }
        glEnd();
    }
}

Can someone figure out what's going on.
Thanx
AnswerRe: WMP Visualization help Pin
Luc Pattyn9-Mar-07 23:41
sitebuilderLuc Pattyn9-Mar-07 23:41 
GeneralRe: WMP Visualization help Pin
XTAL25610-Mar-07 0:33
XTAL25610-Mar-07 0:33 
GeneralRe: WMP Visualization help Pin
Luc Pattyn10-Mar-07 13:25
sitebuilderLuc Pattyn10-Mar-07 13:25 
GeneralRe: WMP Visualization help Pin
XTAL25610-Mar-07 22:25
XTAL25610-Mar-07 22:25 
GeneralRe: WMP Visualization help Pin
Luc Pattyn10-Mar-07 23:08
sitebuilderLuc Pattyn10-Mar-07 23:08 
GeneralRe: WMP Visualization help Pin
XTAL25611-Mar-07 16:27
XTAL25611-Mar-07 16:27 
GeneralRe: WMP Visualization help Pin
Luc Pattyn12-Mar-07 10:22
sitebuilderLuc Pattyn12-Mar-07 10:22 
GeneralRe: WMP Visualization help Pin
XTAL25612-Mar-07 21:41
XTAL25612-Mar-07 21:41 
QuestionProcessing video frames Pin
Techbear19809-Mar-07 18:42
Techbear19809-Mar-07 18:42 
AnswerRe: Processing video frames Pin
Jarno Burger14-Mar-07 0:05
Jarno Burger14-Mar-07 0:05 
AnswerRe: Processing video frames Pin
Rilhas19-May-07 10:28
Rilhas19-May-07 10:28 
QuestionPIC Pin
Bob X8-Mar-07 5:12
Bob X8-Mar-07 5:12 
AnswerRe: PIC Pin
Rilhas19-May-07 10:32
Rilhas19-May-07 10:32 
GeneralRe: PIC Pin
Bob X20-May-07 10:50
Bob X20-May-07 10:50 
GeneralRe: PIC Pin
Rilhas20-May-07 13:25
Rilhas20-May-07 13:25 
GeneralRe: PIC Pin
Bob X20-May-07 18:00
Bob X20-May-07 18:00 
NewsMock Theta Functions Pin
ricecake28-Feb-07 4:53
ricecake28-Feb-07 4:53 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.