PC SOFT
ONLINE REPOSITORY
FOR WINDEVWEBDEV AND WINDEV MOBILE

Home |  | Sign in | English US
TheCube (Enhanced cube control)
Published by Patrice TERRIER
in the category Graphics
New features
dedicated forum:
http://www.objreader.com/index.php?topic=357.msg6150#new

Description
This project originally written in WD12 with GDImage 5.07,
shows how to perform a "cube field" control with GDImage 7.00 in 64-bit mode

Main Features:

1 - Unlike the WINDEV decor Cube control, no need to install the DotNET framework (therefore, no waiting during the initial launch).
2 - You can interact with the cube and its clones.
3 - Each face of the cube can display a different image.
4 - By clicking on a face of the main cube (the largest) you can change the background image.
5 - You can move the cube to any location in the GDImage control (with the mouse or the keyboard).
6 - The "clone" function (specific to GDImage) allows you to have several animated cubes that work at the same time.
7 - The GFI GDImage (visible when choosing an image folder) is compatible with all animations including DirectX, OpenGL, and external controls.

At the same time, this project shows how to make a selection with the mouse on a 3D object with several textures.

In the world of 3D, the usual way to make a selection on a moving object is called: "Picking".
However, this technique, based on the distance of the various objects from the camera, does not make it possible to know with certainty the precise location corresponding to the coordinates of the mouse.

So I was forced to use another method called "color detection".
With this method, when we are in "HitDetection" mode, we use a unique color on each face of the cube instead of "mapping" the textures to it.
Then, it suffices to test the color of the point hovered over by the mouse, to know the corresponding face.

The colors are assigned in the "DrawCube" procedure:

PROCEDURE DrawCube(LOCAL nHitDetection is int)
IF nHitDetection THEN glColor4ub(0,0,1,255)
GL_DrawCubeFrontFace(gaMt[1].Texture)

IF nHitDetection THEN glColor4ub(0,0,2,255)
GL_DrawCubeBackFace(gaMt[2].Texture)

IF nHitDetection THEN glColor4ub(0,0,3,255)
GL_DrawCubeTopFace(gaMt[3].Texture)

IF nHitDetection THEN glColor4ub(0,0,4,255)
GL_DrawCubeBottomFace(gaMt[4].Texture)

IF nHitDetection THEN glColor4ub(0,0,5,255)
GL_DrawCubeRightFace(gaMt[5].Texture)

IF nHitDetection THEN glColor4ub(0,0,6,255)
GL_DrawCubeLeftFace(gaMt[6].Texture)

The actual "HitDetection" detection is performed in the "RenderAnimation" procedure:

IF gP.nHitDetection THEN
x, y is int
nID is 1byte int
ZD_GetObjectXY(IDS_3DOBJECT, x, y)
mX is int = gP.nMouseX - x
mY is int = gP.nMouseY - y
zSplitColorARGB(GetPixel(GLmemDC(), mX, mY), 0, nID, 0, 0)
IF nID < ArrayInfo(gaMt, tiDimension) + 1 THEN
MonBufferAnsi is a Buffer on 520
Transfer(&MonBufferAnsi, &gaMt[nID].FullName, 520)
gP.sUseBackground = UnicodeToAnsi(MonBufferAnsi)//gaMt[nID].FullName)

GDImageUpdateBackground()

// What is the next ListBox texture to use?
nItem is int = ListSelect(BackgroundList)
IF nItem < ListCount(BackgroundList) THEN nItem++ ELSE nItem = 1
ListSelectPlus(BackgroundList, nItem)

// Update the selected texture
swFullName is string UNICODE = AnsiToUnicode(BackgroundList[nItem])
Transfer(&gaMt[nID].FullName, &swFullName, 520)

ZI_UpdateNamedGLTextureFromFileEx(BackgroundList[nItem], gaMt[nID].ID, gaMt[nID].Square)
END

gP.nHitDetection = 0

ELSE
// Paint the resulting bitmap to our window
ZD_ReplaceObjectBitmap(ZI_CreateBitmapFromImage(zBitmapToImage( GLmemDC() )), IDS_3DOBJECT, True)
END


How to use "TheCube":

1 - Perform a single or double click, with the left mouse button, on one of the faces of the cube (the largest). The selected image is used as the new window background, while a new image is displayed on the corresponding face of the cube.
2 - You can use the mouse (left button) or the keyboard to move the cube to a new location.
3 - Clicking with the right mouse button allows you to choose a new folder containing images that will be displayed on the faces of the cube (preferably choose a folder containing more than 6 images).
4 - You can move all the cubes, however the image selection will only be done on the main cube, the one that is enlarged during the initial start-up.

Note:
Due to the use of the 3D functions of GDImage, you must use a graphics card that supports the OpenGL 2.00+ specification.
Illustrations, screen shots
none
none
User reviews
(To evaluate this resource, click 'Write a review')
No review or comment? Be the first one!
ABOUT
RATING:
00No rating
DOWNLOADS:
72
UPDATED:
June 18, 2021
VERSION:
2.00
CONCERNS:
WINDEV
Minimum version: WD17+
SIZE:
10.6 MB
OF SAME DEVELOPER