Powerbasic Museum 2020-B

IT-Consultant: Patrice Terrier => WinLIFT => Topic started by: Patrice Terrier on August 17, 2010, 07:31:14 PM

Title: Animation projects
Post by: Patrice Terrier on August 17, 2010, 07:31:14 PM
I was ashamed by the poor quality of the C# example i have posted a few days ago.
Thus i decided to rework everything from scratch, adding some more spices, to make it a nice looking little application.  8)

This demo shows you how to manipulate a 3D object with the mouse, to inspect a rock core drilling (for the purpose of geological analyses).

The actual Rock core drilling (carottage) can vary but, it is generally 10 centimeter diameter and 1 meter length.

There is no game loop, no animation timer, thus saving CPU resources.  :)

All the mousing is handled in this little callback:

FUNCTION glWndProc(BYVAL hWnd AS DWORD, BYVAL Msg AS LONG, BYVAL wParam AS DWORD, BYVAL lParam AS DWORD) AS LONG

    LOCAL rc AS RECT
    STATIC LeftMousing, RightMousing, wasLX, wasLY, wasRX, wasRY AS LONG

    LOCAL x, y, dx, dy AS LONG

    SELECT CASE LONG Msg
   
    CASE %WM_PAINT
        RenderOpenGL()

    CASE %WM_LBUTTONDOWN
        IF (LeftMousing = %FALSE) THEN
            x = LO(INTEGER, lParam): y = HI(INTEGER, lParam)
            glObj.xcpy = glObj.xrot
            glObj.ycpy = glObj.yrot

            glObj.xdown = x
            glObj.ydown = y
            LeftMousing = %TRUE
        END IF
        IF (GetFocus() <> hWnd) THEN SetFocus(hWnd)

    CASE %WM_LBUTTONUP
        LeftMousing = %FALSE

    CASE %WM_RBUTTONDOWN
        IF (RightMousing = %FALSE) THEN
            x = LO(INTEGER, lParam): y = HI(INTEGER, lParam)
            glObj.xcpy = glObj.xoff
            glObj.ycpy = glObj.yoff

            glObj.xdown = x
            glObj.ydown = y
            RightMousing = %TRUE
        END IF
        IF (GetFocus() <> hWnd) THEN SetFocus(hWnd)

    CASE %WM_RBUTTONUP
        RightMousing = %FALSE

    CASE %WM_MOUSEMOVE
        x = LO(INTEGER, lParam): y = HI(INTEGER, lParam)

        IF (NOT ZI_IsLButtonDown()) THEN
            LeftMousing = %FALSE
        ELSE
            IF ((wasLX <> x) OR (wasLY <> y)) THEN
                IF (LeftMousing) THEN
                   dx = x - glObj.xdown: glObj.yrot = glObj.ycpy + dx / 2.0
                   dy = y - glObj.ydown: glObj.xrot = glObj.xcpy + dy / 2.0
                END IF
            END IF
            wasLX = x: wasLY = y
            RenderOpenGL()
        END IF

        IF (NOT ZI_IsRButtonDown()) THEN
            RightMousing = %FALSE
        ELSE
            IF ((wasLX <> x) OR (wasLY <> y)) THEN
                IF (RightMousing) THEN
                    GetClientRect(g_hGLcontrol, rc)
                    dx = x - glObj.xdown: glObj.xoff = glObj.xcpy - (-45 * dx) / (2.0 * rc.nRight)
                    dy = y - glObj.ydown: glObj.yoff = glObj.ycpy + (-45 * dy) / (2.0 * rc.nBottom)
                END IF
                RenderOpenGL()
            END IF
            wasRX = x: wasRY = y
        END IF
        RenderOpenGL()

    END SELECT

    FUNCTION = CallWindowProc(g_hGLproc, hWnd, Msg, wParam, lParam)

END FUNCTION


The same concept can be used to manipulate complex 3D object.

Screen shot:

