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 마무리

1. Day36

  • 알고리즘 코드카타
  • C++과 Unreal Engine으로 3D 게임 개발
  • CS50x 1주차 마무리

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

  • [7번 과제] Pawn 클래스로 3D 캐릭터 만들기 시작

3. 알고리즘 코드카타

  • 부족한 금액 계산하기(초기 코드)
    • for 문으로 prince * i 만큼의 가격을 누적 덧셈 하여 총 가격 계산
#include <string>
#include <vector>

using namespace std;

long long solution(int price, int money, int count)
{
    long long answer = -1;
    answer = money;
    for (int i = 1; i <= count; ++i)
    {
        answer -= price * i;
    }
    if (answer >= 0)
    {
        answer = 0;
    }
    else
    {
        answer = answer * -1;
    }
    return answer;
}
  • 부족한 금액 계산하기(개선 코드)
    • answer = answer * (count * (count + 1) / 2) - money를 이용 바로 부족한 금액을 계산 그 값이 0이하라면 answer = 0 아니라면 answer 값이 바로 부족한 금액
#include <string>
#include <vector>

using namespace std;

long long solution(int price, int money, int count)
{
    long long answer = price;
    answer = answer * (count * (count + 1) / 2) - money;
    if (answer <= 0)
    {
        answer = 0;
    }

    return answer;
}
  • 문자열 다루기 기본(초기 코드)
    • size()함수로 문자열 길이 판별, for문으로 문자열 순회하며 숫자가 아닌 값이 있다면 false 반환
#include <string>
#include <vector>

using namespace std;

bool solution(string s) {

    if (s.size() != 4 && s.size() != 6)
    {
        return false;
    }

    for (auto& str : s)
    {
        if (str < '0' || str > '9')
        {
            return false;
        }
    }
    return true;
}
  • 문자열 다루기 기본(개선 코드)
    • ‘0’, ‘9’로 숫자인지 아닌지 체크하던 방식을 isdigit함수로 숫자체크
#include <string>
#include <vector>

using namespace std;

bool solution(string s) {

    if (s.size() != 4 && s.size() != 6)
    {
        return false;
    }

    for (auto& str : s)
    {
            // str < '0' || str > '9' 로 체크하던 걸 isdigit(str)로 해결
        if (isdigit(str) == false)
        {
            return false;
        }
    }
    return true;
}
  • 행렬의 덧셈(초기 코드)
    • arr1을 이중 for문으로 순회하면서 같은 행과 열의 길이를 가진 arr2를 arr1에 더한다음 answer = arr1으로 풀이
#include <string>
#include <vector>

using namespace std;

vector<vector<int>> solution(vector<vector<int>> arr1, vector<vector<int>> arr2) {
    vector<vector<int>> answer;
    for (int i = 0; i < arr1.size(); ++i)
    {
        for (int j = 0; j < arr1[i].size(); ++j)
        {
            arr1[i][j] = arr1[i][j] + arr2[i][j];
        }
    }
    answer = arr1;
    return answer;
}
  • 행렬의 덧셈(개선 코드)
    • arr1을 이중 for문으로 순회하면서 같은 행과 열의 길이를 가진 arr2를 arr1에 더한다음 arr1를 반환 불필요하게 answer에 복사하는 과정을 생략
#include <string>
#include <vector>

using namespace std;

vector<vector<int>> solution(vector<vector<int>> arr1, vector<vector<int>> arr2) {
    for (int i = 0; i < arr1.size(); ++i)
    {
        for (int j = 0; j < arr1[i].size(); ++j)
        {
            arr1[i][j] += arr2[i][j];
        }
    }
    return arr1;
}

4. 역량강화 분반 베이직 실전

  • 프로젝트 구성요소 훑어보기 + UCLASS, GameModeBase
    • 언리얼 엔진 환경 설정 및 포트폴리오 계획 수립
    • UCLASS 및 GameModeBase

