Chapitre Un – Création de la caméra isométrique

Création d’une perspective

Maintenant que notre controlleur de personnage est ajouté, nous allons attaquer la création d’une caméra personnalisé. Parce que UDK ne supporte pas cette caméra par défaut, ce sera un bon exercice sur comment bien modifier le fonctionnement de la caméra.

 

Créez un nouveau script appellé IsometricCamera. Changer “extends Object” pour “extends Camera”. Vous devrez me faire confiance et inscrire le long bloc de code suivant que je vous suggère de lire attentivement puisqu’il est en anglais. Il va un peu comme suit : UpdateViewTarget est appellé à chaque frame par UDK. Il permet donc de gérer la vue générale et la position de la caméra. Après avoir initialisé les paramètre de FOV et d’aspect (équivalent à la lentille d’une caméra photo), nous inspectons le mode dans lequel la caméra se trouve. Il existe 3 mode de base soit : fixé (fixed), troisième personne (third person), caméra libre (free cam et free_cam_default). Nous allons en ajouter un autre pour ne pas perdre les fonctionnalités présente, soit isométrique (Isometric). Dans ce mode nous fixons les angles pitch et Yaw et nous ajoutons ensuite une légerte distance entre le joueur principal et la caméra, laissant le joueur en plein centre de l’écran.

 

 

class IsometricCamera extends Camera;
/*****************************************************************
*
*  TUTORIAL FUNCTION
*
*  This function was extended from camera. Your pawn will request
*  a camera type when its created with function GetDefaultCameraMode,
*  Force it to 'Isometric'. This change is small and doesnt hinder the
*  in-game use of other buil-in camera types.
*
*  This is a skeletal function provided to be simple and to the point
*  to get an iso camera, add more or extend from another parent class
*  if you miss anything from GameCamera.
*
*
*****************************************************************/
function UpdateViewTarget(out TViewTarget OutVT, float DeltaTime)
{
local vector		Loc, Pos, HitLocation, HitNormal;
local rotator		Rot;
local Actor			HitActor;
local CameraActor	CamActor;
local bool			bDoNotApplyModifiers;
local TPOV			OrigPOV;

// store previous POV, in case we need it later
OrigPOV = OutVT.POV;

// Default FOV on viewtarget
OutVT.POV.FOV = DefaultFOV;

// Viewing through a camera actor.
CamActor = CameraActor(OutVT.Target);
if( CamActor != None )
{
CamActor.GetCameraView(DeltaTime, OutVT.POV);

// Grab aspect ratio from the CameraActor.
bConstrainAspectRatio	= bConstrainAspectRatio || CamActor.bConstrainAspectRatio;
OutVT.AspectRatio		= CamActor.AspectRatio;

// See if the CameraActor wants to override the PostProcess settings used.
CamOverridePostProcessAlpha = CamActor.CamOverridePostProcessAlpha;
CamPostProcessSettings = CamActor.CamOverridePostProcess;
}
else
{
// Give Pawn Viewtarget a chance to dictate the camera position.
// If Pawn doesn't override the camera view, then we proceed with our own defaults
if( Pawn(OutVT.Target) == None ||
!Pawn(OutVT.Target).CalcCamera(DeltaTime, OutVT.POV.Location, OutVT.POV.Rotation, OutVT.POV.FOV) )
{
// don't apply modifiers when using these debug camera modes.
bDoNotApplyModifiers = TRUE;

switch( CameraStyle )
{
case 'Fixed'		:	// do not update, keep previous camera position by restoring
// saved POV, in case CalcCamera changes it but still returns false
OutVT.POV = OrigPOV;
break;

case 'ThirdPerson'	: // Simple third person view implementation
case 'FreeCam'		:
case 'FreeCam_Default':
Loc = OutVT.Target.Location;
Rot = OutVT.Target.Rotation;

//OutVT.Target.GetActorEyesViewPoint(Loc, Rot);
if( CameraStyle == 'FreeCam' || CameraStyle == 'FreeCam_Default' )
{
Rot = PCOwner.Rotation;
}
Loc += FreeCamOffset >> Rot;

Pos = Loc - Vector(Rot) * FreeCamDistance;
// @fixme, respect BlockingVolume.bBlockCamera=false
HitActor = Trace(HitLocation, HitNormal, Pos, Loc, FALSE, vect(12,12,12));
OutVT.POV.Location = (HitActor == None) ? Pos : HitLocation;
OutVT.POV.Rotation = Rot;
break;

case 'Isometric':
// fix Camera rotation
Rot.Pitch = (-55.0f     *DegToRad) * RadToUnrRot;
Rot.Roll =  (0          *DegToRad) * RadToUnrRot;
Rot.Yaw =   (30.0f      *DegToRad) * RadToUnrRot;

Loc.X = PCOwner.Pawn.Location.X - 64;
Loc.Y = PCOwner.Pawn.Location.Y - 64;
Loc.Z = PCOwner.Pawn.Location.Z + 156;

Pos = Loc - Vector(Rot) * FreeCamDistance;

OutVT.POV.Location = Pos;
OutVT.POV.Rotation = Rot;
break;

case 'FirstPerson'	: // Simple first person, view through viewtarget's 'eyes'
default				:	OutVT.Target.GetActorEyesViewPoint(OutVT.POV.Location, OutVT.POV.Rotation);
break;

}
}
}

if( !bDoNotApplyModifiers )
{
// Apply camera modifiers at the end (view shakes for example)
ApplyCameraModifiers(DeltaTime, OutVT.POV);
}
//`log( WorldInfo.TimeSeconds  @ GetFuncName() @ OutVT.Target @ OutVT.POV.Location @ OutVT.POV.Rotation @ OutVT.POV.FOV );
}

