1. Day37

  • 알고리즘 코드카타
  • C++과 Unreal Engine으로 3D 게임 개발
  • TA 클래스

2. CH3 - C++과 Unreal Engine으로 3D 게임 개발(Day37)

  • [7번 과제] Pawn 클래스로 3D 캐릭터 만들기
    • 컴포넌트 및 Mapping Context 설정
// AMyCharacter.h

class UCapsuleComponent;
class USkeletalMeshComponent;
class USpringArmComponent;
class UCameraComponent;
class UInputMappingContext;

protected:
    // 캡슐 컴포넌트
    UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Component")
    TObjectPtr<UCapsuleComponent> CapsuleComp;
    // 메시 컴포넌트
    UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Component")
    TObjectPtr<USkeletalMeshComponent> MeshComp;
    // 스프링 암 컴포넌트
    UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Component")
    TObjectPtr<USpringArmComponent> SpringArmComp;
    // 카메라 컴포넌트
    UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Component")
    TObjectPtr<UCameraComponent> CameraComp;
    // InputMappingContext
    UPROPERTY(EditDefaultsOnly, Category = "Input")
    TObjectPtr<UInputMappingContext> DefaultMappingContext;

// AMyCharacter.cpp
    AMyCharacter::AMyCharacter()
{
    // Set this pawn to call Tick() every frame.
    PrimaryActorTick.bCanEverTick = true;

    // 캡슐(루트 컴포넌트)
    CapsuleComp = CreateDefaultSubobject<UCapsuleComponent>(TEXT("CapsuleComp"));
    RootComponent = CapsuleComp;
    CapsuleComp->SetSimulatePhysics(false);
    // 메시
    MeshComp = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("MeshComp"));
    MeshComp->SetupAttachment(RootComponent);
    MeshComp->SetSimulatePhysics(false);
    // 스프링 암
    SpringArmComp = CreateDefaultSubobject<USpringArmComponent>(TEXT("SpringArmComp"));
    SpringArmComp->SetupAttachment(RootComponent);
    // 카메라
    CameraComp = CreateDefaultSubobject<UCameraComponent>(TEXT("CameraComp"));
    CameraComp->SetupAttachment(SpringArmComp);
}

void AMyCharacter::BeginPlay()
{
    Super::BeginPlay();

    // Physics false 
    if (CapsuleComp->IsSimulatingPhysics())
    {
        CapsuleComp->SetSimulatePhysics(false);
    }

    if (MeshComp->IsSimulatingPhysics())
    {
        MeshComp->SetSimulatePhysics(false);
    }

    if (APlayerController* PC = Cast<APlayerController>(Controller))
    {
        if (UEnhancedInputLocalPlayerSubsystem* Subsystem = ULocalPlayer::GetSubsystem<UEnhancedInputLocalPlayerSubsystem>(PC->GetLocalPlayer()))
        {
            Subsystem->AddMappingContext(DefaultMappingContext, 0);
        }
    }
}

3. 알고리즘 코드카타

  • 직사각형 별찍기(초기 코드)
    • 2중 for문 이용
#include <iostream>

using namespace std;

int main(void) {
    int a;
    int b;
    cin >> a >> b;
    for (int i = 0; i < b; ++i)
    {
        for (int j = 0; j < a; ++j)
        {
            cout << "*";
        }
        cout << '\n';
    }
    return 0;
}
  • 직사각형 별찍기(개선 코드)
    • append(n, ‘*’) 를이용 n개 만큼 *을 입력한 문자열을 m번 출력
#include <iostream>

using namespace std;

int main(void) {
    int a;
    int b;
    cin >> a >> b;
    for (int i = 0; i < b; ++i)
    {
        for (int j = 0; j < a; ++j)
        {
            cout << "*";
        }
        cout << '\n';
    }
    return 0;
}
  • 최대공약수와 최소공배수(초기 코드)
    • 유클리드 호제법 while문으로 사용
#include <string>
#include <vector>

using namespace std;

vector<int> solution(int n, int m) {
    vector<int> answer;
    int lcm = n * m; 
    int gcd;

    while (m != 0)
    {
        int temp = m;
        m = n % m;
        n = temp;
    }

    gcd = n;
    lcm = lcm / gcd;

    answer.push_back(gcd);
    answer.push_back(lcm);

    return answer;
}
  • 최대공약수와 최소공배수(개선 코드)
    • numeric의 함수 사용 성능은 같으나 코드가 짧아짐
#include <vector>
#include <numeric>

using namespace std;

vector<int> solution(int n, int m) {
    return {gcd(n, m), lcm(n,m)};
}

4. TA 클래스

  • 수학 기초
    • 벡터, 행렬, 좌표계, 삼각함수, 사원수, 보간, 물리기초(운동학, 힘과 운동), 포물선 운동

5. 내일 계획 : CH3 강의 학습, 알고리즘 문제 집중 CS50x 2주차 시작, 과제6 & 과제7 마무리

+ Recent posts