1. Day42

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

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

  • Chapter 3 C++과 Unreal Engine으로 3D 게임 개발(3-1)
    • 인터페이스 기반 아이템 클래스 설계하기
// 1단계: 인터페이스 (순수 가상함수로 구현)
class IItemInterface
{
    virtual void ActivateItem() = 0;
    virtual FName GetItemType() const = 0;
};

// 2단계: 부모 클래스 (인터페이스 구현)
class ABaseItem : public AActor, public IItemInterface
{
    virtual void ActivateItem() override {}  // 빈 함수
    virtual FName GetItemType() const override { return ItemType; }
};

// 3단계: 실제 아이템 (필요한 것만 오버라이드)
class AHealingItem : public ABaseItem
{
    virtual void ActivateItem() override
    {
        // 힐링 로직
        DestroyItem();
    }
    // GetItemType()은 오버라이드 안 함 → 부모꺼 사용
};

3. 알고리즘 코드카타

  • 숫자 문자열과 영단어(초기 코드) - 이게 더 빠름
    • string list[10]에 zero부터 nine까지 배열을 준비
    • range - based for문으로 s 를 순환 (str로 받아서)
    • string temp_s 빈 문자열에 s가 알파벳일 경우 하나씩 +=
    • temp_s == list를 순환해서 참이라면 string num에 인덱스값 i를 to_string()을 이용해 추가
    • str이 정수라면 isdigit(str) 바로 num += str;
    • answer = stoi(num)으로 한번에 정수입력
#include <string>
#include <vector>
#include <cctype>

using namespace std;

int solution(string s) {
    int answer = 0;
    vector<string> numbers = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};
    string num = "";
    string temp_s = "";

    for (auto& str : s)
    {

        if (isalpha(str))
        {
            temp_s += str;
            for (int i = 0; i <= 9; i++)
            {
                if (temp_s == list[i])
                {
                    num += to_string(i);
                    temp_s = "";
                }
            }
        }
        else if (isdigit(str))
        {
            num += str;
        }


    }
    answer = stoi(num);
    return answer;
}
  • 숫자 문자열과 영단어(새로운 라이브러리 코드)
    • 다른 사람 풀이를 보던중 regex_replace를 확인 라이브러리 활용
    • 찾아 봤을때 regex_replace(s, regex(”zero”), “0”); 는 s 문자열을 순환해서 문자열에 zero라는 단어가 있다면 “0”으로 대체 하라는 뜻
    • 하지만 느린 편이라 시간제한이 있는 문제에서는 활용하기 어려움
#include <string>
#include <vector>
#include <regex>

using namespace std;

int solution(string s) {
    int answer;
    vector<string> numbers = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};

    for (int i = 0; i < numbers.size(); i++)
    {
        s = regex_replace(s, regex(numbers[i]), to_string(i));
    }
    answer = stoi(s);
    return answer;
}

4. 스탠다드 클래스

  • 코딩 테스트 준비
  • 평가 문제 풀이

5. TA 클래스

  • 색공간
  • 텍스처 활용 기초
  • 머티리얼 에디터 주요 설정
  • 파라미터 활용
  • 자주 쓰는 노드

6. 내일 계획 : CH3 강의 학습, 알고리즘 문제 집중 CS50x 2주차 진행, 베이직 실전 클래스 과제 제출

1. Day40

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

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

  • 6번, 7번 과제 해설 코드 복습

