Forums Gallery LOGIN |REGISTER

Community Archive is read-only - Here you can view content recorded up until February 2017. To join the latest discussions visit our new forums


Third Person Weapon Attachment Zoom Tutorial

Help others by sharing your tutorials here.


 

User avatar RealmRPGer
Just getting started
Just getting started
 
Posts: 57
Member since: 10.04.2008, 04:43
Location: Bellevue, WA
Likes: 0

Third Person Weapon Attachment Zoom Tutorial

Postby RealmRPGer » 26.05.2008, 15:55

This is the tutorial on how to implement the mod shown here

Alright, well, so, I never managed to get the first person weapons to correctly display in third-person mode, but I haven't worked on the mod in over a month, and since it no longer really much applies to my grand mod, I figured I'd show what I currently have and hope somebody else will implement the last step.


Zooming in and Out

The main part of this mod is the camera zoom. First, however, we're going to have to add a custom function to Item.h so that we can distinguish between a zoom IN and a zoom OUT.

Go down to about line 816 in Item.h and add the following:

Code: Select all
virtual bool IsModifying() { return m_modifying || m_transitioning; }
virtual bool IsEnteringModify() { return m_modifying; } //Add this line
virtual bool IsDestroyed() { return m_properties.hitpoints > 0 && m_stats.health <= 0.f; }


All right. Now we can do the zooming!

Open up PlayerView.cpp and enter function ViewThirdPerson around line 446.

We need three new variables for our camera zoom. These can be created as member variables of CPlayerView, but since this is localized to this function -- and the Crysis dev team used it for GOC view -- I chose to make them static variables of the function:

static float zoomAmount = 0;
static float curInter = 0;
static Quat baseRotation;

If you choose to also make them static, put them towards the top of the function.

This next chunk of the code is where the magic happens:

Code: Select all
IActor* pActor = g_pGame->GetIGameFramework()->GetIActorSystem()->GetActor(m_in.entityId);
if (pActor)
{
   IItem* pItem = pActor->GetCurrentItem();
   if (pItem)
   {
      CWeapon* pWeapon = (CWeapon*)pItem->GetIWeapon();

      if(pWeapon->IsModifying() || zoomAmount > 0 || curInter > 0)
      {

         if(zoomAmount == 0)
            baseRotation = viewParams.rotation;
         
         IActor *owner = gEnv->pGame->GetIGameFramework()->GetIActorSystem()->GetActor(m_in.entityId);
         if(owner && owner->IsPlayer())
         {

            if(pWeapon->IsEnteringModify())
            {
               if(zoomAmount < 1.0f)
                  zoomAmount += 2.25f * m_in.frameTime;
               if(zoomAmount > 1.0f)
                  zoomAmount = 1.0f;
            }
            else
            {
               if(zoomAmount > 0)
                  zoomAmount -= 2.25f* m_in.frameTime;
               if(zoomAmount < 0)
                  zoomAmount = 0;
            }

            Interpolate(curInter, zoomAmount,5.0f, m_in.frameTime);
            

            Quat q = owner->GetEntity()->GetRotation();

            q *= Quat::CreateRotationXYZ(Ang3(-gf_PI/4.0f,gf_PI/6.0f,-gf_PI/3.0f));

            viewParams.rotation = Quat::CreateSlerp(baseRotation,q,curInter);//q;
            m_io.viewQuatFinal = viewParams.rotation;

            
         }
      }

   }
}


To break it down a little:

The first portion just does some sanity checks to make sure there's a player and he/she has a weapon.

if(pWeapon->IsModifying() || zoomAmount > 0 || curInter > 0)
This simply checks to see if the player is currently modifying the weapon. I made the zoom take a bit longer than the character animation, which means we have to continue to zoom out a bit after the character is technically no longer modifying the weapon. zoomAmount is therefore likely unnecessary, but we'll keep it in just for fun.

Code: Select all
if(zoomAmount == 0)
   baseRotation = viewParams.rotation;

zoomAmount is zero when the camera isn't zoomed at all (go figure). We set baseRotation to the original camera rotation so that we can do a nice interpolation with it.

The next line is another sanity check. Don't ask me why it's way down here.

if(pWeapon->IsEnteringModify())

This section just sets the base zoom-in and out values. You can edit these numbers to increase or decrease the speed of the zoom. Notice that we use the function we created earlier in Item.h here.

Interpolate simply creates a smooth ease-in interpolation between the base zoom value, zoomAmount, and the one that will be used, curInter.

CreateRotationXYZ defines the final camera orientation when zooming in is complete. If you dislike the current orientation or want to tweak it a little, modify these values.

