i am trying to find efficient way to get labels working for objects in my game. i hope others will find it useful.
i attached the image to make things clear in what i am trying to do.
Uploaded with ImageShack.us
so, let us say that i have four objects in the scene and they are placed around origin (0,0,0), when i click on any of those objects i want to get the label that will explain to me what that object is. i figured out that the best way to make labels is to have the line (that will be rendered with opengl calls) that will point from object to the Rect that will have all the information bound to the given object. direction of the line will be determined by the vector direction made out of the origin point and the point where the object is in the space. also point where the line will connect to the rect should be calculated in what quadrant object is (negative or positive x and y axis)… that is the idea, probably will improve it later.
i would like it to be class that i could reuse in other projects. i started to write the code, but i can’t figure out what is the best practice.
here is what i know:
i can get transfor of the current object from camera class like this:
var currentTransform : Transform=cam.currentTarget;
this will be used for calculating end point of the line (first one is the objects position) based on the vector direction from origin to the object.
-how to get the camera reference inside the class?
-how to check in what quadrant the object is?
-how to use the class and where the class object should be instantiated? in the camera of GUI scripts?
here is the base of the class i got so far (not really much, i am beginner in these types of things as you can see) any help is appreciated.
//REFERENCE TO CAMERA
var cam : MainCamera;
class Labels extends Object{
var bToRender : boolean = false;
var startPosition : Vector3;
var endPosition : Vector3;
//INITIALIZATION FUNCTION THAT WILL
//GET THE CAMERA REFERENCE
function Initialize(){
}
function ShowLabel(){
}
function CalculateHandlePoints(){
}
function DrawHandle(){
}
//THIS FUNCTION ACTUALLY RENDERS
//EVERYTHING
function OnPostRender(){
if(bToRender){
CreateLineMaterial();
lineMaterial.SetPass(0);
GL.Begin(GL.LINES);
GL.Color(Color(1,1,1,1));
GL.Vertex3(startPosition.x ,startPosition.y, startPosition.z);
GL.Vertex3(endPosition.y ,endPosition.y,endPosition.z);
GL.End();
}
}
}