Showing posts with label Roulette. Show all posts
Showing posts with label Roulette. Show all posts

7/02/2009

Now, my second app was included some MIDI sounds.

Until I get Android test device, The second app will be like this.

6/17/2009

This will be my second Android game application...

Since, I am trying to complete this application. The application still miss some routines but the routines will be made soon.

6/09/2009

Sphere on my Android emulator...



Both 'setModel()' and 'setModelEX()' methods work with making points of sphere surface. Now I get my drawing sphere routine. I recommend a URL which provides some glut functions that can be used under Android. akjava-android-project

class GLBall {
private int VertexCount, mallocCount;
private FloatBuffer mVertexBuffer;
private FloatBuffer mNormalBuffer;
public float z_angle;
private int slices, stacks;

public GLBall()
{
mVertexBuffer = null;
mNormalBuffer = null;
}

public void setModel(double radius, int lats, int longs)
{
double lat0, z0, zr0, lat1, z1, zr1, lng, x, y;
float normal[];
float vertices[];

int mindex = 0, nindex=0;

VertexCount = (lats+1) * (longs+1) * 2;
mallocCount = VertexCount * 3;

normal = new float[mallocCount];
vertices = new float[mallocCount];

stacks = lats+1;
slices = longs+1;

for(int i = 0; i <= lats; i++) {
lat0 = (double)Math.PI * (-0.5 + (i - 1) / (double)lats);
z0 = (double)Math.sin(lat0) * radius;
zr0 = (double)Math.cos(lat0) * radius;

lat1 = (double)Math.PI * (-0.5 + i / (double)lats);
z1 = (double)Math.sin(lat1) * radius;
zr1 = (double)Math.cos(lat1) * radius;
for(int j = 0; j <= longs; j++) {
lng = 2 * Math.PI * (j - 1) /(double)longs;
x = Math.cos(lng);
y = Math.sin(lng);
normal[nindex++] = vertices[mindex++] = (float)(x * zr0);
normal[nindex++] = vertices[mindex++] = (float)(y * zr0);
normal[nindex++] = vertices[mindex++] = (float)z0;
normal[nindex++] = vertices[mindex++] = (float)(x * zr1);
normal[nindex++] = vertices[mindex++] = (float)(y * zr1);
normal[nindex++] = vertices[mindex++] = (float)z1;
}
}
mVertexBuffer = FloatBuffer.wrap(vertices);
mNormalBuffer = FloatBuffer.wrap(normal);
z_angle = 0.0f;
}

public void setModelEX(float radius, int astacks, int aslices)
{
int i, j, vindex = 0, nindex = 0;
float slicestep, stackstep;

stackstep = ((float)Math.PI) / astacks;
slicestep = 2.0f * ((float)Math.PI) / aslices;

VertexCount = astacks * (aslices+1) * 2;
mallocCount = VertexCount * 3;

float normal[] = new float[mallocCount];
float vertices[] = new float[mallocCount];

for (i = 0; i < astacks; i++)
{
float a = i * stackstep;
float b = a + stackstep;

float s0 = (float)Math.sin(a);
float s1 = (float)Math.sin(b);

float c0 = (float)Math.cos(a);
float c1 = (float)Math.cos(b);

float nv;
for (j = 0; j <= aslices; j++)
{
float c = j * slicestep;
float x = (float)Math.cos(c);
float y = (float)Math.sin(c);

nv=x * s0;
normal[nindex++] = nv;
vertices[vindex++] = nv * radius;

nv=y * s0;
normal[nindex++] = nv;
vertices[vindex++] = nv * radius;

nv=c0;
normal[nindex++] = nv;
vertices[vindex++] = nv * radius;

nv=x * s1;
normal[nindex++] = nv;
vertices[vindex++] = nv * radius;

nv=y * s1;
normal[nindex++] = nv;
vertices[vindex++] = nv * radius;

nv=c1;
normal[nindex++] = nv;
vertices[vindex++] = nv * radius;
}
}
mVertexBuffer = FloatBuffer.wrap(vertices);
mNormalBuffer = FloatBuffer.wrap(normal);
z_angle = 0.0f;

this.stacks = astacks;
this.slices = aslices+1;
}

public void draw(GL10 gl) {
int triangles;
gl.glDisable(GL10.GL_TEXTURE_2D);
gl.glVertexPointer(3, GL10.GL_FLOAT, 0, mVertexBuffer);
gl.glNormalPointer(GL10.GL_FLOAT, 0, mNormalBuffer);

gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
gl.glEnableClientState(GL10.GL_NORMAL_ARRAY);

triangles = slices * 2;
for(int i=0; i < stacks; i++)
gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, i*triangles, triangles);

gl.glDisableClientState(GL10.GL_NORMAL_ARRAY);
gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
gl.glEnable(GL10.GL_TEXTURE_2D);
}
}

