Important alert: (current site time 7/16/2013 4:14:29 AM EDT)
 

VB icon

Rotating Cube Demo

Email
Submitted on: 8/21/1998
By: Theo Kandiliotis  
Level: Not Given
User Rating: By 103 Users
Compatibility: VB 5.0, VB 6.0
Views: 38995
author picture
(About the author)
 
     The HELLO WORLD of 3D programming :) A rotating cube demo. You can adjust the rotation (clockwise or anticlockwise) and the speed by moving the mouse cursor towards the right and left edges of the form.
 

Windows API/Global Declarations:

Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
'**************************************
'Windows API/Global Declarations for :Rotating Cube Demo
'**************************************
No API's		
		
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
				
'**************************************
' Name: Rotating Cube Demo
' Description:The HELLO WORLD of 3D programming :)
A rotating cube demo. You can adjust the rotation (clockwise or anticlockwise) and the speed by moving the mouse cursor towards the right and left edges of the form.
' By:Theo Kandiliotis
'
' Inputs:Nothing
'
' Returns:Nothing
'
' Assumes:This is Math stuff mostly,has little to do with VB's methods. I used the Line method to do all the drawing on the form.
To run this project ,you have to paste the text indicated, into a blank text file and save it in ASCII format with an FRM suffix.
Notice that it WILL NOT work if you paste it directly on a VB5 code window...Also make sure that no lines are wrapped before you save it as FRM.
Have fun!
'
' Side Effects:No Side Effects
'
'This code is copyrighted and has' limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=1008&lngWId=1'for details.'**************************************

------======== start copying AFTER this line ======---------
VERSION 5.00
Begin VB.Form frmMain 
AutoRedraw =-1 'True
BackColor=&H00C0C0C0&
Caption ="Rotating Cube DEMO"
ClientHeight=3195
ClientLeft =60
ClientTop=345
ClientWidth =4680
FillColor=&H00C0C0C0&
ForeColor=&H00FF0000&
LinkTopic="Form1"
ScaleHeight =213
ScaleMode=3 'Pixel
ScaleWidth =312
StartUpPosition =3 'Windows Default
WindowState =2 'Maximized
Begin VB.PictureBox Picture1 
 BackColor=&H00FFFFFF&
 BorderStyle =0 'None
 Height =1140
 Left=-1035
 ScaleHeight =76
 ScaleMode=3 'Pixel
 ScaleWidth =772
 TabIndex=0
 Top =1440
 Width=11580
 Begin VB.Label Label1 
 AutoSize=-1 'True
 Caption ="Move the mouse towards the edges of the form to adjust rotation and speed"
 BeginProperty Font 
Name="MS Sans Serif"
Size=12
Charset =161
Weight =700
Underline=0'False
Italic =0'False
Strikethrough=0'False
 EndProperty
 Height =300
 Left=0
 TabIndex=1
 Top =0
 Width=9135
 End
End
Begin VB.Timer Timer1 
 Interval=1
 Left=3825
 Top =2835
End
End
Attribute VB_Name = "frmMain"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private X(8) As Integer
Private y(8) As Integer
Private Const Pi = 3.14159265358979
Private CenterX As Integer
Private CenterY As Integer
Private Const SIZE = 250
Private Radius As Integer
Private Angle As Integer
Private CurX As Integer
Private CurY As Integer
Private CubeCorners(1 To 8, 1 To 3) As Integer
Private Sub Form_Load()
Show
With Picture1
.Width = Label1.Width
.Height = Label1.Height
End With
Picture1.Move ScaleWidth / 2 - Picture1.ScaleWidth / 2, Picture1.Height
CenterX = ScaleWidth / 2
CenterY = ScaleHeight / 2
Angle = 0
Radius = Sqr(2 * (SIZE / 2) ^ 2)
CubeCorners(1, 2) = SIZE / 2
CubeCorners(2, 2) = SIZE / 2
CubeCorners(3, 2) = -SIZE / 2
CubeCorners(4, 2) = -SIZE / 2
CubeCorners(5, 2) = SIZE / 2
CubeCorners(6, 2) = SIZE / 2
CubeCorners(7, 2) = -SIZE / 2
CubeCorners(8, 2) = -SIZE / 2
End Sub
Private Sub DrawCube()
Cls
For i = 1 To 8
X(i) = CenterX + CubeCorners(i, 1) - CubeCorners(i, 3) / 8
y(i) = CenterY + CubeCorners(i, 2) + CubeCorners(i, 3) / 8
Next
Line (X(3), y(3))-(X(4), y(4))
Line (X(4), y(4))-(X(8), y(8))
Line (X(3), y(3))-(X(7), y(7))
Line (X(7), y(7))-(X(8), y(8))
Line (X(1), y(1))-(X(3), y(3))
Line (X(1), y(1))-(X(2), y(2))
Line (X(5), y(5))-(X(6), y(6))
Line (X(5), y(5))-(X(1), y(1))
Line (X(5), y(5))-(X(7), y(7))
Line (X(6), y(6))-(X(8), y(8))
Line (X(2), y(2))-(X(4), y(4))
Line (X(2), y(2))-(X(6), y(6))
Line (X(1), y(1))-(X(4), y(4))
Line (X(2), y(2))-(X(3), y(3))
Line (X(4), y(4))-(X(8), y(8))
Line (X(3), y(3))-(X(7), y(7))
DoEvents
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, y As Single)
CurX = X
CurY = y
End Sub
Private Sub Timer1_Timer()
Select Case CurX
Case Is > ScaleWidth / 2
Angle = Angle + Abs(CurX - ScaleWidth / 2) / 20
If Angle > 360 Then Angle = 0
Case Else
Angle = Angle - Abs(CurX - ScaleWidth / 2) / 20
If Angle < 0 Then Angle = 360
End Select
For i = 1 To 3 Step 2
CubeCorners(i, 3) = Radius * Cos((Angle) * Pi / 180)
CubeCorners(i, 1) = Radius * Sin((Angle) * Pi / 180)
Next
For i = 2 To 4 Step 2
CubeCorners(i, 3) = Radius * Cos((Angle + 2 * 45) * Pi / 180)
CubeCorners(i, 1) = Radius * Sin((Angle + 2 * 45) * Pi / 180)
Next
For i = 5 To 7 Step 2
CubeCorners(i, 3) = Radius * Cos((Angle + 6 * 45) * Pi / 180)
CubeCorners(i, 1) = Radius * Sin((Angle + 6 * 45) * Pi / 180)
Next
For i = 6 To 8 Step 2
CubeCorners(i, 3) = Radius * Cos((Angle + 4 * 45) * Pi / 180)
CubeCorners(i, 1) = Radius * Sin((Angle + 4 * 45) * Pi / 180)
Next
DrawCube
End Sub
-----==== paste the above into a text file and save it with
an FRM suffix in ASCII format.Then just load the FRM file
in the VB5 enviroment=========-------------------------


