• Welcome to Powerbasic Museum 2020-B.
 

News:

Forum in repository mode. No new members allowed.

Main Menu

Animation projects

Started by Patrice Terrier, August 17, 2010, 07:31:14 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Patrice Terrier

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:




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.


...


Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com

Patrice Terrier

#1
And now showing OpenGL 3D lighting...

Moving a MD2 egyptian statue.




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.

...
Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com

Patrice Terrier

#2
Here is another demo with a red lighting effect.




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.  :-[

...
Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com

Patrice Terrier

#3
Here is a version compatible XP, VISTA, SEVEN.




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

Benefit of using a loop animation:

  • Animation keeps playing while moving the window around.
  • Very low CPU foot print.
  • Full control of the frame rate.
  • Full control of the message loop.


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.

...
Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com

Patrice Terrier

#4
This demo has been updated to play full animation.




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


This project has been updated to work with XP, VISTA, SEVEN. 
...
Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com

Patrice Terrier

#5
MD2 Dragon animation.




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. 

...
Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com

Patrice Terrier

All the posts of this thread have been updated, to fix the ZIP file corruption caused by the "Server Collapse".

...
Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com