5/27/2009

My Mog Roulette game likes this...

Probably, it will be completed in the future or may not.

5/14/2009

Clear screen shot of roulette under OpenGL


One of Nehe's OpenGL tutorials gives me an example how to use. The roulette machine will smoothly spin with OpenGL. but since, this picture means alpha valued image works with OpenGL.

To apply for alpha value


To get a proper alpha valued image, some tasks should be included in the previous list. Thank you for Paul Nicholls, I found FloodFill() routine which can be used with TBitmap32.
The above shown picture is alpha valued image. When the generated image is opened by Gimp, it will be the same as the shown above picture. I include its source.

Click -> available download

5/13/2009

Make my own Roulette image...


Making roulette game will have not an easy task. Probably, the task should be included some mathematic routines. I don't know yet what sort of mathematic should be needed for....
At the moment, I will introduce one method how can make roulette image by Delphi 6 and Graphics32. Of course, there are many ways we can make it by using other development tools. To make an executable file with this source, Delphi 6 Standard and Graphics32 Component should be needed.

Uses
  ..., Math, GR32_Image, GR32; // Add this in Uses

// Conversion double rgb color value to TColor value
Function MakeColor(b, g, r: Double): Integer;
begin
    result := Trunc(r * 255) shl 16 + Trunc(b * 255) shl 8 + Trunc(g * 255);
end;

// In order to display text by angle
procedure TextRotate(bitmap: TBitmap32; x, y, angle: integer; atext: string;afont: TFont);
var
    lf:LogFont;
begin
    //Please Change with your country font, test with a different font to get better result...
    Bitmap.Font.Name := '궁서체';
    Bitmap.Font.Size := 12;
    Windows.GetObject(Bitmap.Font.Handle, sizeof(LOGFONT), @lf);
    lf.lfEscapement := angle * 10;
    lf.lfOrientation := angle * 10;
    Bitmap.Font.Handle := CreateFontIndirect(lf);
    Bitmap.Canvas.Brush.Style := bsClear;
    Bitmap.Textout(x, y, atext);
end;

// Button event for drawing roulette Image
procedure TForm1.BitBtn1Click(Sender: TObject);
{ Draw 1 pixcel width line }
procedure DrawLine(X1, Y1, X2, Y2 : Integer; vBitmap: TBitmap32);
Begin
    { Fill area by drawing lines }
    vBitmap.Canvas.MoveTo(X1,Y1);
    vBitmap.Canvas.LineTo(X2,Y2);
End;

const
    DEG2RAD : double = (3.14159/180);
var
    vBitmap : TBitmap32;
    dAngle, degInRad, dAngleX : Double;
    x1, y1, i, centerx, centery : Integer;
    Color0, Color1, Color2 : Integer;
    Angle, X, Y, H, H2, W, X3 : Integer;
    Step : Real;
    ValueT : Array of String;