Other 1 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Not Given category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments
5/1/1999 3:47:00 AMccjx

PLease email me a copy of that and show me how can i change the text and maybe add a graphic.
(If this comment was disrespectful, please report it.)

 
5/14/1999 10:59:00 PMD

can you please e-mail the source for that

(If this comment was disrespectful, please report it.)

 
5/18/1999 8:09:00 AMGreg Roberts

I was very impressed!
Well, actually i am very impressed!
I was sort of expecting properly shaded 3d, but even looking at that WELL DONE!


(If this comment was disrespectful, please report it.)

 
5/25/1999 9:40:00 AMKeir

I am having some trouble with this, i have been program for a while, and i am using VB6, i can find no reference to "Begin" that you use so much to set propertys on objects, Would you send me a form with this on it, perhaps then i would understand. Thanks
(If this comment was disrespectful, please report it.)

 
5/25/1999 11:26:00 AMKeir

Anyone have any ideas on how to make a timer that can have a interval less then 1 ms , email me if so
(If this comment was disrespectful, please report it.)

 
5/28/1999 10:28:00 PMMNK

Keir, you can use a dummy for - next loop to make the computer lose time.Since that takes a very less amt of time, you can check by trial and error method and choose your timing. But it gets processor and memory dependant.
(If this comment was disrespectful, please report it.)

 
7/22/1999 10:12:00 PMCool

CooL LooKinG CodE MaN. KeeP iT Up.
(If this comment was disrespectful, please report it.)

 
7/22/1999 10:14:00 PMProGMasTeR

Short and Simple Code.
(If this comment was disrespectful, please report it.)

 
7/26/1999 11:02:00 PMDerek

nice code and i like the presentation method :)
(If this comment was disrespectful, please report it.)

 
7/31/1999 1:26:00 AMJonathan Feucht

I have been always trying to do that! Very neat! I'm going to use your code to try to build a rhubics cube or something.
(If this comment was disrespectful, please report it.)

 
8/2/1999 1:19:00 PMAnil Monteiro

Awesome ..!!!
(If this comment was disrespectful, please report it.)

 
8/23/1999 3:21:00 PMMatt

Oh my, this is wicked, and there no use of ocx's!!, i made a tacky 3d game at www.mars1998.freeserve.co.uk\doomed.zip
(If this comment was disrespectful, please report it.)

 
10/1/1999 8:13:00 AMErik Pedersen

Hi!
Do you got the code for a yatzy game, that is programmed in VB-6.0? If you have it, can you please mail it to me.

Best regards
Erik Pedersen
(If this comment was disrespectful, please report it.)

 
10/7/1999 9:53:00 PMRobert

Very impressive Code!!!!!!
(If this comment was disrespectful, please report it.)

 
10/9/1999 4:28:00 AMDavid L.S.

Please, Can you send me the source code to me e-mail?
(If this comment was disrespectful, please report it.)

 
11/9/1999 2:08:00 AMWendell

please send me a copy of that source code (zipped) thanks very much.
(If this comment was disrespectful, please report it.)

 
11/13/1999 7:31:00 AMalan

cool...
pls send me a copy of that code with zipped. thanks
(If this comment was disrespectful, please report it.)

 
11/18/1999 11:53:00 PMDragonrider15

nice code...good for beginners. although i have something to suggest: zip it up to post it or give the code, but not the actual insides of the .frm file. and out of the 2 i suggested, zipping it up for d/l would be best. just a tip

Dragonrider15
dragonrider15@hotmail.com
http://welcome.to/dragonrider15 srealm

(If this comment was disrespectful, please report it.)

 
6/22/2000 1:32:28 PMZenZagg

Is there any reason it makes my hard drive sound like a trash compactor when it runs? *cht-cht-cht-cht-cht-cht-cht-cht-cht-cht!* nonstop... heh, nice except for the nonstop HD accesses
(If this comment was disrespectful, please report it.)

 
1/9/2003 12:19:37 PM

cool...
please send me a copy of that
code with zipped. thanks

(If this comment was disrespectful, please report it.)

 
6/18/2005 1:06:08 PMAlex Flex

wtf dummies!
the code IS in that!
(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.