Results 1 to 3 of 3

Thread: Spheroid in DelphiX ?

  1. #1

    Spheroid in DelphiX ?

    Please how I simply create spheroid (or sphere)? Like as textured 3D rotation cube in samples DelphiX.
    Thanks.
    Ijcro.

  2. #2

    Spheroid in DelphiX ?

    Hi,

    Just try something like this:


    Code:
    const
    NumRings = 25; // bigger values -> better quality
    NumSegments = 25;
    
    // Declare array of Vertexes
    ....................
    s_Vertices: array[0..2 * NumRings * (NumSegments + 1) - 1] of TD3DVertex;
    ...................
    
    
    // Fast assembly Sin and Cos for Single numbers
    
    procedure SinCosS(const Theta: Single; var Sin, Cos: Single); register;
    // EAX contains address of Sin
    // EDX contains address of Cos
    // Theta is passed over the stack
    asm
    FLD Theta
    FSINCOS
    FSTP DWORD PTR [EDX] // cosine
    FSTP DWORD PTR [EAX] // sine
    end;
    
    
    
    
    procedure TMainForm.MakeSpheroid;
    const
    v: TD3DValue = 1.0; // Texture coordinates
    u: TD3DValue = 1.0; // Offset coordinates
    dv: TD3DValue = 0.0;
    du: TD3DValue = 0.0;
    Size: TD3DValue = 1.0; // Sphere size
    var n0: TD3DVector;
    i, ring, seg: integer;
    fDeltaRingAngle,
    fDeltaSegAngle: TD3DValue;
    ss, sc,
    r0, r1,
    x0, x1,
    y0, y1,
    z0, z1: TD3DValue;
    segNumSegmentsU: TD3DValue;
    ringNv: TD3DValue;
    vNumRings: TD3DValue;
    begin
    // Define the normals for the sphere
    n0 := MakeD3DVector(0.0, 1.0, 0.0 );
    
    // Establish constants used in sphere generation
    fDeltaRingAngle := pi / NumRings;
    fDeltaSegAngle := 2 * pi / NumSegments;
    
    i := 0;
    
    vNumRings := v / NumRings;
    
    // Generate the group of rings for the sphere
    for ring := 0 to NumRings - 1 do
    begin
    SinCosS(ring * fDeltaRingAngle, r0, y0);
    SinCosS((ring + 1) * fDeltaRingAngle, r1, y1);
    
    ringNv := ring/NumRings * v + dv;
    // Generate the group of segments for the current ring
    for seg := 0 to NumSegments do
    begin
    SinCosS(seg * fDeltaSegAngle, ss, sc);
    x0 := r0 * ss;
    z0 := r0 * sc;
    x1 := r1 * ss;
    z1 := r1 * sc;
    
    segNumSegmentsU := -seg/NumSegments * u + du;
    
    s_Vertices[i] :=
    MakeD3DVERTEX(
    MakeD3DVector(Size * x0 , Size * y0, Size * z0), n0,
    segNumSegmentsU, ringNv);
    inc(i);
    
    s_Vertices[i] :=
    MakeD3DVERTEX(
    MakeD3DVector(Size * x1 , Size * y1, Size * z1), n0,
    segNumSegmentsU, ringNv + vNumRings);
    inc(i);
    end;
    end;
    end;
    
    
    ............
    
    { Draw Screen }
    asm
    FINIT
    end;
    DXDraw.D3DDevice7.BeginScene;
    
    
    DXDraw.D3DDevice7.SetRenderState(D3DRENDERSTATE_CU LLMODE, Ord(D3DCULL_NONE));
    
    DXDraw.D3DDevice7.SetTexture( 0, _some_texture_);
    
    DXDraw.D3DDevice7.DrawPrimitive(
    D3DPT_TRIANGLESTRIP, D3DFVF_VERTEX,
    s_Vertices[0], 2 * NumRings * (NumSegments + 1), 0);
    
    DXDraw.D3DDevice7.EndScene;
    
    asm
    FINIT
    end;
    
    ..........
    And finally, what a coincidence, I write the above code today just for a new fast project of mine (a screensaver). Take a look at:

    http://www.geocities.ws/jimmyvalavan...landscape.html

    (I made the sphere for the night sky at the background)


    The above program is written in DelphiX and just say it's an afternoon's work. The source code is not available at the time, but I'm going to release it real soon.

    By the way, do you know how you enable lightining in DirectX immediate mode using DelphiX ??
    I've tried something like this, but it didn't work:

    Code:
     DXDraw.D3DDevice7.SetLight(0, light);
    
    DXDraw.D3DDevice7.LightEnable(0, true);
    
    DXDraw.D3DDevice7.SetRenderState(D3DRENDERSTATE_SP ECULARENABLE, 1);
    DXDraw.D3DDevice7.SetRenderState(D3DRENDERSTATE_DI FFUSEMATERIALSOURCE, 0);
    DXDraw.D3DDevice7.SetRenderState(D3DRENDERSTATE_LI GHTING, 1);
    DXDraw.D3DDevice7.SetRenderState(D3DRENDERSTATE_SH ADEMODE, 1);
    DXDraw.D3DDevice7.SetRenderState(D3DRENDERSTATE_AM BIENT, $A0A0A0A0);
    Last edited by Jimmy Valavanis; 30-03-2012 at 05:24 PM.

  3. #3

    Spheroid in DelphiX ?

    Very thanks, I am try it
    Ijcro.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •