IT/대학 강의 실습 및 기말 프로젝트

[OpenGL/C++] 그래픽스 기말 프로젝트

rinix_x 2021. 12. 30. 03:37
반응형

 

기획의도

하늘 고래를 나타내고 싶어서 제작하게 되었습니다.

기능 구현

1. 모델링 넣기

모델링을 넣는 과정에서 고래가 아래와 같이 계속 깨는 현상이 발생 했습니다.

읽어 오는 것의 문제라 판단하여 블렌더를 이용해 새로 모델링을 뽑아 균일 하게 만들어 모델링을 추가했습니다.

2. 텍스쳐

고래에 3D max수업에 터득한 기술을 가지고 텍스쳐를 추가해줍니다.

3. 스무딩 대신 수채화..

내부에 있는 스무딩을 했지만, 제대로 스무딩이 적용 되지 않아 다른 방법을 찾던 와중

함수를 이용하여 수채화 느낌으로 만들었습니다.

노래도 넣고, 움직임도 추가하여 완성하였습니다.

4. 1학기 결과

5. 제대로된 스무딩 (코탄젠트라플라시안 스무딩+타우빈 스무딩)

코탄젠트 라플라시안만 사용하자니 배의 주름은 다 사라진채 등의 각진 상태가 그대로이다 보니 두개를 합쳐 모델링을 부드럽게 만들었습니다.

6. 파티클 시스템

중력을 준 상태에서 일정 힘을 줘서 일정 높이 만큼 올라가면 일부는 다시 떨어지고 일부는 사방으로 퍼지는 듯한 느낌을 줘봤습니다.

아래는 해당 파티클에서 사용한 코드며, 궁금하신 분들은 보세요.. ㅎvㅎ

더보기

해당 파티클에서 사용한 코드 입니다.

#include "Ballistic.h"

void Ammunition::Darw(void)
{
	Vec3<double> pos = m_Particle.GetPos();
	glColor3f(0, 0, 0);
	glPushMatrix();
	glTranslatef(pos.x(), pos.y(), pos.z());
	glColor4f(0.0f, 0.0f, 0.75f,0.3f);
	glutSolidSphere(0.05f, 5, 4);
	glPopMatrix();


	glColor4f(0.0f, 0.0f, 0.75f, 0.3f);
	glPushMatrix();
	glTranslatef(pos.x(), 0, pos.z());
	glScalef(1.0f, 0.1f, 1.0f);
	//glutSolidSphere(0.6f, 5, 4);
	glPopMatrix();
}
Ballistic::Ballistic(int size) {
	m_CurrShotType = ShotType::LASER;
	m_Ammunitions.clear();
	// 16개의 총알을 삽입
	m_Ammunitions.resize(size);

	for (auto &p : m_Ammunitions) {
		p.m_Type = ShotType::UNUSED;
		// 준비된 상태 (=총알 미사용)
	}
}
Ballistic::Ballistic()
{
	m_CurrShotType = ShotType::LASER;
	m_Ammunitions.clear();
	// 16개의 총알을 삽입
	m_Ammunitions.resize(MAX_NUM_AMMUNITION); 
	
	for (auto &p : m_Ammunitions) {
		p.m_Type = ShotType::UNUSED;
		// 준비된 상태 (=총알 미사용)
	}
}

Ballistic::~Ballistic()
{
}