begin
    vBitmap := TBitmap32.Create;
    vBitmap.Width := 256;
    vBitmap.Height := 256;
    centerx := 128;
    centery := 128;
    vBitmap.Canvas.Pen.Width := 2;
    vBitmap.Canvas.Pen.Color := MakeColor(0.66, 0.82, 0.82);
    vBitmap.Canvas.Ellipse(10, 10, vBitmap.Width-10, vBitmap.Height-10);
    dAngleX := 360 / 37;
    for i := 0 to 36 do begin
        dAngle := dAngleX * i;
        degInRad := dAngle * DEG2RAD;
        x1 := centerx - trunc(cos(degInRad) * (centerx-10));
        Y1 := centery - trunc(sin(degInRad) * (centery-10));
        vBitmap.Canvas.MoveTo(centerx, centery);
        vBitmap.Canvas.LineTo(X1, Y1);
    end;
    vBitmap.Canvas.Ellipse(40, 40, vBitmap.Width-40, vBitmap.Height-40);

    Color0 := MakeColor(1.0, 0.0, 0.0);
    Color1 := MakeColor(0.0, 1.0, 0.0);
    Color2 := MakeColor(0.0, 0.0, 0.0);
    for i := 0 to 36 do begin
        dAngle := dAngleX * i + 5;
        degInRad := dAngle * DEG2RAD;
        if(i = 0) then
            vBitmap.Canvas.Brush.Color := Color0
        else begin
            if(i mod 2 = 1) then vBitmap.Canvas.Brush.Color := Color1
            else vBitmap.Canvas.Brush.Color := Color2;
        end;
        x1 := centerx - trunc(cos(degInRad) * 110);
        Y1 := centery - trunc(sin(degInRad) * 110);
        vBitmap.Canvas.FloodFill(x1, y1, vBitmap.Canvas.Pen.Color, fsBorder);
    end;
    { Get form size }
    H:=vBitmap.Height;
    W:=vBitmap.Width;

    Angle := 0;
    vBitmap.Canvas.Pen.Color := clBlue;
    while (Angle<360) do begin
        X := centerx - Round(cos(Angle*DEG2RAD) * 88);
        Y := centery - Round(sin(Angle*DEG2RAD) * 88);
        vBitmap.Canvas.Pen.Color:=RGB(255, 255,abs(255-Angle));
        DrawLine(centerx, centery, X, Y, vBitmap);
        Inc(Angle);
    end;

    Angle := 0;
    vBitmap.Canvas.Pen.Color := clBlue;
    while (Angle<360) do begin
        X := centerx - Round(cos(Angle*DEG2RAD) * 48);
        Y := centery - Round(sin(Angle*DEG2RAD) * 48);
        vBitmap.Canvas.Pen.Color:=RGB(abs(255-Angle),abs(255-Angle),abs(255-Angle));
        DrawLine(centerx, centery, X, Y, vBitmap);
        Inc(Angle);
    end;

    vBitmap.Canvas.Brush.Color := RGB($DC, $B4, $8C);
    vBitmap.Canvas.Pen.Color := RGB($DC, $B4, $8C);

    vBitmap.Canvas.Rectangle(126, 128-62, 130, 128+62);
    vBitmap.Canvas.Rectangle(128-62, 126, 128+62, 130);

    vBitmap.Canvas.Rectangle(124, 128-62, 132, 128-22);
    vBitmap.Canvas.Rectangle(124, 128+22, 132, 128+62);
    vBitmap.Canvas.Rectangle(128-62, 124, 128-22, 132);
    vBitmap.Canvas.Rectangle(128+22, 124, 128+62, 132);
    vBitmap.Font.Color := RGB($FF, $FF, $FF);
    vBitmap.Canvas.Brush.Style := bsClear;
    Angle := 90;

    Setlength(ValueT, 37);
    ValueT[0] := '0'; ValueT[1] := '32'; ValueT[2] := '15'; ValueT[3] := '19';
    ValueT[4] := '4'; ValueT[5] := '21'; ValueT[6] := '2'; ValueT[7] := '25';
    ValueT[8] := '17'; ValueT[9] := '34'; ValueT[10] := '6'; ValueT[11] := '27';
    ValueT[12] := '13'; ValueT[13] := '36'; ValueT[14] := '11'; ValueT[15] := '30';
    ValueT[16] := '8'; ValueT[17] := '23'; ValueT[18] := '10'; ValueT[19] := '5';
    ValueT[20] := '24'; ValueT[21] := '16'; ValueT[22] := '33'; ValueT[23] := '1';
    ValueT[24] := '20'; ValueT[25] := '14'; ValueT[26] := '31'; ValueT[27] := '9';
    ValueT[28] := '22'; ValueT[29] := '18'; ValueT[30] := '29'; ValueT[31] := '7';
    ValueT[32] := '28'; ValueT[33] := '12'; ValueT[34] := '35'; ValueT[35] := '5';
    ValueT[36] := '26';
    for i := 0 to 36 do begin
        if(length(ValueT[i]) = 1) Then
            dAngle := dAngleX * i + 3
        else
            dAngle := dAngleX * i;
        degInRad := dAngle * DEG2RAD;
        x1 := centerx - trunc(cos(degInRad) * 110);
        Y1 := centery - trunc(sin(degInRad) * 110);
        TextRotate(vbitmap, x1, y1, Angle, ValueT[i], vBitmap.Font);

        Angle := Angle - 10;
        if(Angle = 0) then Angle := 360;
    end;

    PaintBox01.Canvas.CopyRect(Bounds(0, 0, vBitmap.Width, vBitmap.Height), vBitmap.Canvas,
Bounds(0, 0, vBitmap.Width, vBitmap.Height));
    vBitmap.SaveToFile('image.bmp');
    vBitmap.Free;
end;