Simple 3D Cube
Simple 3D Cube
Simple 3D Cube
Simple 3D Cube
Simple 3D Cube
Simple 3D Cube Simple 3D Cube Simple 3D Cube Simple 3D Cube Simple 3D Cube Simple 3D Cube Simple 3D Cube Simple 3D Cube
Simple 3D Cube Simple 3D Cube
Simple 3D Cube
Go Back  Xtreme Visual Basic Talk > > > Simple 3D Cube


Reply
 
Thread Tools Display Modes
  #1  
Old 07-19-2005, 11:59 PM
DrFire DrFire is offline
Newcomer
 
Join Date: Sep 2004
Posts: 17
Default Simple 3D Cube


I have been searching forums, Visual Basic sites, EVERYWHERE! I cannot find an example of what I want. If you've seen the Mac OS X 3D cube fast user switching, I want this exact type thing (so no up and down rotation, just left and right). I want to take a screenshot of the current desktop and then have an image on the next side of the cube. If this has to be done in DirectX, so be it! I have been looking for days and days, please someone just help me with this code.
Reply With Quote
  #2  
Old 07-20-2005, 09:28 AM
passel's Avatar
passelSimple 3D Cube passel is offline
Sinecure Expert

Super Moderator
* Guru *
 
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 8,024
Default

Yes, quite a few people like that Mac eye candy stuff.
On the Mac, the desktop is managed by Quartz/Quartz Extreme, which takes advantage of the high end Graphic cards, and integrates 2D/3D, alphablending, anti-aliasing, Open-Gl, etc. to let the graphic card GPU handle a lot of these special effects.

When ever a window is open, closed, moved, etc. the image of the window is rasterized and passed as a texture to OpenGL, and the GPU can handle the bulk of the work of scaling, distorting, zooming, rotating, rippling, or whatever else the programmer decided should be done to the image in transitioning from one state to another.

I've haven't seen the user switch cube effect yet, but I assume the desktop must start shrinking down, revealing itself as being on one side of a cube.
As it is shrinking, I assume it may also start rotating, revealing another desktop on another side of the cube.
Probably once the cube has rotated past the 45 degree point, it will start zooming back out as it continues rotating until the new desktop fills the screen.

I don't know how feasible this would be to do in DirectX.

I think the effect could be accomplished easy enough (assuming an isometric 3d cube would be acceptable) on an NT based computer (NT, Win 2000, XP) using plgblt (parallelogram blt (BLock Transfer)).
plgblt is not implemented on Win9X machines.

You would have to capture the current Screen, then reference that in the plgblt.
You will need to work out how to map the 3 points the plgblt needs to emulate a side of your cube.

The result will not be as fast, nor look as good as the Mac, but you don't have the power of the GPU and support of the windows manager to help you.

If DirectX could be used, then you would have the GPU and DirectX to help, but I don't know if it would make sense, since switching between the Window manager, and DirectX full screen mode is not a quick or smooth transition, so wouldn't look nearly as good as a standard GDI32 approach, but I'm only guessing, since I don't know DirectX

Also, the task bar at the bottom of the screen may be a problem.
I don't know if using a full screen window, or writing directly to the desktop would be the way to go.

I don't know if anyone else will take the initiative to try something on their own, so it may be up to you to start working on it, and see how far you get.

(p.s. Oh, and by the way, I wouldn't say this was a simple, 3-D cube. It's a bit more involved than that).
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.

Last edited by passel; 07-20-2005 at 09:37 AM.
Reply With Quote
  #3  
Old 07-20-2005, 02:34 PM
DrFire DrFire is offline
Newcomer
 
Join Date: Sep 2004
Posts: 17
Default

Well, I figured looking at games today, and all that's going on in them, that a simple rotating cube wouldn't be much, I've also seen some examples of exactly what I'm looking for, but there were multiple cubes, or other effects that I don't want. I have a rather fast computer, so I don't think the speed would be an issue. From what I've read, people consider a 3D spinning cube in DirectX as the 'Hello World' of DirectX... I just have no clue on how to use DirectX, but I thank you for your comment, passel.
Reply With Quote
  #4  
