World Matrix for Line Graph

Started by
0 comments, last by GameDev.net 18 years ago
Hello guys... I need help formulating a world matrix for a line graph control that is using DirectX for rendering. Previously I was using GDI, but performing transformations per-frame was causing too large of a performance hit. I migrated to DirectX so I would be able to use hardware transformations (a one-time hit for generating a world matrix and letting the GPU do most of the calculations, as opposed to 100% CPU calculations). I am using C# w/ Managed DirectX 9. The view and projection matrices are as follows:
this.d3dDevice.Transform.View = Matrix.LookAtLH(new Vector3(0.0f, 0.0f, -1.5f), new Vector3(0.0f, 0.0f, 0.0f), new Vector3(0.0f, 1.0f, 0.0f));

this.d3dDevice.Transform.Projection = Matrix.PerspectiveFovLH((float)Math.PI / 4, 1.0f, 1.0f, 100.0f);
Each line is represented pragmatically as a data channel. Currently I generate the vertices as a line strip with the X-position as the time (every 1.0f is one second), and the Y-position the value of that data sample in the data channel. Currently the world matrix (per data channel) is calculated as follows:
channel.WorldTransform = Matrix.Scaling(1000.0f / (float)(timeScale), 1.0f / (channel.Max - channel.Min), 0.0f) *
   Matrix.Translation(-(float)viewTimeMin / (float)timeScale - (float)Math.PI / 8, -channel.Min - (float)Math.PI / 8 * 1.5f, 0.0f);
The scaling is used to fit the data channel into the view. The timeScale value for X is the amount of time that is to be displayed in ms (by default this is 15000ms). The Y scaling is then 1.0f divided by the maximum value minus the minimum value of the data channel, so that the maximum value is at the top of the screen and the minimum value is at the bottom of the screen. There is no scaling along the Z-axis. I then perform a translation along the X-axis of the current viewable time minimum (in ms) divided by the current time scale minus 1/2 of the Y-field of view. The Y-axis translation is calculated as the negative of the minimum channel value minus 1/2 of the Y-field of view multiplied by 1.5f (on suggestion from a colleague, gave good results). There is no translation along the Z-axis. I hope this makes sense, I would greatly appreciate any help. We've been sitting down trying to formulate an equation for the world matrix calculations for almost a week with no solid results. While this does seem to work to an extent, the translation and scaling are off as compared to the GDI version. The GDI version used the following formula to perform the transformations:
private PointF TransformSample(RectangleF fromSpace, RectangleF toSpace, DataSample sample)
{
	float xValue = (float)sample.TimeStamp;
	float yValue = (float)sample.ConvertedData;
	PointF retVal = new PointF();

	retVal.X = (((xValue - fromSpace.Left) / fromSpace.Width) * toSpace.Width) + toSpace.Left;
	retVal.Y = (((yValue - fromSpace.Top) / fromSpace.Height) * toSpace.Height) + toSpace.Top;

	return retVal;
}
An example of fromSpace is:
RectangleF dataRegion = new RectangleF((float)viewTimeMin, channel.Min, viewTimeDiff, viewChannelDiff);
An example of toSpace is:
RectangleF screenSpace = new RectangleF(0, 0, this.graphArea, this.graphArea.Width, this.graphArea.Height);
Thanks guys!
- ObikeCodito Ergo Sum.
Advertisement
Bah... simple solution. Needed to set the view matrix to the identity and remove Pi from all calculations. That removed all necessary calculation workarounds for the view.

This topic is closed to new replies.

Advertisement