CreateSlerp does basically the same thing is Interpolate (yep, that's right, double interpolation here!).


Now let's hook it in with the camera modes.

The block of code starting with if (g_pGameCVars->goc_enable) defines the GOC-mode behavior. We're going to modify a couple of lines here to make it work with our zoom:

Code: Select all
if (g_pGameCVars->goc_enable)
{
//NEW STUFF BEGINS HERE
   Vec3 target(g_pGameCVars->goc_targetx * (1.0f - zoomAmount) + (zoomAmount * .25f),
      (1.0f - zoomAmount)*g_pGameCVars->goc_targety, g_pGameCVars->goc_targetz);
//END OF NEW STUFF
   static Vec3 current(target);

   Interpolate(current, target, 5.0f, m_in.frameTime);

   // make sure we don't clip through stuff that much
   Vec3 offsetX(0,0,0);
   Vec3 offsetY(0,0,0);
   Vec3 offsetZ(0,0,0);
   offsetX = m_io.viewQuatFinal.GetColumn0() * current.x;
   offsetY = m_io.viewQuatFinal.GetColumn1() * current.y;
   offsetZ = m_io.viewQuatFinal.GetColumn2() * current.z;

   IActor* pActor = g_pGame->GetIGameFramework()->GetIActorSystem()->GetActor(m_in.entityId);
   if (pActor)
   {
      static ray_hit hit;   
      IPhysicalEntity* pSkipEntities[10];
      int nSkip = 0;
      IItem* pItem = pActor->GetCurrentItem();
      if (pItem)
      {
         CWeapon* pWeapon = (CWeapon*)pItem->GetIWeapon();
         if (pWeapon)
             nSkip = CSingle::GetSkipEntities(pWeapon, pSkipEntities, 10);
      }

      float oldLen = offsetY.len();

      Vec3 start = m_io.baseQuat * m_io.eyeOffsetView + viewParams.position+offsetX+offsetZ;
      if (gEnv->pPhysicalWorld->RayWorldIntersection(start, offsetY, ent_static|ent_terrain|ent_rigid,
         rwi_ignore_noncolliding | rwi_stop_at_pierceable, &hit, 1, pSkipEntities, nSkip))
      {
         offsetY = hit.pt - start;
         if (offsetY.len()> 0.25f)
         {
            offsetY -= offsetY.GetNormalized()*0.25f;
         }
         current.y = current.y * (hit.dist/oldLen);
      }
   }
   
   //viewParams.position += m_io.viewQuatFinal.GetColumn0() * current.x;      // right
   //viewParams.position += m_io.viewQuatFinal.GetColumn1() * current.y;   // back
   //viewParams.position += m_io.viewQuatFinal.GetColumn2() * current.z;   // up
   viewParams.position += offsetX + offsetY + offsetZ;
}
else
{
if (m_io.bUsePivot)         
   viewParams.position += m_io.viewQuatFinal.GetColumn1() * m_in.params_viewDistance + m_io.viewQuatFinal.GetColumn2() * (0.25f + m_in.params_viewHeightOffset);
else
   {
//NEW STUFF BEGINS HERE
      viewParams.position += m_io.viewQuatFinal.GetColumn0() * 0.2f +
         m_io.viewQuatFinal.GetColumn1() * -m_in.thirdPersonDistance* ((1.0f/1024.f)* (1 + (1.0f - curInter)*1024))+ m_io.viewQuatFinal.GetColumn2() * (0.25f + m_in.params_viewHeightOffset);
//END OF NEW STUFF
   }
}


Lines 3 and 59 contain the modified code.

The other section we modified at the bottom defines the normal (dev-mode) third person view. With this code, our camera now correctly zooms in and out when you open the weapon attachment hud!

Editing the HUD

This next section is bit of a work in progress. You'll notice a few obscurities with some of the weapons when you try to modify them in third person. This is because the weapon models use Helpers to determine the slot positions, and some of the third person models don't define these. The camera angle setup in the previous section also isn't the same angle as in first person, and the HUD contains offsets so that they display a bit better (in first person mode). The section to modify this is in Hud.cpp, in OnPostUpdate, around line 3343.

Look for the line (or do a search for it) if(pCurrentWeapon && pCurrentWeapon->IsModifying()).

First off, change the line if (helper.slot != CItem::eIGS_FirstPerson) to
if (helper.slot != CItem::eIGS_FirstPerson && helper.slot != CItem::eIGS_ThirdPerson)

Technically, weapons are supposed to be defined based on whether their first person or third person, but some of the third person weapons are set to the first person slot.

The other suspect is AdjustWeaponAccessory. You can have the game not use this if you're third person mode, keep it, or maybe write your own function for handling the offsets.

Of course, neither of these modifications are necessary if the weapon model is changed to the first person one... So I'd suggest working on that first.



Well, there you have it. The long-awaited third person zoom. Try it out and tell me if you have any problems, as it's very possible I missed something.
Last edited by RealmRPGer on 26.05.2008, 16:10, edited 3 times in total.
User avatar chuckles
Just getting started
Just getting started
 
Posts: 17
Member since: 30.05.2008, 01:23
Likes: 0

RE: Third Person Weapon Attachment Zoom Tutorial

Postby chuckles » 01.06.2008, 22:19

Can't you modify some of these in the XML for each weapon?

\Game\Scripts\Entities\Items\XML\Weapons\SOCOM.xml -for example.


I know you can change the model to the 1st person one using this, but it won't be in the right place. I think you can also change or add helpers...
User avatar RealmRPGer
Just getting started
Just getting started
 
Posts: 57
Member since: 10.04.2008, 04:43
Location: Bellevue, WA
Likes: 0

RE: Third Person Weapon Attachment Zoom Tutorial

Postby RealmRPGer » 03.06.2008, 01:38

Originally posted by chuckles
Can't you modify some of these in the XML for each weapon?

\Game\Scripts\Entities\Items\XML\Weapons\SOCOM.xml -for example.


I know you can change the model to the 1st person one using this, but it won't be in the right place. I think you can also change or add helpers...


Sure, you can modify the third person weapons, but the idea behind this mod is that it automatically works with any weapons created for first person mode.
User avatar Lenox47
Intern Dev
Intern Dev
 
Posts: 180
Member since: 09.02.2008, 18:08
Location: France
Likes: 7

Postby Lenox47 » 24.01.2009, 14:43

Could you make a pre-made? With the code of the Third Person Weapon Attachment Zoom and the GOC. Because I use for my future GOC MOD Butterfly! That would be really nice because I do not even with the tutorial, though, I'm French but I understand maybe not XD


Thanks :)
User avatar CoD511
Honourable Member
Honourable Member
 