(http://www.zapsolution.com/pictures/Drilling.jpg)


The whole project is attached to this post under the name of Cylinder.zip.


This demo is meant to work on VISTA/SEVEN to use WinLIFT's composited skins.


...


Title: Lighting 3D (WinLIFT/GDImage OpenGL project)
Post by: Patrice Terrier on August 18, 2010, 11:41:30 PM
And now showing OpenGL 3D lighting...

Moving a MD2 egyptian statue.

(http://www.zapsolution.com/pictures/Lighting.jpg)


And here is the lighting code section:

    DIM LightDiffuse(3) AS SINGLE:  ARRAY ASSIGN LightDiffuse()  = 1.0, 1.0, 0.8, 1.0
    DIM LightAmbient(3) AS SINGLE:  ARRAY ASSIGN LightAmbient()  = 0.3, 0.3, 0.3, 1.0
    DIM LightPosition(3) AS SINGLE: ARRAY ASSIGN LightPosition() = -50.0, 150.0, -100.0, 1.0

    glLightfv(%GL_LIGHT1, %GL_DIFFUSE, LightDiffuse(0))     ' Setup the Diffuse Light
    glLightfv(%GL_LIGHT1, %GL_AMBIENT, LightAmbient(0))     ' Setup the Ambient Light
    glLightfv(%GL_LIGHT1, %GL_POSITION,  LightPosition(0))  ' Position the Light

    glMaterialfv(%GL_FRONT, %GL_SPECULAR, LightDiffuse(0))


    glMaterialfv(%GL_FRONT, %GL_EMISSION, 0.05)
    glMaterialfv(%GL_FRONT, %GL_SHININESS, 5.0)

    glEnable(%GL_LIGHT1)                                    ' Enable Light ONE

    glEnable(%GL_LIGHTING)                                  ' Enable Lighting
    glColorMaterial(%GL_FRONT, %GL_AMBIENT_AND_DIFFUSE)
    glEnable(%GL_COLOR_MATERIAL)                            ' Enable Coloring Of Material



See the attached Lighting.zip project.


Credit: the MD2ex.dll is a variation of the excellent Petr Schreiber's MD2Plus.dll.
(mine is building a texture on the fly from any of the GDImage supported graphic formats).

This demo is meant to work on VISTA/SEVEN to use WinLIFT's composited skins.

...
Title: Red lighting (OpenGL)
Post by: Patrice Terrier on August 19, 2010, 04:35:08 PM
Here is another demo with a red lighting effect.

(http://www.zapsolution.com/pictures/Lighting2.jpg)


The 3D object is made of 3 md2 objects: head, body, throne.


Sorry for XP's users, it is intended to work on VISTA/SEVEN.  :-[

...
Title: Sydney
Post by: Patrice Terrier on August 21, 2010, 07:51:23 PM
Here is a version compatible XP, VISTA, SEVEN.


(http://www.zapsolution.com/pictures/Sydney.jpg)

This new OpenGL demo, shows you the superiority of the loop animation model hover the traditional game loop.

Benefit of using a loop animation:

Next step would be to lead the animation on a playing audio, and you would get a new BassBox plugin :)

Better to play the demo full screen.

See the attached ZIP file.

...
Title: Hueteotl (full MD2 animation)
Post by: Patrice Terrier on August 22, 2010, 11:26:43 PM
This demo has been updated to play full animation.

(http://www.zapsolution.com/pictures/Lighting3.jpg)


The 3D object is made of one single md2 objects with 198 frames.


This project has been updated to work with XP, VISTA, SEVEN. 
...
Title: Dragon
Post by: Patrice Terrier on August 23, 2010, 11:28:52 AM
MD2 Dragon animation.

(http://www.zapsolution.com/pictures/Dragon.jpg)


The 3D object is made of one single md2 objects with 200 frames.

The Pristina font is being used to display the coordinates.


This project works with XP, VISTA, SEVEN. 

...
Title: Re: Animation projects
Post by: Patrice Terrier on August 09, 2011, 04:26:07 PM
All the posts of this thread have been updated, to fix the ZIP file corruption caused by the "Server Collapse".

...