No announcement yet.

The Cube

  • Filter
  • Time
  • Show
Clear All
new posts

  • The Cube

    The Cube

    Direct link to download the project

    The purpose of this GDImage 5.06+ project, is to provide an easy (and reliable) way to perform face detection on a 3D rotating cube, using the mouse to pickup a specific picture.

    While "Picking" is the usual way of doing things in 3D's world. I have taken another approach because what i wanted to do was to select a specific face of the cube, and not the whole cube itself.

    "Picking" is based on the depth detection of an object, but In the case of a rotating cube it could not be used, because very often two or three faces are just in front of the camera, meaning each of the face is exactly at the same distance from the camera.

    The solution i have used to solve this problem is named "color detection" mode.
    When i am in HitDection mode, instead of mapping the textures on each face of the cube i am using a unique color for each of the face. Then i just have to check the color of the pixel located at the mouse coordinates to figure the real face that has been selected.

    SUB DrawCube (BYVAL HitDetection AS LONG)
        IF HitDetection THEN CALL glColor4ub(0,0,1,255)
        CALL GL_DrawCubeFrontFace(mt(1).Texture)
        IF HitDetection THEN CALL glColor4ub(0,0,2,255)
        CALL GL_DrawCubeBackFace(mt(2).Texture)
        IF HitDetection THEN CALL glColor4ub(0,0,3,255)
        CALL GL_DrawCubeTopFace(mt(3).Texture)
        IF HitDetection THEN CALL glColor4ub(0,0,4,255)
        CALL GL_DrawCubeBottomFace(mt(4).Texture)
        IF HitDetection THEN CALL glColor4ub(0,0,5,255)
        CALL GL_DrawCubeRightFace(mt(5).Texture)
        IF HitDetection THEN CALL glColor4ub(0,0,6,255)
        CALL GL_DrawCubeLeftFace(mt(6).Texture)
    Screen shot:

    How to use "The Cube":
    • Click or double click with the left mouse button on a cube's face. The selected picture become the new background, while loading a new image.
    • You can also use the left mouse button to drag the cube to another location.
    • Using a right mouse button click, allows you to select a new folder (with more than 6 pictures) to populate the cube faces with new images.

    This project could be a good candidate to create a true VISTA's widget to change the desktop wallpaper.

    Because of the use of 3D, you must have a graphic card that is OpenGL 2.00+ compatible.

    Patrice Terrier
    Addons: GDImage.DLL 32/64-bit (Graphic library), WinLIFT.DLL 32/64-bit (Skin Engine).

  • #2
    The Cube clone

    I have reworked a little The Cube project to show you the powerful GDImage's clone feature, added only two lines of code:

    '   // For the fun we add two clones
        CALL ZD_CloneObject(%IDS_3DOBJECT, %IDS_CLONE2, rc.nRight - %GL_SizeX, 0): ZD_SetObjectScale(%IDS_CLONE2, 0.5): ZD_SetObjectAnchorMode(%IDS_CLONE2, %ANCHOR_CENTER)
        CALL ZD_CloneObject(%IDS_3DOBJECT, %IDS_CLONE1, 0, 0): ZD_SetObjectAnchorMode(%IDS_CLONE1, %ANCHOR_CENTER)
    and here is the result:

    The link provided in the first post of this thread has been updated with the new zip file.

    You can move the clone arround, however you must still use the large cube to perform image selection.

    Of course, instead of image selection you could fire another window or application.

    Patrice Terrier
    Addons: GDImage.DLL 32/64-bit (Graphic library), WinLIFT.DLL 32/64-bit (Skin Engine).