Advertisement
Guest User

ZScript - Viewport 2D target projection error

a guest
Apr 24th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.76 KB | None | 0 0
  1.     void DrawMainBar (double TicFrac)
  2.     {
  3.         if(CPlayer && CPlayer.mo)
  4.         {      
  5.             let mech = MechWarrior(CPlayer.mo);
  6.             if(!mech)return;
  7.            
  8.             if(mech.targetenemy && mech.targetenemy.health > 0)
  9.             {
  10.                 Actor target = mech.targetenemy;
  11.                
  12.                 vector2 screencoords;
  13.                 vector3 fromworldpos;
  14.                 vector3 eyepos = (mech.pos.x, mech.pos.y, mech.pos.z);
  15.                
  16.                 double distance = mech.Distance3D(target);
  17.                 float viewfov = mech.player.FOV;
  18.                
  19.                 bool behind;
  20.                
  21.                 console.printf("%f",mech.pitch);
  22.                
  23.                 fromworldpos = MWD_CoordUtil.WorldToScreen(target.pos,eyepos,mech.pitch,mech.angle,mech.roll,viewfov);
  24.                 [screencoords, behind] = MWD_CoordUtil.toViewport(fromworldpos);
  25.                
  26.                 if (-1 < fromworldpos.z && fromworldpos.z <= 1)
  27.                 {
  28.                       // this is the coordinates where you're drawing to:
  29.                       if (distance == 0) { return; }
  30.  
  31.                       double  height        = target.height;
  32.                       double  radius        = target.radius;
  33.                       double  visibleRadius = radius * 2000.0 / distance;
  34.                       double  visibleHeight = height * 1000.0 / distance;
  35.  
  36.                       Vector2 left   = (screencoords.x - visibleRadius / 2.0, screencoords.y);
  37.                       Vector2 right  = (screencoords.x + visibleRadius / 2.0, screencoords.y);
  38.                       Vector2 top    = (screencoords.x, screencoords.y - visibleHeight / 2.0);
  39.                       Vector2 bottom = (screencoords.x, screencoords.y + visibleHeight / 2.0);
  40.  
  41.                       Vector2 topLeft     = (left.x,  top.y);
  42.                       Vector2 topRight    = (right.x, top.y);
  43.                       Vector2 bottomLeft  = (left.x,  bottom.y);
  44.                       Vector2 bottomRight = (right.x, bottom.y);
  45.                    
  46.                       DrawImage("RETCA0",topLeft,0,1.0);
  47.                       DrawImage("RETCB0",topRight,0,1.0);
  48.                       DrawImage("RETCC0",bottomLeft,0,1.0);
  49.                       DrawImage("RETCD0",bottomRight,0,1.0);
  50.                  }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement