I recently posted an AGK2 Tier 2 3D Sample in C++ for Windows (MSVS Express 2013) which some people are finding helpful. I have ported the code from C++ over to Tier 1 Basic. Perhaps it will serve as a good example for those wishing to try 3D in Basic. You can compare the two to see how the AppGameKit commands are quite portable. Sun texture image is attached. Enjoy!
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Planets_T1 - AGKv2 Tier-1 Sample Application
// Author: MARDONIX Marty Quire (aka Uncle Martin) - Tampa, Florida, USA - www.mardonix.com
// Created: July 2015
// Description: Several small spheres revolving around a larger rotating central sphere
// Purpose: Sample to demonstrate simple 3D graphics using AGK2 in Tier1 Basic
// Environment: Built & tested with AGKv2 on Windows 8.1 with nVidia graphics
// DISCLAIMER: Permission given to use at your discretion, no claims or implications of suitability
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#option_explicit
// Define a color type structure
type ColorTyp
Red as Integer
Grn as integer
Blu as integer
Alp as integer
endtype
// Define a platform type structure
type PlatformTyp
Size as float
Color as ColorTyp
OrbitRadius as float
OrbitAngSpd as float
OrbAngDeg as float
xPos as float
yPos as float
zPos as float
endtype
// Define variables
KeyW as integer // Camera In
KeyS as integer // Camera Out
KeyC as integer // Camera Down
KeySp as integer // Camera Up
KeyZ as integer // Camera "Zero" (reset)
KeyEsc as integer // Exit application
global Planet as PlatformTyp[15] // Planet definitions
CamHi as float // Camera height (Y)
CamDis as float // Camera distance (Z)
Plnt as integer
// Define constants
#constant ANG_360 = 360.0 // 360 degrees per circle
#constant CAMHI_RAT = 0.3 // Camera height (Y) rate
#constant CAMDS_RAT = 0.3 // Camera distance (Z) rate
#constant FIRST_PLNT = 3 // First planet index
#constant LAST_PLNT = 10 // Last planet index
////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Initialization code
// Setup display
SetWindowTitle( "Planets_T1" )
SetWindowSize( 1024, 768, 0 )
SetVirtualResolution( 1024, 768 )
SetOrientationAllowed( 1, 1, 1, 1 )
SetClearColor(0, 0, 0) // black
SetSyncRate(60, 0)
SetScissor(0, 0, 0, 0)
// Set up lighting with a white lightpoint at the origin
CreateLightDirectional(1, 0, 0, 0, 0, 0, 0) // only needed to create point light
CreateLightPoint(1, 0, 0, 0, 100, 255, 255, 255) // only index 1 available for now
// Set up central star object at origin
CreateObjectSphere(1, 3.0, 16, 32) // Sphere
SetObjectColor(1, 255, 255, 0, 255) // Yellow
SetObjectPosition(1, 0, 0, 0) // at Origin
SetObjectLightMode(1, 0) // Disable lighting on this object
LoadImage(1, "Sun1.png") // Load Texture
SetObjectImage(1, 1, 0) // Apply texture
// Set up initial camera Y height & Z distance from origin
CamHi = 5.0 // Y
CamDis = 22.5 // Z
// Populate planetary data table
// Index Radius Speed Size Red Grn Blu
LoadPlanet( 3, 3.0, 4.0, 0.3, 255, 0, 0) // Red
LoadPlanet( 4, 4.1, 3.5, 0.4, 255, 127, 0) // Orange
LoadPlanet( 5, 5.2, 3.0, 0.5, 255, 255, 0) // Yellow
LoadPlanet( 6, 6.3, 2.5, 0.6, 0, 255, 0) // Green
LoadPlanet( 7, 7.4, 2.0, 0.7, 0, 0, 255) // Blue
LoadPlanet( 8, 8.5, 1.5, 0.8, 255, 0, 255) // Magenta
LoadPlanet( 9, 9.6, 1.0, 0.9, 255, 255, 255) // White
LoadPlanet(10, 10.7, 0.5, 1.0, 0, 255, 255) // Cyan
// For each planet (first to last)
for Plnt = FIRST_PLNT to LAST_PLNT
// Set up the planet
CreateObjectSphere(Plnt, Planet[Plnt].Size, 8, 16) // Sphere of specified size
SetObjectColor(Plnt, Planet[Plnt].Color.Red, Planet[Plnt].Color.Grn, Planet[Plnt].Color.Blu, Planet[Plnt].Color.Alp)
next
repeat
// Display help text for camera keyboard controls
PrintC("C/Sp=Dn/Up CamY: ")
PrintC(CamHi)
Print(" Z=Reset CamY/Z")
PrintC("W/S=In/Out CamZ: ")
Print(CamDis)
// Get key inputs
KeyW = GetRawKeyState(87) // Camera In
KeyS = GetRawKeyState(83) // Camera Out
KeyC = GetRawKeyState(67) // Camera Down
KeySp = GetRawKeyState(32) // Camera Up
KeyZ = GetRawKeyState(90) // Camera "Zero" (reset)
KeyEsc = GetRawKeyState(27) // Exit application
// Update camera Y Height & Z Distance based on key inputs (note: not currently limited)
// Y Height Dn/Up
if (KeyC)
CamHi = CamHi - CAMHI_RAT
elseif (KeySp)
CamHi = CamHi + CAMHI_RAT
endif
// Z Distance In/Out
if (KeyW)
CamDis = CamDis - CAMDS_RAT
elseif (KeyS)
CamDis = CamDis + CAMDS_RAT
endif
// Reset
if (KeyZ)
CamHi = 5.0
CamDis = 22.5
endif
// For each planet (first to last)
for Plnt = FIRST_PLNT to LAST_PLNT
// Integrate & wrap orbital angle based on its angular speed (sign controls direction)
Planet[Plnt].OrbAngDeg = Planet[Plnt].OrbAngDeg - Planet[Plnt].OrbitAngSpd
if (Planet[Plnt].OrbAngDeg < -ANG_360) then Planet[Plnt].OrbAngDeg = Planet[Plnt].OrbAngDeg + ANG_360
// Determine & set planet's circular path position based on it's angular position & radius
// Polar to rectangular: Z = R * cos(angle); X = R * sin(angle); angles in degrees
Planet[Plnt].zPos = Planet[Plnt].OrbitRadius * cos(Planet[Plnt].OrbAngDeg)
Planet[Plnt].xPos = Planet[Plnt].OrbitRadius * sin(Planet[Plnt].OrbAngDeg)
SetObjectPosition(Plnt, Planet[Plnt].xPos, Planet[Plnt].yPos, Planet[Plnt].zPos)
next
//Rotate sun using innermost planet angle (deg)
SetObjectRotation(1, 0, Planet[3].OrbAngDeg, 0)
// Update camera Y Height & Z Distance, while still looking at origin
SetCameraPosition(1, 0, CamHi, CamDis)
SetCameraLookAt(1, 0, 0, 0, 0)
// Update display
Sync()
until (KeyEsc)
end
// Define function to help populate planetary data table
function LoadPlanet(Id as integer, Ra as float, Sp as float, Sz as float, Rd as integer, Gr as integer, Bl as integer)
Planet[Id].OrbitRadius = Ra
Planet[Id].OrbitAngSpd = Sp
Planet[Id].Size = Sz
Planet[Id].Color.Red = Rd
Planet[Id].Color.Grn = Gr
Planet[Id].Color.Blu = Bl
Planet[Id].Color.Alp = 255
endfunction
Code every line like it might be your last...
Someday it will be.