CSharp .Net Tutorial: Reading Mouse Input in Truevision 3D

James Cloud
Introduction

Mouse input data, such as the mouse's position and the status of its buttons, are used in most computer games. 3D shooters, real time strategy games, and the like use this information to tell if the user is firing the weapon, clicking a certain unit, or selecting a part of the graphical user interface. However, whatever its use, this data can be used in most Truevision 3D projects for debugging purposes. Below is highlighted two steps on how to retrieve mouse data using Truevision 3D.

Step One - Input Device

An instance of the TVInputEngine is required to read user input in Truevision 3D projects. Add this definition like so,

public TVInputEngine inputEngine;

And, initialize the input engine before the main loop,

// Initialize the Input Controls
inputEngine = new TVInputEngine();
inputEngine.Initialize(true, true);

Step Two - Reading Mouse Data

As with rendering, loading resources, etc. it is good to have a separate function for reading the user's input. Create a void called 'checkInput()' using the source code supplied below.

private void checkInput()
{
// Data Holders
int aX = 0;
int aY = 0;
bool bBut1 = false;
bool bBut2 = false;
bool bBut3 = false;

// Read the Mouse Data
inputEngine.GetMouseState(ref aX, ref aY, ref bBut1, ref bBut2, ref bBut3);

// Add Code Here

}

Make sure to call the newly created 'checkInput()' method in your main loop for the variables ax, ay, bBut1, bBut2, and bBut3 to be constantly updated with the current status of the mouse.

Conclusion

In the input checking function, the mouse's data is stored into the aX, aY, bBut1, bBut2, and bBut3 variables. aX and aY contain the mouse's x(horizontal) and y(vertical) positions, respectively. The bBut1, bBut2, and bBut3 booleans contain the mouse's button status from button 1 through button 3. You could declare these variables globally if you would like to access them outside of the 'checkInput' function.

Published by James Cloud

I like to program and do basically anything that has to do with technology and computers.  View profile

To comment, please sign in to your Yahoo! account, or sign up for a new account.