Old 07-23-2005, 04:21 AM
DeX's Avatar
DeXSimple 3D Cube DeX is offline
Senior Contributor

* Expert *
 
Join Date: Aug 2003
Location: Berkhamsted, England
Posts: 940
Default

One thing that I don't get, is how do you get an image of your desktop which as an aspect ratio of 4:3 or 5:4 onto the face of a cube which has an aspect ratio of 1:1?
__________________
Check out my free Download Meter prog written in VB6.
Having trouble using the registry in VB? Try my free registry control.
Reply With Quote
  #5  
Old 07-23-2005, 12:38 PM
passel's Avatar
passelSimple 3D Cube passel is offline
Sinecure Expert

Super Moderator
* Guru *
 
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 8,024
Default

Well, it doesn't strickly have to be a cube.
In fact, while I haven't seen it in action, I have seen a still image from a book of the user swap in action.
I guess it doesn't really create a cube, it just distortes the desktop into a shrinking trapezoid, and slides it to the left (or right, can't tell from the picture), as it brings in a growing trapezoid from the other side.

Because it is not a parallelogram, you can't use the plgblt.

And while I agree that a 3D spinning cube is the "Hello World" of most 3D libraries, you are talking about something completely different.
You are talking about grabbing the desktop, which if you're running a DirectX program full screen, doesn't exist.
And if you're talking about running DirectX in a window, then you have the same coordination problems, and display problems, as I've already mentioned (dealing with the taskbar, transition artifacts during the period of capturing the desktop, then showing your window, then doing the effect, and then whatever your intention is after that).
For, DeX, I can give a quickly slapped together example, of what I think the effect looks like. But I just used an image of a form I already had on the disk, and am doing the effect inside a form, not trying to capture the desktop.
I also just use the one image, both "going off" and "coming on" to the form.
This example also shows how bad the stretchblt looks without anti-aliasing, which on the Mac, since they are using OpenGL and texture mapping, I'm sure looks much better.
Some half-toning could be done in the StretchBlt, but that would make it several times slower than it currently is. I'm stepping the transition 15 pixels at a time, as it is, to make it complete the transition quicker. (perhaps a smaller number could be used on a faster machine).

Anyway, just a crude, quickly slapped together example attached. No frills.
Attached Files
File Type: zip CubeSwitch.zip (16.7 KB, 67 views)
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.

Last edited by passel; 07-23-2005 at 12:50 PM.
Reply With Quote
  #6  
Old 07-24-2005, 12:19 AM
DrFire DrFire is offline
Newcomer
 
Join Date: Sep 2004
Posts: 17
Default

Didn't think about just using the simple StretchBlt; good idea, passel. That is indeed what I wanted, you did good work. Although some times it seems before the transition is completed the form turns white or disappears then shows again when the transition is completed. I'll work on speeding that up. Thankyou for your help, passel. I'll let you know if I can speed it up significantly.
Reply With Quote
  #7  
Old 07-24-2005, 10:07 AM
passel's Avatar
passelSimple 3D Cube passel is offline
Sinecure Expert

Super Moderator
* Guru *
 
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 8,024
Default

The simplest way to speed it up, of course, is to change the step size. Even with a step size of -50, the transition seems to get the point across well enough.
I guess the mind fills in the gaps.

And as for the form turning white, I've seen that as well.
I'm not sure why it happens. The larger your step size, the less the chance it will happen, so is related to how much drawing is being done in the loop.

You can eliminate the glitch, at least it did on my machine, by adding a DoEvents where you do the Refresh (line before, or after, or on the same line).
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.
Reply With Quote
  #8  
Old 07-24-2005, 02:57 PM
blastoboy1000's Avatar
blastoboy1000 blastoboy1000 is offline
Junior Contributor
 
Join Date: Sep 2004
Posts: 220
Default

This intrigued me, and so I tinkered with it, adding some microsoft code to capture the entire screen. I tried making it capture the entire screen and then rotating it from there, with the form the same size as the screen, but it goes really really slowly and just crashes. Is there any way to make the image capture of less quality so that the cube actually finishes spinning? The modified version is attached.

EDIT: reposted attachment, includes option for fullscreen
Edit by moderator:
Please do not post compiled attachments. Source only.

