Article Preview
Buy Now
FEATURE
Rotating a Cube
Rotating a 3D Wireframe Cube on a Canvas
Issue: 17.2 (March/April 2019)
Author: Eugene Dakin
Author Bio: Eugene works as a Senior Oilfield Technical Specialist. He has university degrees in the disciplines of Engineering, Chemistry, Biology, Business, and a Ph.D. in Chemical Engineering. He is the author of dozens of books on Xojo available on the xdevlibrary.com website.
Article Description: No description available.
Article Length (in bytes): 14,146
Starting Page Number: 44
Article Number: 17207
Resource File(s):
project17207.zip Updated: 2019-03-04 09:41:38
Related Link(s): None
Excerpt of article text...
Our project for today is to create a program to display a spinning 3-dimensional wireframe cube on a 2-dimensional Xojo canvas. This works on Windows, Mac, and Linux systems and works in 32-bit and 64-bit modes. The program uses Xojo native code so that the same code-base can be used on any supported operating system.
When you start the program and a
Canvas
is loaded, lines are drawn in a cube form, and the cube rotates (see Figure 1).How It Works
Basically, our window has a
canvas
, and 12 lines are drawn. Dimensions are changed in atimer
with every call and the new line coordinates are recalculated and drawn (see Figure 2).Before the lines are drawn, there is the ability to change the spin-rate for the xy, xz, and yz axis. To centre the cube there are x-axis offset and y-axis offset values from the upper and left part of the canvas. Also, a scale factor is available to increase or decrease the size of the cube.
To make the cube spin faster, either change all of the
xyR
,xzR
, andyzR
values to a higher number such as 3.14/90 or change the timerperiod
to a value lower than 20. There is a limit on many computers where the lowest limit seems to be near about 15 milliseconds or so.
...End of Excerpt. Please purchase the magazine to read the full article.