void Ballistic::Update(void)
{
	double dt = 0.01;

	for (auto &p : m_Ammunitions) {
		if (p.m_Type != ShotType::UNUSED) {
			p.m_Particle.Integrate(dt);
			if (p.m_Particle.GetPos().y() < -1.0 || p.m_Particle.GetPos().z() > 200.0) {
				p.m_Type = ShotType::UNUSED;
			}
			if (p.m_Particle.GetPos().y() > 5.0f) {
				for (int i = 0; i < 10; i++) {
					//printf("ch");
					Ballistic childBallistic;
					float theta = i * rand() % 360 / 180.0f * 3.141592;
					double px = 5.0f *cos(theta);
					double pz = 5.0f * sin(theta);
					childBallistic.m_CurrShotType = ShotType::ARTILLERY;
					childBallistic.Fire();
					childBallistic.Firedd(px, pz,7.0);
					for (auto &sp : childBallistic.m_Ammunitions) {
						if (sp.m_Type != ShotType::UNUSED) {
							sp.Darw();

						}
					}
				}
			}
				
		}
	}
}
void Ballistic::Firedd(double x, double z, double y) {
	Ballistic *shot;
	for (auto &p : m_Ammunitions) { // 16번
		if (p.m_Type == ShotType::UNUSED) {
			switch (m_CurrShotType) {
			case PISTOL:
				p.m_Particle.SetMass(2.0f);
				p.m_Particle.SetVel(0.0f, 0.0f, 35.0f);
				p.m_Particle.SetAcc(0.0f, -1.0f, 0.0f);
				p.m_Particle.SetDamping(0.99f);
				break;
			case ARTILLERY:
				p.m_Particle.SetMass(200.0f);
				p.m_Particle.SetVel(x, 5.0f, z);  //x<5 z<5
				p.m_Particle.SetAcc(0.0f, -10.0f, 0.0f);
				p.m_Particle.SetDamping(0.99f);
				break;
			case FIREBALL:
				p.m_Particle.SetMass(1.0f);
				p.m_Particle.SetVel(0.0f, 0.0f, 10.0f);
				p.m_Particle.SetAcc(0.0f, 0.6f, 0.0f); // Floats up
				p.m_Particle.SetDamping(0.9f);
				break;
			case LASER:
				p.m_Particle.SetMass(200.0f);
				p.m_Particle.SetVel(0.0f, 15.0f, 0.0f);
				p.m_Particle.SetAcc(0.0f, -25.0f, 0.0f); // No gravity
				p.m_Particle.SetDamping(0.99f);
				break;
			}
			// 총알에 대한 재질의 정의
			// Set the data common to all particle types
			// 총알의 위치를 초기화
			p.m_Particle.SetPos(-1.5, y, 0.0);
			p.m_Particle.ClearForce();
			p.m_Type = m_CurrShotType;
			break;
		}
	}
}

void Ballistic::Fire(void)
{
	Ballistic *shot;
	for (auto &p : m_Ammunitions) { // 100번
		if (p.m_Type == ShotType::UNUSED) {
		switch (m_CurrShotType) {
		case PISTOL:
			p.m_Particle.SetMass(2.0f); 
			p.m_Particle.SetVel(0.0f, 0.0f, 35.0f); 
			p.m_Particle.SetAcc(0.0f, -1.0f, 0.0f);
			p.m_Particle.SetDamping(0.99f);
			break;
		case ARTILLERY:
			p.m_Particle.SetMass(200.0f); 
			p.m_Particle.SetVel(0.0f, 5.0f, 5.0f); 
			p.m_Particle.SetAcc(0.0f, -20.0f, 0.0f);
			p.m_Particle.SetDamping(0.99f);				
			break;
		case FIREBALL:
			p.m_Particle.SetMass(1.0f);
			p.m_Particle.SetVel(0.0f, 0.0f, 10.0f);
			p.m_Particle.SetAcc(0.0f, 0.6f, 0.0f); // Floats up
			p.m_Particle.SetDamping(0.9f);				
			break;
		case LASER :
			p.m_Particle.SetMass(200.0f); 
			p.m_Particle.SetVel(0.0f, 15.0f, 0.0f); 
			p.m_Particle.SetAcc(0.0f, -20.0f, 0.0f); // No gravity
			p.m_Particle.SetDamping(0.99f);				
			break;
		}
		// 총알에 대한 재질의 정의
		// Set the data common to all particle types
		// 총알의 위치를 초기화
		p.m_Particle.SetPos(-1.5, 1.0, 0.0);
		p.m_Particle.ClearForce();
		p.m_Type = m_CurrShotType;
		break;
		//Fire();
	}		
	}
}

7. 2학기 시연영상

입자를 크게 만들어서 살짝 어색하지만, 물을 뿜는 고래를 표현해봤었습니다.

GitHub

아직 추가하지 않았습니다 추후 추가해보겠습니다.

 

 

2020학년도 1~2학기에 제작한 프로젝트 입니다.

반응형