Posts: 6361
Member since: 21.12.2007, 04:15
Location: Western Australia
Likes: 17

Postby CoD511 » 24.01.2009, 14:51

Originally posted by Lenox47
Could you make a pre-made? With the code of the Third Person Weapon Attachment Zoom and the GOC. Because I use for my future GOC MOD Butterfly! That would be really nice because I do not even with the tutorial, though, I'm French but I understand maybe not XD


Thanks :)


You do realize this thread is six, going onto seven, months old? And that the author hasn't logged into Crymod for 6 months either? ;)
The years have passed rapidly but the memories remain fresh.
User avatar Lenox47
Intern Dev
Intern Dev
 
Posts: 180
Member since: 09.02.2008, 18:08
Location: France
Likes: 7

Postby Lenox47 » 24.01.2009, 14:54

ah ok ... thin lol

But maybe someone could help me anyway, not necessarily RealmRPGer!

I really need this script, just a file with the script in fact already included.
User avatar Dxslayer
Executive Producer
Executive Producer
 
Posts: 3812
Member since: 22.07.2008, 20:57
Location: California, US
Likes: 0

Postby Dxslayer » 24.01.2009, 21:19

8o
I'll get back to modding once Crysis 2 is out
:)
'till then stay well my peeps

Image
User avatar RealmRPGer
Just getting started
Just getting started
 
Posts: 57
Member since: 10.04.2008, 04:43
Location: Bellevue, WA
Likes: 0

Postby RealmRPGer » 24.01.2009, 22:43

I may not have logged in for a while, but that doesn't mean I'm not watching. ;)

This tutorial was created so that other people could incorporate the mod into their own, as there's already some fairly extensive mod compilations out there. I might release this as a standalone mod, however.
User avatar Melekai
Regular Dev
Regular Dev
 
Posts: 551
Member since: 17.10.2008, 01:57
Likes: 0

Postby Melekai » 25.01.2009, 19:22

Im glad this thread was bumped up. It does help a bit. i will most defaintly use this.

could a similar method be used to move the camera rather than just zoom?
User avatar RealmRPGer
Just getting started
Just getting started
 
Posts: 57
Member since: 10.04.2008, 04:43
Location: Bellevue, WA
Likes: 0

Postby RealmRPGer » 25.01.2009, 22:54

Yes, the camera could be moved. Take a look at the GOC mode section and the xOffset, yOffset, and zOffset variables.
User avatar Melekai
Regular Dev
Regular Dev
 
Posts: 551
Member since: 17.10.2008, 01:57
Likes: 0

Postby Melekai » 25.01.2009, 23:12

excellent. now i just need to c++ compiler for both 32 and 64 bit :P
User avatar Lenox47
Intern Dev
Intern Dev
 
Posts: 180
Member since: 09.02.2008, 18:08
Location: France
Likes: 7

Postby Lenox47 » 26.01.2009, 19:35

Well, if i want a file with this mod it's because i don't compile my mod...i have a bug with Visual Basic ;(
User avatar b94
Senior Developer
Senior Developer
 
Posts: 884
Member since: 10.05.2008, 21:35
Location: Puyallup, Washington, USA
Likes: 0

Postby b94 » 27.01.2009, 08:31

vid yo!!!!
User avatar squidney2k1
Intern Dev
Intern Dev
 
Posts: 127
Member since: 07.01.2008, 23:12
Location: California
Likes: 0

Postby squidney2k1 » 30.01.2009, 08:19

I'd be nice to see this finally included in the GOC mod. I think James-Ryan had figured out how to do this, as well as correct a few issues in the GOC (i.e. lasers not lining up, making binoculars 1st person only, etc.), but hasn't released any updates.
User avatar smashingpunk007
Intern Dev
Intern Dev
 
Posts: 125
Member since: 01.12.2007, 04:10
Likes: 0

Postby smashingpunk007 » 17.02.2009, 10:47

Can someone please send me their already modified weapon zoom files. I just got the OTS mod today ,and I was trying to follow this tutorial but I can't find Item.h, or PlayerView.cpp. If someone already has the "fixed" files can you PM please, well if you can thanks.