Sec 02 について
流れ
- まずRiderで作業するのに集中するために、Auto CompileやLive Codingを消した。
- キャラクターの基本のセットアップ
- Created Character Class
- Created Weapon object and attached to mesh
- Applied Animation
- Setting up player enhanced input
- Private Dependency Module にEnhanced Inputを入れないといけない
- Setup GameModeBase and GameBase
- Setup PlayerController
- Casting input to enhanced input
- Setup Move function
- highlight the enemy when mouse over
- by creating interface
- Highlighting via post process material
- add post process volume and make it extens infinite
- custom depth stencil : Enabled with Stencil
- add PP_highlighing material to post process volume
- change enemy actor’s custom depth
発見
BindActionの第4引数に渡す関数ポインタの型をドキュメントで知りたい
void AAuraPlayerController::SetupInputComponent()
{
...
->BindAction(MoveAction, ETriggerEvent::Triggered, this, &AAuraPlayerController::Move);
EnhancedInputComponent}
void AAuraPlayerController::Move(const FInputActionValue& Value) {...}
BindActionの第4引数には、void (AAuraPlayerController::*)(const FInputActionValue&)
という型の関数ポインタを渡す必要がある。これはどこを読めばわかるのか?
BindActionのドキュメントによれば、上の関数の引数の形は
template<class UserClass>
& BindAction
FInputActionBinding (
const FName ActionName,
const EInputEvent KeyEvent,
* Object,
UserClass typename FInputActionHandlerWithKeySignature::TMethodPtr< UserClass > Func
)
で、この第四引数であるFEnhancedInputActionHandlerValueSignature
のドキュメントによれば、 typedef TBaseDelegate_OneParam< void, const FInputActionValue & > FEnhancedInputActionHandlerValueSignature
Rotation MatrixのGetUnitAxisの意味
const FVector2D InputAxisVector = Value.Get<FVector2D>();
const FRotator Rotation = GetControlRotation();
const FRotator YawRotation(0, Rotation.Yaw, 0);
const FVector ForwardDirection = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::X);
const FVector RightDirection = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::Y);
if (APawn* ContrlledPawn = GetPawn<APawn>())
{
->AddMovementInput(ForwardDirection, InputAxisVector.Y);
ContrlledPawn->AddMovementInput(RightDirection, InputAxisVector.X);
ContrlledPawn}
FRotationMatrix(YawRotation)
は、YawRotationを回転行列に変換している。この回転行列は、YawRotationの回転軸をZ軸にしている。ここまではいいが、行列にする意味は何か?
GetUnitAxis(EAxis::X)
は、回転行列の1列目を取得していることになる。
\[ \begin{pmatrix} \cos\theta & -\sin\theta & 0 \\ \sin\theta & \cos\theta & 0 \\ 0 & 0 & 1 \end{pmatrix} \longmapsto \begin{pmatrix} \cos\theta \\ \sin\theta \\ 0 \end{pmatrix} , \begin{pmatrix} -\sin\theta \\ \cos\theta \\ 0 \end{pmatrix} , \begin{pmatrix} 0 \\ 0 \\ 1 \end{pmatrix} \]
これについて考えれば、1,2,3列目のベクトルとは、回転後のベクトルの、向いている方向、その方向を \(x'\) 軸として作り上げる右手系 \(x', y', z'\) の基底ベクトルになっていることがわかる。
GetControlRotation()
でControl世界の回転を取得しているので、その世界の \(x, y\) 軸への方向に動きを制限して、Inputを適用している。
仮想関数周り
class Parent{
public:
virtual void VFunc() { std::cout << "Parent" << std::endl; }
void NVFunc() { std::cout << "Parent" << std::endl; }
};
class Child : public Parent{
public:
void VFunc() override { std::cout << "Child" << std::endl; }
void NVFunc() { std::cout << "Child" << std::endl; }
};
int main()
{
* p = new Child();
Parent// Parentとしてpを定義しているので、virtualじゃない関数はParentのものが呼ばれる
->VFunc(); // Child
p// virtualな関数はChildのものが呼ばれる
->NVFunc(); // Parent
p}
以上がvirtual
についての話で、sub classで書き換えられる前提の関数は次のように書く。
class Parent{
public:
virtual void VFunc() = 0;
};
Tick関連の話
.bCanEverTick = true; PrimaryActorTick
これをContructorで設定しないとTickしない。ただし、PlayerControllerはデフォルトでPlayerTickするようになっている。
Collision Channelの話
Character Collision PresetではECC_VisibilityがOffになってるんで気をつけて。