3. 알고리즘 코드카타

  • 최소직사각형(초기 코드)
    • sort를 이용 백터들의 원소를 [큰값, 작은값] 으로 전부 정렬한다음 큰값 중의 최대값과 작은값 중의 최대값을 곱한값을 반환
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int solution(vector<vector<int>> sizes) {
    int maxW = 0;
    int maxH = 0;
    for (auto& v : sizes)
    {
        sort(v.begin(), v.end(), greater<>());
        maxW = max(maxW, v[0]);
        maxH = max(maxH, v[1]);
    }

    return maxW * maxH;
}
  • 최소직사각형(개선코드)
    • sort 대신 max(maxW, max()) 로 배열안의 큰수들중 큰수를 가져오고 max(maxH, min())으로 배열안의 짧은 수중 큰 수를 가져와서 곱함
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int solution(vector<vector<int>> sizes) {
    int maxW = 0;
    int maxH = 0;
    for (auto& v : sizes)
    {
        maxW = max(maxW, max(v[0], v[1]));
        maxH = max(maxH, min(v[0],v[1]));
    }

    return maxW * maxH;
}

4. 스탠다드 클래스

  • 컴퓨터 구조를 알아야 하는 이유
  • 데이터의 표현 - 비트와 인코딩
  • 소스코드와 명령어

5. TA 클래스

  • 렌더링 파이프라인
  • 렌더링 파이프라인 흐름 정리
CPU (준비)
├── 메시, 텍스처, 셰이더 등 리소스 로드
├── 어떤 오브젝트를 그릴지 결정
└── GPU한테 "렌더링" 명령 (Draw Call)
        ↓
GPU (렌더링 파이프라인 실행)
├── Input Assembler (정점 데이터 조립)
├── Vertex Shader (좌표 변환) ← Local→World→View→Clip 
├── Rasterizer (삼각형 → 픽셀) ← Clipping, NDC, Screen 변환 
├── Pixel Shader (픽셀 색상 계산)
└── Output Merger (최종 출력)
        ↓
Frame Buffer → 모니터 출력

Local Space
    ↓ Model Matrix (월드 배치)
World Space  
    ↓ View Matrix (카메라 기준 정렬)
View Space
    ↓ Projection Matrix (Frustum 정의 + w에 깊이 저장)
Clip Space
    ↓ Clipping (시야 밖 잘라냄) ← GPU가 자동 처리
    ↓ w로 나누기 (원근감 적용)
NDC (-1 ~ 1)
    ↓ Viewport Transform (해상도에 맞게)
Screen Space (픽셀 좌표)
  • 최종 Defferd Rendering 흐름 정리
CPU (준비)
├── 메시, 텍스처, 셰이더 등 리소스 로드
├── 어떤 오브젝트를 그릴지 결정
└── GPU한테 "렌더링" 명령 (Draw Call)
        ↓
========================================
   Deferred 렌더링 시작
========================================
        ↓
GPU 파이프라인(렌더링 파이프라인) 1회차: Geometry Pass
├── Input Assembler (정점 데이터 조립)
├── Vertex Shader (좌표 변환) ← Local→World(Model)→View(View)→Clip(Projection)
├── Rasterizer (삼각형 → 픽셀) ← Clipping, NDC, Screen 변환
├── Pixel Shader (표면 속성 계산)
└── Output → G-Buffer에 저장 (화면 출력 X)
        ↓
G-Buffer (여러 텍스처)
├── Diffuse (기본 색)
├── Normal (법선)
├── Metallic / Roughness
├── Specular
└── Depth (깊이)
        ↓
GPU 파이프라인(렌더링 파이프라인) 2회차: Lighting Pass
├── Input Assembler (화면 전체 quad)
├── Vertex Shader (단순 좌표 전달)
├── Rasterizer (픽셀화)
├── Pixel Shader (G-Buffer 읽고 조명 계산)
└── Output → 중간 렌더 타겟에 저장
        ↓
GPU 파이프라인(렌더링 파이프라인) 3회차: Post Process
├── Input Assembler (화면 전체 quad)
├── Vertex Shader (단순 좌표 전달)
├── Rasterizer (픽셀화)
├── Pixel Shader (블룸, 색보정, SSAO 등)
└── Output Merger (최종 출력)
        ↓
Frame Buffer → 모니터 출력

6. 다음주 : CH3 강의 학습, 알고리즘 문제 집중 CS50x 2주차 진행, 베이직 실전 클래스 과제 진행

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