Special

Introducing the “Welcome to Xojo” Bundle!

New to Xojo and looking for guidance? We've put together a terrific bundle to welcome you! Xojo Bundle

This bundle includes six back issues of the magazine -- all of year 21 in printed book and digital formats -- plus a one-year subscription (beginning with 22.1) so you'll be learning all about Xojo for the next year. It's the perfect way to get started programming with Xojo. And you save as much as $35 over the non-bundle price!

This offer is only available for a limited time as supplies are limited, so hurry today and order this special bundle before the offer goes away!

Article Preview


Buy Now

Issue 17.2 ('Barchart API')
Instant purchase and download via GumRoad!

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):

Download Icon 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 a timer 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, and yzR values to a higher number such as 3.14/90 or change the timer period 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.