Code:
public static Result Draw() {
var vertices = new PositionColored[3];
vertices[0] = new PositionColored(new Vector3(0.0f, 0.0f, 5.0f), 0xff00ff00);
vertices[1] = new PositionColored(new Vector3(5.0f, 0.0f, 0.0f), 0xff0000ff);
vertices[2] = new PositionColored(new Vector3(-5.0f, 0.0f, 0.0f), 0xffff0000);
Device.VertexShader = null;
Device.PixelShader = null;
CameraInfo cam = Helper.Magic.ReadStruct<CameraInfo>(camPtr);
Vector3 eyePt = cam.Pos; // XYZ location of my camera. Tested working + correct values
Vector3 lookAtPt = cam.Pos + cam.ViewMat1; // This part I'm pretty certain is wrong. I have my ViewMatrix broken up into 3 Vectors because I don't want to deal with unsafe code using 2d arrays. I think I just copied the method used by Harland in the third link (cam.Pos + new Vector3(Mat[0][0], Mat[0][1], Mat[0][2])
Vector3 upPt = new Vector3(0, 0, 1); // Up direction. I've seen people using both (0,0,1) and (0,1,0), so I've tried them both but neither have fixed my problem
Matrix matWorld = Matrix.Translation(tar.Location.X, tar.Location.Y, tar.Location.Z); // This should be the location where I'm trying to render the object, on top of my target in this case.
Matrix matView = Matrix.LookAtRH(eyePt, lookAtPt, upPt);
Matrix matProj = Matrix.PerspectiveFovRH(cam.FieldOfView * 0.6f, (float)(800/600), cam.NearPlane, cam.FarPlane);
Device.SetTransform(TransformState.World, matWorld);
Device.SetTransform(TransformState.View, matView);
Device.SetTransform(TransformState.Projection, matProj);
Result res = Device.DrawUserPrimitives(PrimitiveType.TriangleStrip, 1, vertices);
return res;
public struct CameraInfo
{
uint Unk1;
uint Unk2;
public Vector3 Pos;
public Vector3 ViewMat1;
public Vector3 ViewMat2;
public Vector3 ViewMat3;
public float FieldOfView;
float Unk3;
int Unk4;
public float NearPlane;
public float FarPlane;
}
}
EDIT: I now have the projection working - it correctly renders a box over any unit that I specify, I can draw lines to/between units, etc. However, I still have two problems - first, the my rendering is still only shown when I mouse over a unit. I can't for the life of me figure out how to fix this. The rendered boxes also flash on and off when I start writing in the chat box (like when the typing positioner thing blinks on and off as normal, so does my rendered box). I can temporarily fix this in a really dirty way by using a script to show the tooltip (