3D Rad - Free 3D game maker - Forum

This forum is now archived!

This forum is locked, and is a read-only version. A new community-ran forum can be found at classdev.net

News:

The 3DRad community can be found at classdev.net.

Pages: [1]

Author Topic: Function - iPrint to Screen with Offset  (Read 540 times)

fourdee

« on: February 03, 2013, 10:18:29 AM »
Hi all,

I thought its about time i started contributing to the 3Drad script database.
I've learnt so much from using Jestermon's L2P function, and, other user scripting examples.

I was playing around with my new "dev mode".
I wanted to have multiple text info on screen, at various locations, with offsets.
Apologies if something similar has been done/shared before. But this is all my own work from scratch.

My goals were:
- Use only 1 text print object (by using iPrint instead of the iObjectLocationSet(TEXT))
- Be able to print multiple text values using the i3DLocationToScreen
- Print a description (string) and a value (float)
- Have a Vector offset which is applied with the objects rotation
- All in one easy to use function

And here it is!
Code: [Select]
//--------- Screen iPrint using Vectors/quats ---------------------
//if you already have Vectors/Quats, throw them into this function

void FUNC_v3_iprint(Vector3 v3_target,Quaternion q_target,Vector3 v3_offset,float input,string description){
   Vector3 v3_text;
   Vector3 v3_cam;
   string value;

   iObjectLocation(CAM,v3_cam);

   if(v3_offset.x !=0){v3_offset.x *= 1 + (iVectorLength(v3_cam - v3_target)/8);}
   if(v3_offset.y !=0){v3_offset.y *= 1 + (iVectorLength(v3_cam - v3_target)/8);}
   iVectorRotate(v3_offset,v3_offset,q_target);

   v3_target += v3_offset;

   i3DLocationToScreen(v3_text,v3_target,CAM);
   if(v3_text.x !=1000000000 || v3_text.y !=1000000000){//behind the camera
         iStringStr(value,input,"%.0f");
         iPrint(description,v3_text.x,v3_text.y,TEXT_PRINT);
         if(input != -1337){iPrint(value,v3_text.x,v3_text.y - 1,TEXT_PRINT);}
      }
}

//---------- Screen iPrint using Objects --------------------------

void FUNC_obj_iprint(int OBJ_TARGET,Vector3 v3_offset,float input,string description){
   string value;
   Vector3 v3_text;
   Vector3 v3_cam;
   Vector3 v3_target;
   Quaternion q_target;

   //Get target Object location/rotations - create Vector/Quat
   iObjectLocation(CAM,v3_cam);
   iObjectLocation(OBJ_TARGET,v3_target);
   iObjectOrientation(OBJ_TARGET,q_target);

   //Scan length from Camera to the Object target, and.....
   //Multiply the offset vector values against its distance results
   if(v3_offset.x !=0){v3_offset.x *= 1 + (iVectorLength(v3_cam - v3_target)/8);}
   if(v3_offset.y !=0){v3_offset.y *= 1 + (iVectorLength(v3_cam - v3_target)/8);}

   //Rotate the Offset Vector to match the target
   iVectorRotate(v3_offset,v3_offset,q_target);

   //Apply the Offset Vector to the target Vector
   v3_target += v3_offset;

   //Compute screen location to Target Vector
   i3DLocationToScreen(v3_text,v3_target,CAM);
   if(v3_text.x !=1000000000 || v3_text.y !=1000000000){//behind the camera, prevent iprint
         iStringStr(value,input,"%.0f");
         iPrint(description,v3_text.x,v3_text.y,TEXT_PRINT);//Print description
         if(input != -1337){iPrint(value,v3_text.x,v3_text.y - 0.4,TEXT_PRINT);}//Print Value under
      }

}

//--------------------------------------------------------------------

int TEXT_PRINT = OBJ_44;
int CAR = OBJ_22;
int CAM = OBJ_0;

float speed = 0f;
float steering = 0f;

void Main(){

   if(iInitializing()){iObjectLocationSet(TEXT_PRINT,Vector3(0,0,0));}

   speed = IN_22;
   steering = IN_24;

   //            target   -  offset - value - description
   FUNC_obj_iprint(CAR,Vector3(0,0,2),speed,"Front");
   FUNC_obj_iprint(CAR,Vector3(0,0,-2),speed,"Back");
   FUNC_obj_iprint(CAR,Vector3(-1,0,0),steering,"Left");
   FUNC_obj_iprint(CAR,Vector3(1,0,0),steering,"Right");
   FUNC_obj_iprint(CAR,Vector3(0,1,0),speed,"Top");

   //use -1337 as the input float to disable value/float text
   FUNC_obj_iprint(CAR,Vector3(0,-0.5,0),-1337,"TextOnly");

}

Features i want, but cant see a way round:
Rotate the text with the target
- iObjectOrientationSet(TEXT) does nothing
- Cant use multiple font.dds files (animations with fake rotations)

Scale text with distance
- Just not possible with iPrint, or even by the object textprint inputs

Change colour for iPrint
- Just not possible with iPrint, Only by changing the whole textprint colour

If anyone knows a way past the above issues, please let me know!


I'll also be looking at a way of hiding the text if its infront of another, but, thats something for another day :)

Files below.
Cheers.

Some tests in Tr0n (dev_mode):

« Last Edit: February 03, 2013, 10:39:55 AM by Fourdee »
« Reply #1 on: February 03, 2013, 03:05:10 PM »
iPrint(string,float,float,OBJ_X)

Screen resolution 32x24 for all sprites. Textprint uses built-in unchangable sprites.
Screen locations -16 to +16, -12 to +12
« Last Edit: March 26, 2013, 08:16:55 AM by XingBat »

secondry2

« Reply #2 on: February 04, 2013, 12:44:14 AM »
thax for sharing! Appreciate it ;)
Pages: [1]