5. 팀 프로젝트 대비 언리얼 Git LFS 실습

  • 각자 프로젝트 2개 생성
    • Asset 저장용 하나 거기서 Imigration으로 필요한 부분만 옮겨서 담아둘 프로젝트 하나
  • 추출된 Asset 을 압축해서 Git 마스터한테 전달(클라우드 활용)
  • Git마스터가 실제 작업을 진행할 프로젝트 생성(Git 마스터는 프로젝트 3개 생성)
    • 이 프로젝트에 모든 Asset 취합
    • Github에 Push
    • 프로젝트 통으로 압축 및 공유
  • 각자 받은 압축 파일 해제 후 Add existing repogitory 한 다음 브랜치를 파서 작업
  • 이후 Asset이 추가될 필요가 있다면 모든 브랜치를 pr한다음 정리하고 같은 브랜치로 맞춘 다음 Git 마스터가 Asset을 받아 프로젝트에 추가하고 Push
    • 단 이번에는 모두가 같은 경로에 Asset을 추가하고 Asset과 함께 Git 마스터가 Github에 푸시한 이후의 .git파일도 공유받아 덮어 씌울 것

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

1. Day35

  • 알고리즘 코드카타
  • C++과 Unreal Engine으로 3D 게임 개발(6번 과제)
  • CS50x 1주차 마무리

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

  • [6번 과제] 회전 발판과 움직이는 장애물
    • 필수 기능 + 도전 기능 일부분 구현
void AMovingPlatform::BeginPlay()
{
    Super::BeginPlay();

    // 초기 위치 세팅(블루프린트에서 설정) == 초기위치에서 Dist값 계산 후 MaxRange를 넘어가면 방향 전환
    SetActorLocation(StartLocation);
    // 초기 Acotr 각도 세팅
    SetActorRotation(StartRotation);
    // 초기 이동 방향 세팅 == 엑터의 정면
    MoveDirection = GetActorForwardVector();
    // FTimerHandle을 활용한 코드
    GetWorld()->GetTimerManager().SetTimer(
        TimerHandle,
        this,
        &AMovingPlatform::MovePlatform,
        0.016f,
        true
    );
}

void AMovingPlatform::MovePlatform()
{
    // 현재 위치 & 움직일 위치 선정
    FVector CurrentLocation = GetActorLocation();
    FVector NewLocation = CurrentLocation + (MoveDirection * MoveSpeed * 0.016f);
    // Platform 이동
    SetActorLocation(NewLocation);
    // 이동 거리 계산
    float Dist = FVector::Dist(StartLocation, NewLocation);
    // Actor의 정면 방향으로 진행 중 최대 거리를 넘기면 방향 반대로 전환
    if (bMovingForward && Dist >= MaxRange)
    {
        MoveDirection = -MoveDirection;
        bMovingForward = false;
    }
    // 방향을 반대로 전환해 초기 위치에 근접하게 된다면 다시 방향 전환
    else if (bMovingForward == false && Dist <= 1.0f )
    {
        MoveDirection = -MoveDirection;
        bMovingForward = true;
    }

    if (IsValid(GEngine))
    {
        FString DebugMsg = FString::Printf(TEXT("Distance: %f / Dir: %s"), Dist, *MoveDirection.ToString());
        GEngine->AddOnScreenDebugMessage(-1, 0.0f, FColor::Red, DebugMsg);
    }
}
void ARotatingPlatform::BeginPlay()
{
    Super::BeginPlay();
    // 초기 위치 세팅(블루프린트에서 설정)
    SetActorLocation(StartLocation);
    // 초기 Acotr 각도 세팅
    SetActorRotation(StartRotation);

    // FTimerHandle을 활용한 코드
    GetWorld()->GetTimerManager().SetTimer(
        TimerHandle,
        this,
        &ARotatingPlatform::RotatePlatform,
        0.016f,
        true
    );
}

void ARotatingPlatform::RotatePlatform()
{
    // Platform 이동
    AddActorLocalRotation(RotateSpeed * 0.016f);
}

3. 알고리즘 코드카타

  • 수박수박수박수박수박수?
  • 내적(초기 코드)
    • 배열의 길이 만큼 반복문에서 a의 값과 b 의값을 곱한 값을 answer에 더해줌
#include <string>
#include <vector>

using namespace std;

int solution(vector<int> a, vector<int> b) {
    int answer = 0;
    for (int i = 0; i < a.size(); ++i)
    {
        answer += a[i] * b[i];
    }
    return answer;
}
  • 내적(개선 코드)
    • numeric 헤더를 가져와 내적을 구하는 함수인 inner_product를 사용
#include <string>
#include <vector>
#include <numeric>

using namespace std;

int solution(vector<int> a, vector<int> b) {
    int answer = inner_product(a.begin(), a.end(), b.begin(),0);

    return answer;
}

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

+ Recent posts