news about forums links tools tutorials contact

(Draw) Portal HUD - author: luke wenke
    class PortalsHUD extends UnrealHUD;

    // This is a subclass of UnrealHUD which adds portals to your view,
    // you could also subclass UT's ChallengeHUD to add the portals in UT.

    function PostRender(canvas Canvas)
    {
    // A function called DrawPortal will be used four times to create
    // four extra views.  DrawPortal is a function of the Canvas. Here
    // is the function definition:
    // Canvas.DrawPortal(int X, int Y, int Width, int Height, actor CamActor,
    //                   vector CamLocation, rotator CamRotation,
    //                   optional int FOV, optional bool ClearZ);
    //
    // Note: (this is for Unreal 224- the problems may be fixed in later verisons)
    //
    // - Sprites are reflected from the right side of the screen to the left, and
    // from the bottom of the screen to the top, so it is best to use DrawPortal
    // at the top-left corner, or taking up the whole top or whole left of the
    // screen.
    //
    // - The player's mesh won't display unless the player's bBehindView is True
    // (you can type "behindview 1" and "behindview 0" in the console to turn
    // the behindview on and off)
    //
    // - The sound is only calculated for the player's main camera and not for the
    // extra views.
    //
    // - The CamActor parameter currently doesn't do anything, but you need to put
    // in a valid actor there so that the script compiles.
    //
    // - ClearZ specifies whether the Z-buffer should be cleared or not- this doesn't
    // seem to make any difference.
    //
    // - The portals do not resize and reposition themselves when you adjust
    // the screen-size using + and -.
    //
    // - Parts of the portals which are not part of the world are not visible
    // (instead of being black) to see this in action, move into walls
    // while watching the "facing player cam" portal.

      local Projectile projectile1, proj;
      local Pawn pawn1, p;
      local rotator CirclingRotation;

      projectile1 = None;

      // Pick the last found projectile (the newest one)
      foreach AllActors(class'projectile', proj)
        projectile1 = proj;

      pawn1 = None;
      foreach AllActors(class'Pawn', p)
        // If the pawn is not the player and is not a HorseFly
        // (portals using individual FlockPawns such as HorseFlies crash
        // Unreal for some reason).
        if (p != owner && !p.IsA('FlockPawn'))
          // pick the last found pawn (the newest one)
          pawn1 = p;

      // Setup the font
      Canvas.Reset();
      Canvas.Font = Canvas.MedFont;
      Canvas.DrawColor.r = 255;
      Canvas.DrawColor.g = 255;
      Canvas.DrawColor.b = 255;

      // Projectile cam
      if (projectile1 != None)
      {
        // Portal's starting X
        // (the number of pixels from the left side of the screen)
        Canvas.DrawPortal(0,

        // Portal's starting Y
        // (the number of pixels from the top of the screen)
        0,

        // height of the portal (30% of the total screen width)
        Canvas.SizeX*0.3,

        // width of the portal (30% of the total screen height)
        Canvas.SizeY*0.3,

        // the camera actor
        // it doesn't seem to make any difference what you put here,
        // as long as it is a valid actor
        self,

        // the location of the camera (40 units behind the projectile)
        projectile1.Location -40 * vector(projectile1.Rotation),

        // the rotation of the camera
        projectile1.Rotation,

        // the field of view angle of the camera (optional)
        90);

        // Display the title for the portal
        Canvas.SetPos(Canvas.SizeX*0.02, Canvas.SizeY*0.05);
        Canvas.DrawText("Projectile Cam");

        // Display the name of the projectile
        Canvas.SetPos(Canvas.SizeX*0.02, Canvas.SizeY*0.25);
        Canvas.DrawText(projectile1.name);
      }

      // pawn cam
      if (pawn1 != None)
      {
        Canvas.DrawPortal(Canvas.SizeX*0.7,
        0,
        Canvas.SizeX*0.3,
        Canvas.SizeY*0.3,
        self,
        pawn1.Location,
        pawn1.Rotation);

        // Display the title for the portal
        Canvas.SetPos(Canvas.SizeX*0.72, Canvas.SizeY*0.05);
        Canvas.DrawText("Pawn Cam");

        // Display the name of the projectile
        Canvas.SetPos(Canvas.SizeX*0.72, Canvas.SizeY*0.25);
        Canvas.DrawText(pawn1.name);
      }

      // facing player cam
      // these two portals turn on if behindview is on
      if (PlayerPawn(owner).bBehindView)
      {
         Canvas.DrawPortal(0,
         Canvas.SizeY*0.7,
         Canvas.SizeX*0.3,
         Canvas.SizeY*0.3,
         self,

         // Start at the player's location and move 100 units
         // in the direction in which they are facing.
         owner.Location + 100*vector(owner.Rotation),

        // Make the camera have the opposite rotation to the player
        // by converting the rotation to a vector, inverting the vector,
        // and converting the vector to a rotation.
        rotator(-vector(owner.Rotation)));

        // Display the title for the portal
        Canvas.SetPos(Canvas.SizeX*0.02, Canvas.SizeY*0.75);
        Canvas.DrawText("Facing Player Cam");

        // Circling player camera
        // Begin with the player's rotation,
        CirclingRotation = owner.Rotation;

        // look down,
        CirclingRotation.Pitch -= 8000;

        // and rotate every 10 seconds.
        CirclingRotation.Yaw = (Level.TimeSeconds*65536) / 10;

        Canvas.DrawPortal(Canvas.SizeX*0.7,
        Canvas.SizeY*0.7,
        Canvas.SizeX*0.3,
        Canvas.SizeY*0.3,
        self,

        // Start at the player's location and go backwards 60 units
        // in the direction of the circling rotation.
        owner.Location - 60*vector(CirclingRotation),

        // Give the camera the circling rotation
        CirclingRotation);

        // display the title for the portal
        Canvas.SetPos(Canvas.SizeX*0.72, Canvas.SizeY*0.75);
        Canvas.DrawText("Circling Player Cam");
      }

      // Draw the menu and UnrealHUD on top by calling the PostRender
      // function in our parent class.
      Super.PostRender(Canvas);
    }

    class PortalsGameInfo extends UnrealGameInfo;

    // In order to have players use the new HUD with portals just make
    // a new gametype, and set the HUDType variable to the new HUD class.

    defaultproperties
    {
    HUDType=PortalsHUD
    }