The Wizards Engine : Rendering

This page describes how to use the rendering capabilities of the engine.

Objects

The engine can render 3D objects in the world. This is done by using the Physical class.

// Create new physical. This will immediately place it in the world at the set position
var p = new Physical();
p.Mesh = myMesh;
p.WorldMatrix = Matrix.Translation(new Vector3(10,2,4));
var bb = p.GetBoundingBox(); // gets the bounding box
 
// To remove the Physical from existence
TW.Data.Objects.Remove(p);

Meshes

Meshes are used by the engine to represent the data of a 3D model. These meshes can be loaded from file, or created dynamically:

// IMesh is the interface respresenting a mesh
IMesh mesh;
 
// This loads the model located in the gamedata folder. (/bin/GameData/SkyMerchant/MyModel.obj)
// Do NOT add an extension after this path!!! (detected automatically)
mesh = TW.Assets.LoadMesh("SkyMerchant/MyModel");
 
// Creates a box 1x1x1 with "Hello" on it
mesh = UtilityMeshes.CreateMeshWithText(1,"Hello",TW.Graphics);
 
// Creates a box 1x1x1 with "Hello" on it
// Also relative to (/bin/GameData). NOTE ADD THE EXTENSION FOR TEXTURES!!
mesh = UtilityMeshes.CreateMeshWithTexture(1,TW.Assets.LoadTexture("SkyMerchant/Gold.jpg"));

Camera

You can manipulate the camera in the engine using the CameraInfo Singleton. You often need the center screen ray:

// Get access to the camera settings
var info = TW.Data.Get<CameraInfo>();
 
// Gets a ray starting from the camera eye into the look direction, located at the center of the screen.
var ray = info.GetCenterScreenRay();

If you wan't to use a custom camera, you can use the following code:

// Create the view matrices
var view = Matrix.LookAtRH(eye, target, Vector3.UnitY);
var projection = Matrix.PerspectiveRH(800, 600, 0.1f, 1000);
 
// Create a camera to use as a custom camera.
var customCam = new CustomCamera();
customCam.SetViewProjectionMatrix(view, projection);
 
// Get access to the camera settings
var info = TW.Data.Get<CameraInfo>();
info.ActivateCustomCamera(customCam); // Activate your camera
info.ActivateSpecatorCamera(); // Activate the default specator camera

Line rendering

You can render lines using the LineManager. You can render a variety of line based primitives!

Note that you have to call this every frame in your gameloop, because lines are only rendered for the current frame!

TW.Graphics.LineManager3D.AddLine(start,end,color); // More using the intellisense!

 

2D rendering

TODO