Ajoutez maintenant un bloc de DefaultProperties comme suit :

DefaultProperties

{

DefaultFOV=90.f

}

Ceci permettra de mettre la largeur de vue par défaut FOV. Faites des test ici, généralement 80-90 c’est normal sinon vous aurez une vue de poisson ou plus bizzare encore…

Inclure la caméra dans le jeu

Il faudra intervenir dans les propriétés par défaut du controlleur de personnage, ajouter ceci dans le bloc de defaultproperties : CameraClass=class‘IsometricCamera’.

 

Compiler la solution et appuyer sur play et vous devriez avoir une surprise !

 

Un peu d’aide

 

Comme vous pouvez voir, la caméra s’obstine à ne pas prendre notre nouvelle perspective. Pourquoi ? très simple : Notre avatar par défaut (classe Pawn) fait par défaut la requête d’une caméra FPS. Nous allons donc créer notre propre classe pawn pour pallier au problème.

 

Créer un pawn ou pantin ou avatar (votre choix quoi)

Ajoutez un fichier script et nommez le MyPawn. Changer sont extends Object pour GamePawn. Copiez les instructions suivantes qui demandera notre nouveau mode de caméra :

simulated function name GetDefaultCameraMode( PlayerController RequestedBy )

{

return ‘Isometric’;

}

Encore, pour utiliser la classe pawn nouvellement créé, il faudra intervenir dans une section defaultproperties, mais cette fois dans le jeu directement soit la classe GameInfo. votre fichier IsometricGameInfo devrait ressembler à ça :

class IsometricGameInfo extends GameInfo;

DefaultProperties

{

bDelayedStart=false

PlayerControllerClass=class‘IsometricGamePlayerController’

DefaultPawnClass=class‘MyPawn’

}

NOTEZ QUE la variable bDelayedStart est très importante. La raison est que dans une session de jeu Unreal Tournament, le joueur démarre en attente d’équipe et de joueur, nous spécifions donc de ne pas attendre ici.

Compilez et exécutez, vous devriez avoir la bonne caméra

 

EDIT FROM FEEDBACKS (Jan 02, 2010) : Ajouter les informations suivantes à la classe MyPawn, puisque certaines erreures ont été reportés :

defaultproperties
{
	Components.Remove(Sprite)

	Begin Object Class=DynamicLightEnvironmentComponent Name=MyLightEnvironment
		ModShadowFadeoutTime=0.25
		MinTimeBetweenFullUpdates=0.2
		AmbientGlow=(R=.01,G=.01,B=.01,A=1)
		AmbientShadowColor=(R=0.15,G=0.15,B=0.15)
		LightShadowMode=LightShadow_ModulateBetter
		ShadowFilterQuality=SFQ_High
		bSynthesizeSHLight=TRUE
	End Object
	Components.Add(MyLightEnvironment)

    Begin Object Class=SkeletalMeshComponent Name=InitialSkeletalMesh
		CastShadow=true
		bCastDynamicShadow=true
		bOwnerNoSee=false
		LightEnvironment=MyLightEnvironment;
        BlockRigidBody=true;
        CollideActors=true;
        BlockZeroExtent=true;
		PhysicsAsset=PhysicsAsset'CH_AnimCorrupt.Mesh.SK_CH_Corrupt_Male_Physics'
		AnimSets(0)=AnimSet'CH_AnimHuman.Anims.K_AnimHuman_AimOffset'
		AnimSets(1)=AnimSet'CH_AnimHuman.Anims.K_AnimHuman_BaseMale'
		AnimTreeTemplate=AnimTree'CH_AnimHuman_Tree.AT_CH_Human'
		SkeletalMesh=SkeletalMesh'CH_LIAM_Cathode.Mesh.SK_CH_LIAM_Cathode'
	End Object

	Mesh=InitialSkeletalMesh;
	Components.Add(InitialSkeletalMesh);
}

chap1_iso_visuals

 

 

C’était facile non ? nous continuerons donc prochainement avec l’ajout de support spéciale pour la souris et l’intelligence pour le mouvement du personnage.

 

 

Les sources sont disponibles pour le chapitre 1 ici en anglais seulement.

 

 

 

Chapter 2 – Getting the mouse into the fray

 

 

 

Update me when site is updated
Share and Enjoy:
  • Print
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • Slashdot
  • PDF
  • Twitter
  1. Pas encore de commentaire
  1. Pas encore de trackbacks
Vous devez être identifié pour poster un commentaire