José Roca Forum
Web Site
News: Version 2.01 of the SED Editor released
 
*
Welcome, Guest. Please login or register. September 09, 2010, 02:34:43 PM


Login with username, password and session length


PowerBASIC is a trademark of PowerBASIC, Inc.
This is not an official PowerBASIC site and we are not affiliated with PowerBASIC, Inc.
DISCLAIMER: The software and accompanying documentation are provided "as is" and without warranties as to performance or merchantability or any other warranties whether expressed or implied. Because of the various hardware environments into which the software may be used, no warranty of fitness for a particular purpose is offered. The user must assume the entire risk of using the software. In no case shall any of the contributors to this project be liable for any incidental, special or consequential damages or loss, including, without limitation, lost profits or the inability to use equipment or access data. This is true even if we are advised of the possibility of such damages. We also don't have any obligation of fix eventual bugs or to add new features.
Pages: 1   Go Down
  Print  
Author Topic: The Cube  (Read 1115 times)
0 Members and 1 Guest are viewing this topic.
Patrice Terrier
Global Moderator
Hero Member
*****

Karma: 36
Offline Offline

Gender: Male
Posts: 1353


WWW
« on: June 21, 2009, 05:42:14 PM »

The Cube

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 HitDetection 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.

Code:
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)
END SUB

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.


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


Note:
Because of the use of 3D, you must have a graphic card that is OpenGL 2.00+ compatible.
« Last Edit: June 23, 2009, 06:40:47 PM by Patrice Terrier » Logged

Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com
Petr Schreiber
Sr. Member
****

Karma: 9
Offline Offline

Posts: 420


« Reply #1 on: June 21, 2009, 09:07:50 PM »

Very nice demo, very playful way to change the background bitmap.

It was also wise choice to make the picking color based, only problem could occur in 16 bit mode, but I guess nobody uses this setup any longer. Color picking is quite common in pro computer games.






Logged

AMD Sempron 3400+ | 1GB RAM @ 533MHz | GeForce 6200 / GeForce 9500GT | 32bit Windows XP SP3

psch.thinbasic.com
Patrice Terrier
Global Moderator
Hero Member
*****

Karma: 36
Offline Offline

Gender: Male
Posts: 1353


WWW
« Reply #2 on: June 21, 2009, 11:07:37 PM »

Thank you Petr.

Note: I have written also a (standard) "picking" mode version, if interrested let me know, then i shall post the code here.

...
Logged

Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com
Patrice Terrier
Global Moderator
Hero Member
*****

Karma: 36
Offline Offline

Gender: Male
Posts: 1353


WWW
« Reply #3 on: June 23, 2009, 06:53:48 PM »

The Cube project has been reworked a little...

I have added two more cubes (they are just clone from the main cube), you can move them around, however the image selection must still be done with the big one.

Clone is a very unique and powerful feature of GDImage, only two lines of code added to the GDImageCreateSprite procedure:

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)


Screen shot of the WinDev's version, however new PB's version looks the same.




The new zip file is attached to the first post of this thread.
« Last Edit: June 23, 2009, 07:52:44 PM by Patrice Terrier » Logged

Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com
Pages: 1   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC

IMPRESSUM
Valid XHTML 1.0! Valid CSS! Dilber MC Theme by HarzeM
Page created in 0.245 seconds with 19 queries.