Last edited by lebb; 07-24-2005 at 06:26 PM. Reason: Removed attachment with .exe
Reply With Quote
  #9  
Old 07-24-2005, 06:43 PM
passel's Avatar
passelSimple 3D Cube passel is offline
Sinecure Expert

Super Moderator
* Guru *
 
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 8,024
Default

Well, if you refer to my earlier post, adding a DoEvents may prevent the crashing. I haven't had it crash on my machine, but I didn't try it without the DoEvents.
You can speed it up by going with less quality, by doing wider chunks of Stretchblt, rather than the 1 pixel wide ones that are in the original code.
For example, I've added a variable so that it is easy to adjust the value in the IDE to see what it looks like. I also stepped the main loop by a much larger magnitude.
Here's the Form_Click code, after my modifications.
The variable "Inc" controls how wide each strip of Stretchblt area is (the wider the strips, the less has to be done).
Code:
Private Sub Form_Click() Dim x As Single, yt As Single, yb As Single, yd As Single, xd As Single, xs As Single, x2 As Single Dim Inc As Single Inc = 10 For x = ScaleWidth - 2 To 1 Step -100 yt = (ScaleHeight / 4) * ((ScaleWidth - x) / ScaleWidth) yb = ScaleHeight - yt yd = yt / x xd = ScaleWidth / x Line (0, 0)-(ScaleWidth, ScaleHeight), BackColor, BF xs = 0 ' Debug.Print x For x2 = 0 To x Step Inc StretchBlt hDC, x2, yt, Inc, yb - yt, Picture1.hDC, xs, 0, Inc, Picture1.ScaleHeight, vbSrcCopy xs = xs + (xd * Inc) yt = yt - (yd * Inc) yb = ScaleHeight - yt Next yt = (ScaleHeight / 4) * (x / ScaleWidth) yd = -(yt / (ScaleWidth - x)) yt = 0 yb = ScaleHeight xd = ScaleWidth / (ScaleWidth - x) xs = 0 ' Debug.Print x For x2 = x To ScaleWidth - 1 Step Inc StretchBlt hDC, x2, yt, Inc, yb - yt, Picture1.hDC, xs, 0, Inc, Picture1.ScaleHeight, vbSrcCopy xs = xs + (xd * Inc) yt = yt - (yd * Inc) yb = ScaleHeight - yt Next Refresh DoEvents Next PaintPicture Picture1.Picture, 0, 0 End Sub
Perhaps a better modification would be to have a dynamic self adjusting stretchblt width (say divide each side of the cube into 50 or 100 blits (but width no less than 1)).
Thus the narrow area (the area on the right initially) has a smaller stretch width, than the wide area (the area on the left initially).
Then as the area on the left get's smaller (and the angle steeper, and the blockiness more obvious) the stetch widths will also be getting smaller to compensate. Meanwhile, the widths on the expanding side will be expanding as well, helping to keep the number of blits necessary in check.
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.

Last edited by passel; 07-25-2005 at 07:36 AM.
Reply With Quote
  #10  
Old 07-25-2005, 03:27 AM
DrFire DrFire is offline
Newcomer
 
Join Date: Sep 2004
Posts: 17
Default

That's quite a bit faster passel, very good work. It's actually going at a usable speed now on my 1280x960 resolution with a screenshot of the desktop. Doesn't use much RAM either. Thank you for you help.
Reply With Quote
  #11  
Old 07-25-2005, 10:36 AM
blastoboy1000's Avatar
blastoboy1000 blastoboy1000 is offline
Junior Contributor
 
Join Date: Sep 2004
Posts: 220
Default

Thanks, also for the DoEvents reminder. I sometimes forget about that.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Simple 3D Cube
Simple 3D Cube
Simple 3D Cube Simple 3D Cube
Simple 3D Cube
Simple 3D Cube
Simple 3D Cube Simple 3D Cube Simple 3D Cube Simple 3D Cube Simple 3D Cube Simple 3D Cube Simple 3D Cube
Simple 3D Cube
Simple 3D Cube
 
Simple 3D Cube
Simple 3D Cube
 
-->