Page 2 of 4 FirstFirst 1234 LastLast
Results 11 to 20 of 31

Thread: Drawing phasers!

  1. #11

    Re: Drawing phasers!

    Quote Originally Posted by ize
    Those screenies look great btw :thumbsup:
    only the last screenshot was of my game, others were from game i'm remaking.
    This is my game project - Top Down City:
    http://www.pascalgamedevelopment.com...y-Topic-Reboot

    My OpenAL audio wrapper with Intelligent Source Manager to use unlimited:
    http://www.pascalgamedevelopment.com...source+manager

  2. #12

    Re: Drawing phasers!

    Here's a quick and dirty hack i wrote you might be able to use. You'll need to add a TGLDirectOpenGL component to your GLScene as well as adding OpenGL1X to your uses list. It's compiled with Delphi 2009, but i don't think there's any difference in code if you're using another version.

    [pascal]
    { Draws the Phase }
    procedure Phase(Sides: Byte;Rad: Single;Mat: TGLLibMaterial;
    const Verts: array of TVector;var rci: TRenderContextInfo);
    var
    fn,cv,nv,d,u,r: TVector;
    Vx: array of TVector;
    x,y,y2,z: Single;
    i0,i1,i2,i,o: Integer;
    begin
    SetLength(Vx, Sides*Length(Verts)); // array to hold all phase points
    // calclate points
    for i:=0 to High(Verts) do begin
    if i<High(Verts) then o:=1 else o:=-1;
    cv:=Verts[i]; // current position
    nv:=Verts[i+o]; // next position
    d:=VectorNormalize(VectorSubtract(nv,cv)); // direction vector (normalized)
    if o<0 then NegateVector(d); // stops flipping because of reversal. comment out to see
    u:=VectorNormalize(VectorCrossProduct(d,XHmgVector )); // up vector (assuming Y is up)
    r:=VectorNormalize(VectorCrossProduct(d,u)); // right vector

    for o:=0 to Sides-1 do begin
    { divide points equally around phase }
    x:=Rad*Sin(DegToRad(o*(360/Sides)))*r[0];
    y:=Rad*Cos(DegToRad(o*(360/Sides)))*u[1];
    y2:=Rad*Cos(DegToRad(o*(360/Sides)))*u[2];
    z:=Rad*Sin(DegToRad(o*(360/Sides)))*r[2];
    Vx[(i*Sides)+o]:=VectorMake(cv[0]+x, cv[1]+y, cv[2]+z+y2);
    end;
    end;

    { draw points }
    for i:=0 to High(Verts)-1 do begin
    if Assigned(Mat) then mat.Material.Apply(rci);
    glBegin(GL_TRIANGLE_STRIP)
    for o:=0 to Sides do begin
    i0:=((i+1)*Sides)+o mod Sides;
    i1:=(i*Sides)+o mod Sides;
    i2:=((i+1)*Sides)+((o+1) mod Sides);

    { calculate face normal }
    fn:=VectorCrossProduct(VectorSubtract(Vx[i0],Vx[i1]),VectorSubtract(Vx[i0],Vx[i2]));
    fn:=VectorNormalize(fn);
    glNormal3fv(@fn);

    { un-comment to wrap texture around phase }
    glTexCoord2f(0,o/Sides); glVertex3fv(@Vx[i0]);
    glTexCoord2f(1,o/Sides); glVertex3fv(@Vx[i1]);

    { un-comment to map texture to each side }
    // glTexCoord2f(0,o and 1); glVertex3fv(@Vx[i0]);
    // glTexCoord2f(1,o and 1); glVertex3fv(@Vx[i1]);
    end;
    glEnd;
    if Assigned(Mat) then Mat.Material.UnApply(rci);
    end;

    { clean up }
    SetLength(Vx, 0);
    end;
    [/pascal]

    also on onRender event for TGLDirectOpenGL component:
    [pascal]
    procedure TForm1.GLDirectOpenGL1Render(Sender: TObject; var rci: TRenderContextInfo);
    var
    m: TGLLibMaterial;
    v: array of TVector;
    begin
    { un-comment to disable lighting and culling }
    // gldisable(GL_CULL_FACE);
    // glDisable(GL_LIGHTING);

    { replace 'test' with the name of your material }
    m:=GLMaterialLibrary1.Materials.GetLibMaterialByNa me('test');

    { you can make adjustments to material 'm' before calling the routine
    (eg emission/blending/etc)
    }
    Phase(8, 0.25, m, v, rci); // draw the phase (Sides,Radius,Material,Pos'n array,ContextInfo)

    { clean up needed?}
    m:=nil;
    SetLength(v,0);

    { un-comment to re-enable lighting and culling (if disabled above) }
    // glEnable(GL_LIGHTING);
    // glEnable(GL_CULL_FACE);
    end;
    [/pascal]

    I figured as you're already using tglpipes, this method isn't too different except instead of being objects, it's drawn to the buffer. You can adjust the number of sides, radius and segments in the phase so it's fairly flexible. Although it's not setup for splines (from your screenshots they all seemed to be straight lines) it won't take too much modding to incorporate them. it's definitely not perfect, but it kinda works

    small app wrapped around the function
    Video
    Download app

    Any problems, let me know.
    Windows Vista x64 Ultimate<br />AMD Athlon x64 4000+<br />Codegear Delphi 2009, Delphi 2007, Borland Delphi 7

  3. #13

    Re: Drawing phasers!

    ize: you made a very nice demo, but that wasn't the problem, the problem is that ideally i would only have half of pipe, which always faces the camera and uv mapping along the length of the pipe / cylinder like this screenshot:



    Your code is good and it could be likely easily changed for the uv mapping method (if we use normal face culling for this then maybe the uv mapping could be just projected somehow and rear faces culled off?)

    I will produce a video from old game to show what exactly i meant, the UV mapped side follows the camera source, so that the phasers look as if they are volumetric, the uv mapping also animates along phaser path towards the target.

    The phasers have a smaller taper / radius at the origin, on the screenshots i set that to actual diameter of the rest of phaser so that the inner structure was more obviously seen.

    I will get a video by the end of the day to show exactly how it works.
    This is my game project - Top Down City:
    http://www.pascalgamedevelopment.com...y-Topic-Reboot

    My OpenAL audio wrapper with Intelligent Source Manager to use unlimited:
    http://www.pascalgamedevelopment.com...source+manager

  4. #14

    Re: Drawing phasers!

    OK, as promised.. the video of desired effect (from a old game that i am remaking):

    http://mathpudding.com/temp/phasers.wmv

    The emitter taper size is now less exaggarated so that you can see it's not a straight cylindrical shape, you can see very well in video how the texture on cylinder always faces the camera.

    If anyone can help me obtain such effect.. i have my paypal account on hot standby

    NECRODOME:

    I didn't do that.. that's the old game, i am remaking THAT engine and need to achieve that effect in my new game, and i don't have access to old source code

    This is the game i am recreating in delphi, i got most of stuff worked out such as loading existing ship models (i wrote a .nif model format parser and renderer for glscene):

    EDIT: i added reply to my old post, for some reason i get a database error trying to reply to this topic!!!


    Database Error
    Please try again. If you come back to this error screen, report the error to an administrator.
    edit #2: apparently i get that error everywhere on the forum now.. this is bad!
    This is my game project - Top Down City:
    http://www.pascalgamedevelopment.com...y-Topic-Reboot

    My OpenAL audio wrapper with Intelligent Source Manager to use unlimited:
    http://www.pascalgamedevelopment.com...source+manager

  5. #15
    Legendary Member NecroDOME's Avatar
    Join Date
    Mar 2004
    Location
    The Netherlands, Eindhoven
    Posts
    1,059

    Re: Drawing phasers!

    Looks nice
    Like it how you did it with inner and outer beam
    EDIT:

    oh... ok... sorry, didn't read .... just looks nice


    btw:

    I also have database errors!!! cannot post new topics

    (sorry so ruin your topic)
    NecroSOFT - End of line -

  6. #16

    Re: Drawing phasers!

    That game looks like fun Hey, thanks for the earlier compliments. Sorry it didn't solve the problem but i think that i can tweak the code to look more like you want. It's almost there from what i can see - the beam does just look like two 8-sided cylinders with normal face culling (like you said). The impact point is definitely just a billboard sprite facing the camera and that's real easy to achieve - you could either:
    • use a TGLSprite which is purely 2D and won't go too well with the 3D space atmosphere
    • use a TGLQuad with the following IIRC:


    [pascal]
    GLQuad1.Pointto(GLCamera1.absolutePosition, YHMGVector); // assuming YAxis is up
    [/pascal]

    It's either PointTo or PointToObject (i'll double check when i'm playing in delphi again)

    [thinking out loud]
    As for the tapering, that's not a problem at all. If i make the phase a class, then each "node" can also have a radius as well as position (like TGLPipe).

    Also, it's not a big leap from there to get some pulsating animation. The phase is a direct line so interpolating several nodes along the path is do-able, then just sine wave the radii of all nodes over time. But i'm getting WAY ahead of myself back to the orignal problem ... the glow seems to be using additive textures (which i can't help with as my artist skills are beyond laughable ) i'll try the image you posted above.
    [/thinking out loud]

    Now that i have an idea of the desired result, i'll (try and) post something soon
    Windows Vista x64 Ultimate<br />AMD Athlon x64 4000+<br />Codegear Delphi 2009, Delphi 2007, Borland Delphi 7

  7. #17

    Re: Drawing phasers!

    ize: the problem isn't the billboard sprite or the taper point or the cylinder geometry, the problem is texture uv mapping, please watch the video carefully and observe how the texture uv mapping on phaser always faces the camera, that is the actual problem i am having.
    This is my game project - Top Down City:
    http://www.pascalgamedevelopment.com...y-Topic-Reboot

    My OpenAL audio wrapper with Intelligent Source Manager to use unlimited:
    http://www.pascalgamedevelopment.com...source+manager

  8. #18

    Re: Drawing phasers!

    So, suddently everyone is fresh out of ideas?
    This is my game project - Top Down City:
    http://www.pascalgamedevelopment.com...y-Topic-Reboot

    My OpenAL audio wrapper with Intelligent Source Manager to use unlimited:
    http://www.pascalgamedevelopment.com...source+manager

  9. #19

    Re: Drawing phasers!

    Hi there. Well don't i feel like the prize idiot - i ran off at 1000 mph ... in completely the wrong direction I came online last night to upload the 2nd version and saw your post that it wasn't right. So went back to the drawing board and studied the video for about 10mins frame by frame to see exactly what it did.

    After much head scratching/headaches/nosebleeds i think i have what you're looking for!

    Sorry, no source at the mo because it's in such a mess after being ripped to shreds! All the materials are embedded in the app, but they can easily be loaded at runtime, etc. There's also no need to have the variations like i've done - you can have one "template" material, assign it to the phase and then make changes to the phase material leaving the original untouched.
    The only thing i couldn't get right was the highlighting of the phaser. I think the best "cheat" would just be to put it in the texture. I'm no artist so i didn't try it.

    I can give you an outline of how i achived it though. It's probably wrong as i'm not a maths genius. It involved a LOT of trial and even more errors

    • I calculated the direction from the camera to the first node in the phase and did a cross product of that with the phaser direction to give me the final vector (eye vector).
    • After that i calculated the angle of the phase direction and eye vector using the phase up vector as a reference. This angle returns -1 .. 1 which i changed to 0 .. 2 and made it signed so i know which side it was on -=left +=right
    • Finally i used this number to modify the uv tex coords to "slide" the texture around the phaser


    Here ya go:
    Video
    Download app

    Let me know if this is at least in the right direction

    laters
    Windows Vista x64 Ultimate<br />AMD Athlon x64 4000+<br />Codegear Delphi 2009, Delphi 2007, Borland Delphi 7

  10. #20

    Re: Drawing phasers!

    Well.. to problem of texturemapping a cylinder to point camera, we have few things known:
    1. U-coordinate of each vertex never change, so we only need to count 1 value; V-coordinate.
    BUT
    2. If we think about how texture behaves if model stands still and only texture-coordinates change, we know that the animation and the general looks would be different depending on angle. Sort of distortion/ripples happen. So we can skip step 1 and rotate the cylinder along its center, so we still have only 1 value to calculate and that is rotation angle.
    3. What values we have to use? We can use glGet on GL_MODELVIEW_MATRIX to get all 3 rotation vectors that camera uses. And we can count normal vector to cylinder when it is at 0 degree rotation (which is completely free to choose along the surface of cylinder).
    4. That all known, we should better draw some picture to get a good overview on what vectors we are comparing, or analyze them realtime in program... and that goes way beyond a simple forum post

Page 2 of 4 FirstFirst 1234 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
  •