[FIXED] Convert c/c++ [For : Next] to PB

Just starting out? Need help? Post your questions and find answers here.
CodeCave
User
User
Posts: 16
Joined: Wed Jun 19, 2013 10:50 pm

[FIXED] Convert c/c++ [For : Next] to PB

Post by CodeCave »

I want to convert this code to PB but i dont get it right...
Mby someone sees what im doing wrong here :)

Code:

Code: Select all

void cDraw::Circle(int X, int Y, int radius, int sides, int a, int r, int g, int b)
{
    D3DXVECTOR2 Line[128];
    float Step = Math.GetPI() * 2.0 / sides;
    int Count = 0;
    for (float index=0; index < Math.GetPI() *2.0; index += Step)
    {
        float X1 = radius * cos(index) + X;
        float Y1 = radius * sin(index) + Y;
        float X2 = radius * cos(index+Step) + X;
        float Y2 = radius * sin(index+Step) + Y;
        Line[Count].x = X1;
        Line[Count].y = Y1;
        Line[Count+1].x = X2;
        Line[Count+1].y = Y2;
        Count += 2;
    }
    pLine->Begin();
    pLine->Draw(Line,Count,D3DCOLOR_ARGB(a,r,g,b));
    pLine->End();
}
My Code:

Code: Select all

Global pi = 3.14159265

Procedure D3D_Circle(x.f,y.f,radius.f,parts.l,color.l)
  Dim vLine.D3DXVECTOR2(128)
  steps.f = (pi*2)/parts
  pos = 0
  For i = 0 To 128 Step steps ;<- CANT GET THIS RIGHT
    x1.f = radius * Cos(i) + x
    y1.f = radius * Sin(i) + y
    x2.f = radius * Cos(i+steps) + x
    y2.f = radius * Sin(i+steps) + y
    vLine(pos)\x = x1
    vLine(pos)\y = y1
    vLine(pos+1)\x = x2
    vLine(pos+1)\y = y2
    pos = pos + 2
  Next
  *D3Dline\Begin()
  *D3Dline\Draw(@vLine(0), 128, color)
  *D3Dline\End()
EndProcedure
How would that Code look in PB ?

Code: Select all

for (float index=0; index < Math.GetPI() *2.0; index += Step)
thx CodeCave
Last edited by CodeCave on Fri Jun 21, 2013 3:13 pm, edited 1 time in total.
Deluxe0321
User
User
Posts: 69
Joined: Tue Sep 16, 2008 6:11 am
Location: ger

Re: [HELP] Convert c/c++ [For : Next] to PB

Post by Deluxe0321 »

Maybe like this?

Code: Select all

;for (float index=0; index < Math.GetPI() *2.0; index += Step)
index.f = 0
_step.f = 2.0 * #PI
While index.f  <  _step.f
  index + _step.f  
Wend
CodeCave
User
User
Posts: 16
Joined: Wed Jun 19, 2013 10:50 pm

Re: [HELP] Convert c/c++ [For : Next] to PB

Post by CodeCave »

Thx 4 the fast help got it working :)

Thats how it looks now:

Code: Select all

Procedure D3D_Circle(x.f,y.f,radius.f,parts.f,color.l)
  Dim vLine.D3DXVECTOR2(1)
  *D3DLine\SetAntialias(#False)
  *D3DLine\SetGLLines(#True)
  x = x + radius
  y = y + radius
  index.f = 0
  _step.f = 2.0 * #PI
  _parts.f = _step / parts
  pos.l = 0
  While index  <  _step
    index = index + _parts
    x1.f = radius * Cos(index) + x
    y1.f = radius * Sin(index) + y
    x2.f = radius * Cos(index+_parts) + x
    y2.f = radius * Sin(index+_parts) + y
    vLine(pos)\x = x1
    vLine(pos)\y = y1
    vLine(pos+1)\x = x2
    vLine(pos+1)\y = y2
    pos = pos + 2
    ReDim vLine.D3DXVECTOR2(pos+1)
  Wend
  *D3DLine\Begin()
  *D3DLine\Draw(@vLine(0), pos, color)
  *D3DLine\End()
EndProcedure
Post Reply