Page 5 of 11 FirstFirst ... 34567 ... LastLast
Results 41 to 50 of 103

Thread: PGDmC: Vectored!

  1. #41
    Co-Founder / PGD Elder WILL's Avatar
    Join Date
    Apr 2003
    Location
    Canada
    Posts
    6,107
    Blog Entries
    25
    Lookin' good. Trying to make the ship more visible with thicker lines are ya?
    Jason McMillen
    Pascal Game Development
    Co-Founder





  2. #42
    Quote Originally Posted by WILL View Post
    Lookin' good. Trying to make the ship more visible with thicker lines are ya?
    LOL yeah...all the objects in the game are now drawn using my shiny new glowing line routine that I got working a couple of days ago. I am very pleased with the results.

    It uses a triangle strip to draw parts of an alpha blended circle texture as a line replacement:



    cheers,
    Paul

  3. #43
    Quote Originally Posted by paul_nicholls View Post
    LOL yeah...all the objects in the game are now drawn using my shiny new glowing line routine that I got working a couple of days ago. I am very pleased with the results.

    It uses a triangle strip to draw parts of an alpha blended circle texture as a line replacement:
    That's a very nice pseudo-filter! It looks as good as a real one! (And as a bonus I am sure it is less messy to get different glow at different parts.)

  4. #44
    Quote Originally Posted by Ingemar View Post
    That's a very nice pseudo-filter! It looks as good as a real one! (And as a bonus I am sure it is less messy to get different glow at different parts.)
    Thanks mate

    If you are interested, here is the code I wrote. It uses Jarrod Davis' SvEngine and its OpenGL like primitives routines (I also wrote those) so it could easily be adapted to OpenGL or some other system

    If you examine the code, I have included 'diagrams' of where all the points are and how they are used for the triangle strips.

    Note: if converting to straight OpenGL, you need to do anti-clockwise vertices as opposed to clockwise in DirectX (SvEngine uses DirectX behind the scenes)! Same with the texture coordinates, the v coord (vertical ones are flipped around in OpenGL I believe)...

    Oh, and here is the glow texture I used too (very very hard to see as it is very alpha blended) - I have surrounded it by another colour so you can see it:
    particle3_colorkey.png

    Code:
    unit unit_glowinglines;
    
    interface
    
    uses
      SvEngine;
    
    procedure DrawGlowingLine(x1,y1,x2,y2: Single; color: cardinal; RenderState: Integer; texture: TsvTexture; DrawEnd1,DrawEnd2: Boolean; width: Single = 1);
    
    implementation
    
    uses
      unit_vectors;
    
    type
    //
    // TRGBA
    //
      TRGBA = packed record
        case Integer of
          0: (b,g,r,a: Byte);
          1: (Value: Cardinal);
      end;
    
    //
    // glowing line routines
    //
    
    function  OffsetCoord(const ox,oy,x,y: Single; up,right: TVector2f): TVector2f;
    // this function moves along the rotated space's up & right vectors by
    // y and x respectively, and then translates it to ox,oy
    begin
      Result.x := ox + x * right.x + y * up.x;
      Result.y := oy + x * right.y + y * up.y;
    end;
    
    procedure DrawGlowingLine(x1,y1,x2,y2: Single; color: cardinal; RenderState: Integer; texture: TsvTexture; DrawEnd1,DrawEnd2: Boolean; width: Single = 1);
    var
      up, right: TVector2f;
      dx,dy: Single;
      radius: Single;
      p0,p1,p2,p3: TVector2f;
      p4,p5,p6,p7: TVector2f;
      c: TRGBA;
    begin
      c.Value := color;
    
      if width <= 1 then
      begin
        sv.RenderDevice.BeginPrimitive(ptLineList,RenderState,nil);
          sv.RenderDevice.Color4ub(c.r,c.g,c.b,c.a);
          sv.RenderDevice.Vertex2f(x1,y1);
          sv.RenderDevice.Vertex2f(x2,y2);
        sv.RenderDevice.EndPrimitive;
    
        Exit;
      end;
    
      radius := width / 2;
    
      dx := X2 - X1;
      dy := Y2 - Y1;
    
      // calculate rotation vectors for line
      up    := VecNormalize(VecPerp(Vector2f(dx,dy)));
      right := VecNormalize(Vector2f(dx,dy));
    
      // calculate triangle strip points
      p1 := OffsetCoord(x1,y1,-radius,-radius,up,right);
      p7 := OffsetCoord(x2,y2,+radius,-radius,up,right);
      p6 := OffsetCoord(x2,y2,+radius,+radius,up,right);
      p0 := OffsetCoord(x1,y1,-radius,+radius,up,right);
    
      p5 := OffsetCoord(x2,y2,0,-radius,up,right);
      p4 := OffsetCoord(x2,y2,0,+radius,up,right);
      p2 := OffsetCoord(x1,y1,0,+radius,up,right);
      p3 := OffsetCoord(x1,y1,0,-radius,up,right);
    
    {
      U->   0.0      0.5                     0.5        1.0
    
            p1       p3                      p5         p7
      0.0   +--------*-----------------------*----------+     0.0
    V       |                   up                      |
    |       |      x1,y1         |         x2,y2        |
    v       |        *-----------+-----------*          |
            |                       right ->            |
            |                                           |
      0.1   +--------*-----------------------*----------+     1.0
            p0      p2                       p4         p6
    
      uv    0.0      0.5                     0.5        1.0
    }
    
      sv.RenderDevice.BeginPrimitive(ptTriangleStrip,RenderState,texture);
    
        sv.RenderDevice.Color4ub(c.r,c.g,c.b,c.a);
    
        {
        triangle strip vertex order
        ---------------------------
            1  3  5  7
            +--+--+--+
            |\ |\ |\ |
            | \| \| \|
            +--+--+--+
            0  2  4  6
        }
        if DrawEnd1 then
        begin
          sv.RenderDevice.Texcoord2f(0.0,1); sv.RenderDevice.Vertex2f(p0.x,p0.y);
          sv.RenderDevice.Texcoord2f(0.0,0); sv.RenderDevice.Vertex2f(p1.x,p1.y);
        end;
    
        // stretch center of texture along middle section
        sv.RenderDevice.Texcoord2f(0.5,1); sv.RenderDevice.Vertex2f(p2.x,p2.y);
        sv.RenderDevice.Texcoord2f(0.5,0); sv.RenderDevice.Vertex2f(p3.x,p3.y);
        sv.RenderDevice.Texcoord2f(0.5,1); sv.RenderDevice.Vertex2f(p4.x,p4.y);
        sv.RenderDevice.Texcoord2f(0.5,0); sv.RenderDevice.Vertex2f(p5.x,p5.y);
    
        if DrawEnd2 then
        begin
          sv.RenderDevice.Texcoord2f(1.0,1); sv.RenderDevice.Vertex2f(p6.x,p6.y);
          sv.RenderDevice.Texcoord2f(1.0,0); sv.RenderDevice.Vertex2f(p7.x,p7.y);
        end;
    
      sv.RenderDevice.EndPrimitive;
    end;
    
    end.
    unit_vectors.pas
    Code:
    unit unit_vectors;
    
    interface
    
    type
    //
    // TVector2f
    //
      PVector2f = ^TVector2f;
      TVector2f = record
        x, y: Single;
      end;
    
    //
    // TVector3f
    //
      PVector3f = ^TVector3f;
      TVector3f = record
        x, y, z: Single;
      end;
    
    //
    // TVector4f
    //
      PVector4f = ^TVector4f;
      TVector4f = array[0..3] of Single;
    
    function  Vector2f(const aX,aY: Single): TVector2f;
    function  VecNegative(const v: TVector2f): TVector2f; overload;
    function  VecAdd(const v1, v2: TVector2f): TVector2f; overload;
    function  VecSubtract(const v1, v2: TVector2f): TVector2f; overload;
    function  VecMultiply(const v: TVector2f; const s: Single): TVector2f; overload;
    function  VecNormalize(const v: TVector2f): TVector2f; overload;
    function  VecLen(const v: TVector2f): Single; overload;
    function  VecDot(const v1,v2: TVector2f): Single; overload;
    function  VecPerp(const v: TVector2f): TVector2f;
    
    function  Vector3f(const aX,aY,aZ: Single): TVector3f;
    function  VecNegative(const v: TVector3f): TVector3f; overload;
    function  VecAdd(const v1, v2: TVector3f): TVector3f; overload;
    function  VecSubtract(const v1, v2: TVector3f): TVector3f; overload;
    function  VecMultiply(const v: TVector3f; const s: Single): TVector3f; overload;
    function  VecNormalize(const v: TVector3f): TVector3f; overload;
    function  VecLen(const v: TVector3f): Single; overload;
    function  VecDot(const v1,v2: TVector3f): Single; overload;
    function  VecCross(const v1,v2: TVector3f): TVector3f;
    
    function  Vector4f(const aX,aY,aZ: Single; const aW: Single = 1): TVector4f;
    
    implementation
    
    //
    // TVector2f routines
    //
    function Vector2f(const aX, aY: Single): TVector2f;
    begin
      Result.x := aX;
      Result.y := aY;
    end;
    
    function  VecNegative(const v: TVector2f): TVector2f;
    begin
      Result.x := -v.x;
      Result.y := -v.y;
    end;
    
    function  VecAdd(const v1, v2: TVector2f): TVector2f;
    begin
      Result.x := v1.x + v2.x;
      Result.y := v1.y + v2.y;
    end;
    
    function  VecSubtract(const v1, v2: TVector2f): TVector2f;
    begin
      Result.x := v1.x - v2.x;
      Result.y := v1.y - v2.y;
    end;
    
    function  VecMultiply(const v: TVector2f; const s: Single): TVector2f;
    begin
      Result.x := v.x * s;
      Result.y := v.y * s;
    end;
    
    function  VecNormalize(const v: TVector2f): TVector2f;
    var
      mag: Single;
    begin
      mag := VecLen(v);
      if mag < 1 then mag := 1;
    
      Result.x := v.x / mag;
      Result.y := v.y / mag;
    end;
    
    function  VecLen(const v: TVector2f): Single;
    begin
      Result := Sqrt(Sqr(v.x) + Sqr(v.y));
    end;
    
    function  VecDot(const v1,v2: TVector2f): Single;
    begin
      Result := v1.x * v2.x + v1.y * v2.y;
    end;
    
    function  VecPerp(const v: TVector2f): TVector2f;
    begin
      Result := Vector2f(-v.y, v.x);
    end;
    
    //
    // TVector3f routines
    //
    function Vector3f(const aX, aY, aZ: Single): TVector3f;
    begin
      Result.x := aX;
      Result.y := aY;
      Result.z := aZ;
    end;
    
    function  VecNegative(const v: TVector3f): TVector3f;
    begin
      Result.x := -v.x;
      Result.y := -v.y;
      Result.z := -v.z;
    end;
    
    function  VecAdd(const v1, v2: TVector3f): TVector3f;
    begin
      Result.x := v1.x + v2.x;
      Result.y := v1.y + v2.y;
      Result.z := v1.z + v2.z;
    end;
    
    function  VecSubtract(const v1, v2: TVector3f): TVector3f;
    begin
      Result.x := v1.x - v2.x;
      Result.y := v1.y - v2.y;
      Result.z := v1.z - v2.z;
    end;
    
    function  VecMultiply(const v: TVector3f; const s: Single): TVector3f;
    begin
      Result.x := v.x * s;
      Result.y := v.y * s;
      Result.z := v.z * s;
    end;
    
    function  VecNormalize(const v: TVector3f): TVector3f;
    var
      mag: Single;
    begin
      mag := VecLen(v);
      if mag < 1 then mag := 1;
    
      Result.x := v.x / mag;
      Result.y := v.y / mag;
      Result.z := v.z / mag;
    end;
    
    function  VecLen(const v: TVector3f): Single;
    begin
      Result := Sqrt(Sqr(v.x) + Sqr(v.y) + Sqr(v.z));
    end;
    
    function  VecDot(const v1,v2: TVector3f): Single;
    begin
      Result := v1.x * v2.x + v1.y * v2.y + v1.z * v2.z;
    end;
    
    function  VecCross(const v1,v2: TVector3f): TVector3f;
    begin
      Result.x := v1.y * v2.z - v1.z * v2.y;
      Result.y := v1.z * v2.x - v1.x * v2.z;
      Result.z := v1.x * v2.y - v1.y * v2.x;
    end;
    
    //
    // TVector4f routines
    //
    function Vector4f(const aX, aY, aZ: Single; const aW: Single = 1): TVector4f;
    begin
      Result[0] := aX;
      Result[1] := aY;
      Result[2] := aZ;
      Result[3] := aW;
    end;
    
    end.
    cheers,
    Paul
    Last edited by paul_nicholls; 07-07-2011 at 10:48 PM.

  5. #45
    As a better FTP test for the competition, I have uploaded the current version of Vectored! to the FTP site so people can give it a whirl if they wish (Win32 only!!). You need 7z to unpack it (creates a folder, no install necessary).

    See the "paul_nicholls - vectored! - early test.7z" file (1.94 MB)

    NOTE: it is only a test at the moment, and nowhere near the final thing

    You can destroy asteroids and get destroyed by asteroids, but it has some sound effects now...yay (they were created using sfxr).

    It still needs optimizing to improve the frame rate at times

    Shoot = (quick tap for normal fire, hold down for 1 second or more to fire misslle)
    move left/right = left/right cursor keys
    Exit game = Escape

    Asteroids need 4 shots of normal fire to explode, but only 1 missile shot...

    cheers,
    Paul

  6. #46
    It looks pretty good
    Will the tunnel speed increase during gameplay?
    The pulsating glow effect on the asteroids look cool.
    Imagine I've written something clever here inspiring you to make something awesome. If that happens give me credits

  7. #47
    It's kind of hard to tell they're asteroids from far away though now because of the glowing effect. Also, the game runs kind of poorly (50fps; i5 w/ nvidia 310m)

  8. #48
    PGD Staff code_glitch's Avatar
    Join Date
    Oct 2009
    Location
    UK (England, the bigger bit)
    Posts
    933
    Blog Entries
    45
    Hmm... I barely get 30fps where dead space 2 gets 30+fps on med/high so performance is an 'issue' I would say... I shudder to think of the carnage on a GMA chip

    Anyway, I couldn't help noticing one big problem: Memory leak. Shooting boosts memory a few kb, as does a new asteroid - destroying them does NOT make mem usage decrease. I started on 16,714kb RAM and within a minute reached 18,224kb which is a tad worrying

    Otherwise very good game, lots of potential - as an improvement: where lines meet it make a big blob which might be nice to avoid? Kinda reminds me of the original tron and the old amstrad days even though those where before my time I have played with them
    I once tried to change the world. But they wouldn't give me the source code. Damned evil cunning.

  9. #49
    @pstudio: thanks mate I'm not sure if the tunnel speed will change, but the red rectangles in the tunnel will end up being blocks and other stuff that stick up and you have to avoid or get destroyed. Oh, and there will be less red blocks in the beginning but that will increase as time/levels increase

    @dazappa: I guess it is hard to tell from afar that they are asteroids To be honest, I am drawing more of the asteroids than I need to right now, and this extra drawing is not helping. It causes more glowing on them and might even slow things down! I am working on the frame rate issues along with the rest of the game...

    Thanks for trying it guys!

    cheers,
    Paul

  10. #50
    Quote Originally Posted by code_glitch View Post
    Hmm... I barely get 30fps where dead space 2 gets 30+fps on med/high so performance is an 'issue' I would say... I shudder to think of the carnage on a GMA chip
    FPS carnage...funny! Yeah, I am working on the FPS issue mate. It probably doesn't help that the engine I am using is a very very good 2d engine, but it has no native 3d drawing routines out of the box (I am working on this too after the competition!). So I am currently emulating the OpenGL pipeline by using equivalent matrices and routines to transform objects from world space to the screen and then drawing them as 2d lines.

    Quote Originally Posted by code_glitch View Post
    Anyway, I couldn't help noticing one big problem: Memory leak. Shooting boosts memory a few kb, as does a new asteroid - destroying them does NOT make mem usage decrease. I started on 16,714kb RAM and within a minute reached 18,224kb which is a tad worrying
    There isn't a memory leak, it is Windows not releasing memory as objects are being destroyed - a well known problem!! The memory gets returned after the game finishes. I could make it so I create a pool of objects at the start of the game that I just reuse and not create/destroy any during the game...

    Quote Originally Posted by code_glitch View Post
    Otherwise very good game, lots of potential - as an improvement: where lines meet it make a big blob which might be nice to avoid? Kinda reminds me of the original tron and the old amstrad days even though those where before my time I have played with them
    The blobs are formed from the line ends intersecting each other and having additive effects with their alpha blended parts..

    As you say it is a bit like Tron and I quite like the effect to be honest LOL

    Thanks for playing mate!!

    cheers,
    Paul

Page 5 of 11 FirstFirst ... 34567 ... LastLast

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
  •