Skip to content

Commit

Permalink
Merge from master
Browse files Browse the repository at this point in the history
  • Loading branch information
tigertang committed Jul 21, 2018
2 parents 479ee83 + d201629 commit f71773d
Show file tree
Hide file tree
Showing 23 changed files with 412 additions and 92 deletions.
22 changes: 18 additions & 4 deletions include/happy_bird/controller_utility/character.h
Original file line number Diff line number Diff line change
@@ -1,18 +1,30 @@
#pragma once

#include <memory>

#include "bullet_common.h"
#include "object.h"
#include "color.h"
#include "timer.h"

class World;

class Character {
protected:
static float static_pace_;
float max_speed_;
Object* object_;
World* world_;
Object* object_;
// Config
float max_speed_ = 15;
float laser_attack_freq_ = 1;
float laser_attack_dist_ = 10;
Color laser_attack_color_ = color::Blue();
float box_attack_freq_ = 3;
float box_attack_dist_ = 5;
float box_attack_range_ = 5; // along depth axis
Color box_attack_color_ = color::Red();
public:
Character(World*, Object*, float speed = 15);
Character(World*, Object*);
~Character();
void Bind(Object* object);
Object* GetDelegate(void);
Expand All @@ -23,4 +35,6 @@ class Character {
void ResetRotate(void);
void LaserAttack(void);
void BoxAttack(void);
};
void Gain(float);
void Lose(float);
};
6 changes: 3 additions & 3 deletions include/happy_bird/particle.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ enum ParticleFlag{
kRandomColorParticle = 0x60, // 00 for mono
// origin var
kJitterParticle = 0x80,
// inner force
kInnerParticle = 0x100
// Special effect
kMockFlame = 0x100
} ;
struct ParticleConfig{
// explicit assigned
Expand All @@ -88,7 +88,7 @@ struct ParticleConfig{
bool gradual; // true for gradual change
// external option
bool jitter;
bool inner_force;
bool mock_flame;

ParticleConfig(glm::vec3 v, Color color, int flags = 0);
};
Expand Down
2 changes: 2 additions & 0 deletions include/happy_bird/stage.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ class Stage{
friend Stage;
std::shared_ptr<Object> data_ref_;
public:
StageWrapper(std::shared_ptr<Object> shared): data_ref_(shared){ }
StageWrapper(Object* naked): data_ref_(naked){ }
~StageWrapper(){ }
std::weak_ptr<Object> get(void){
return static_cast<std::weak_ptr<Object> >(data_ref_);
}
Expand Down
6 changes: 6 additions & 0 deletions include/happy_bird/temp_collection.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include <iostream>
#include <list>
#include <memory>

Expand All @@ -16,6 +17,10 @@ class TempCollection{
TempWrapper(Object* naked, float duration):data_ref_(naked), duration_(duration){
timer_ = Timer::New();
}
TempWrapper(std::shared_ptr<Object> shared, float duration):data_ref_(shared), duration_(duration){
timer_ = Timer::New();
}
~TempWrapper(){ }
std::weak_ptr<Object> get(void){
return static_cast<std::weak_ptr<Object> >(data_ref_);
}
Expand All @@ -33,6 +38,7 @@ class TempCollection{
}
void Update(void);
void PushBack(Object* object, float duration); // second
void PushBack(std::shared_ptr<Object> object, float duration);
private:
World* world_;
ObjectContainer objects_;
Expand Down
1 change: 1 addition & 0 deletions include/happy_bird/world.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class World{
TempCollection temp_;
public:
// shared
static bool exit;
static int height, width;
static Camera* camera;
static glm::vec3 global_ambient;
Expand Down
Binary file modified resources/hero.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/hero_0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/vampire.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions shader/blood_decr.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#version 330 core

uniform vec3 uColor;

in vec3 vColor;
out vec4 FragColor;

void main(){
// Halo shading //
vec2 radiant = gl_PointCoord - vec2(0.5, 0.5);
float radiusSquare = dot(radiant, radiant);
if(abs(radiant.y) < 0.1 && abs(radiant.x) < 0.2){
FragColor = vec4(vColor, 1.0);
}
else if(radiusSquare < 0.15){ // from 0.0625 to 0.25
FragColor = vec4(vColor, 0.15 - radiusSquare);
}
else{
discard;
}
// FragColor = vec4(vColor, 1.0);
}
7 changes: 4 additions & 3 deletions shader/blood_incr.frag
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,21 @@

uniform vec3 uColor;

in vec3 vColor;
out vec4 FragColor;

void main(){
// Halo shading //
vec2 radiant = gl_PointCoord - vec2(0.5, 0.5);
float radiusSquare = dot(radiant, radiant);
if(abs(radiant.x) < 0.07 && abs(radiant.y) < 0.2 || abs(radiant.y) < 0.07 && abs(radiant.x) < 0.2){
FragColor = vec4(uColor, 1.0);
FragColor = vec4(vColor, 1.0);
}
else if(radiusSquare < 0.25){ // from 0.0625 to 0.25
FragColor = vec4(uColor, 0.25 - radiusSquare);
FragColor = vec4(vColor, 0.25 - radiusSquare);
}
else{
discard;
}
// FragColor = vec4(uColor, 1.0);
// FragColor = vec4(vColor, 1.0);
}
76 changes: 40 additions & 36 deletions shader/common.frag
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,6 @@

const float zero = 0.00000001;

#define UnfoldParallelSingle(n) if(i == n){ \
color += CalculateParallelLight(eye, lightCollection.parallel[n], material);\
}
#define UnfoldParallel UnfoldParallelSingle(0)\
UnfoldParallelSingle(1)\
UnfoldParallelSingle(2)\
UnfoldParallelSingle(3)\
UnfoldParallelSingle(4)
#define UnfoldPointSingle(n) if(i == n){ \
color += CalculatePointLight(eye, lightCollection.point[n], material);\
}
#define UnfoldPoint UnfoldPointSingle(0)\
UnfoldPointSingle(1)\
UnfoldPointSingle(2)\
UnfoldPointSingle(3)\
UnfoldPointSingle(4)
#define UnfoldSpotSingle(n) if(i == n){ \
color += CalculateSpotLight(eye, lightCollection.spot[n], material);\
}
#define UnfoldSpot UnfoldSpotSingle(0)\
UnfoldSpotSingle(1)\
UnfoldSpotSingle(2)\
UnfoldSpotSingle(3)\
UnfoldSpotSingle(4)


struct Attenuation {
float range;
float constant;
Expand Down Expand Up @@ -66,9 +40,9 @@ struct LightCollectionTotal {
struct LightCollection {
vec3 ambient;
LightCollectionTotal total;
ParallelLight parallel[1];
PointLight point[1];
SpotLight spot[1];
ParallelLight parallel[4];
PointLight point[4];
SpotLight spot[4];
};

struct PureColorMaterial {
Expand All @@ -90,7 +64,7 @@ in vec3 vNormal;

out vec4 fragColor;

vec3 CalculatePointlLight(Eye eye, PointLight light, PureColorMaterial material) {
vec3 CalculatePointLight(Eye eye, PointLight light, PureColorMaterial material) {
vec3 lightDirection = normalize(light.position - vPosition);
float diffuseFactor = max(dot(vNormal, lightDirection), 0.0) * light.intensity;

Expand Down Expand Up @@ -146,16 +120,46 @@ vec3 CalculateSpotLight(Eye eye, SpotLight light, PureColorMaterial material) {
vec3 CalculateFragmentColor(Eye eye, LightCollection lightCollection, PureColorMaterial material) {
vec3 color = lightCollection.ambient;
for (int i = 0; i < lightCollection.total.parallel; i++) {
// UnfoldParallel
color += CalculateParallelLight(eye, lightCollection.parallel[i], material);
if(i == 0){
color += CalculateParallelLight(eye, lightCollection.parallel[0], material);
}
if(i == 1){
color += CalculateParallelLight(eye, lightCollection.parallel[1], material);
}
if(i == 2){
color += CalculateParallelLight(eye, lightCollection.parallel[2], material);
}
if(i == 3){
color += CalculateParallelLight(eye, lightCollection.parallel[3], material);
}
}
for (int i = 0; i < lightCollection.total.point; i++) {
// UnfoldPoint
color += CalculatePointlLight(eye, lightCollection.point[i], material);
if(i == 0){
color += CalculatePointLight(eye, lightCollection.point[0], material);
}
if(i == 1){
color += CalculatePointLight(eye, lightCollection.point[1], material);
}
if(i == 2){
color += CalculatePointLight(eye, lightCollection.point[2], material);
}
if(i == 3){
color += CalculatePointLight(eye, lightCollection.point[3], material);
}
}
for (int i = 0; i < lightCollection.total.spot; i++) {
// UnfoldSpot
color += CalculateSpotLight(eye, lightCollection.spot[i], material);
if(i == 0){
color += CalculateSpotLight(eye, lightCollection.spot[0], material);
}
if(i == 1){
color += CalculateSpotLight(eye, lightCollection.spot[1], material);
}
if(i == 2){
color += CalculateSpotLight(eye, lightCollection.spot[2], material);
}
if(i == 3){
color += CalculateSpotLight(eye, lightCollection.spot[3], material);
}
}
return color;
}
Expand Down
19 changes: 19 additions & 0 deletions shader/flame.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#version 330 core

uniform vec3 uColor;

in vec3 vColor;
out vec4 FragColor;

void main(){
// Halo shading //
vec2 radiant = gl_PointCoord - vec2(0.5, 0.5);
float radiusSquare = dot(radiant, radiant);
if(abs(radiant.x) < 0.2 && abs(radiant.y) < 0.2){
FragColor = vec4(vColor, 1.0);
}
else{
discard;
}
// FragColor = vec4(vColor, 1.0);
}
47 changes: 40 additions & 7 deletions shader/hero.frag
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ struct LightCollectionTotal {
struct LightCollection {
vec3 ambient;
LightCollectionTotal total;
ParallelLight parallel[1];
PointLight point[1];
SpotLight spot[1];
ParallelLight parallel[4];
PointLight point[4];
SpotLight spot[4];
};

struct TextureMaterial {
Expand All @@ -65,7 +65,7 @@ in vec2 vTexCoord;

out vec4 fragColor;

vec3 CalculatePointlLight(Eye eye, PointLight light, TextureMaterial material) {
vec3 CalculatePointLight(Eye eye, PointLight light, TextureMaterial material) {
vec3 lightDirection = normalize(light.position - vPosition);
float diffuseFactor = max(dot(vNormal, lightDirection), 0.0) * light.intensity;

Expand Down Expand Up @@ -121,13 +121,46 @@ vec3 CalculateSpotLight(Eye eye, SpotLight light, TextureMaterial material) {
vec3 CalculateFragmentColor(Eye eye, LightCollection lightCollection, TextureMaterial material) {
vec3 color = lightCollection.ambient;
for (int i = 0; i < lightCollection.total.parallel; i++) {
color += CalculateParallelLight(eye, lightCollection.parallel[i], material);
if(i == 0){
color += CalculateParallelLight(eye, lightCollection.parallel[0], material);
}
if(i == 1){
color += CalculateParallelLight(eye, lightCollection.parallel[1], material);
}
if(i == 2){
color += CalculateParallelLight(eye, lightCollection.parallel[2], material);
}
if(i == 3){
color += CalculateParallelLight(eye, lightCollection.parallel[3], material);
}
}
for (int i = 0; i < lightCollection.total.point; i++) {
color += CalculatePointlLight(eye, lightCollection.point[i], material);
if(i == 0){
color += CalculatePointLight(eye, lightCollection.point[0], material);
}
if(i == 1){
color += CalculatePointLight(eye, lightCollection.point[1], material);
}
if(i == 2){
color += CalculatePointLight(eye, lightCollection.point[2], material);
}
if(i == 3){
color += CalculatePointLight(eye, lightCollection.point[3], material);
}
}
for (int i = 0; i < lightCollection.total.spot; i++) {
color += CalculateSpotLight(eye, lightCollection.spot[i], material);
if(i == 0){
color += CalculateSpotLight(eye, lightCollection.spot[0], material);
}
if(i == 1){
color += CalculateSpotLight(eye, lightCollection.spot[1], material);
}
if(i == 2){
color += CalculateSpotLight(eye, lightCollection.spot[2], material);
}
if(i == 3){
color += CalculateSpotLight(eye, lightCollection.spot[3], material);
}
}
return color * 5;
}
Expand Down
9 changes: 4 additions & 5 deletions shader/particle.frag
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
#version 330 core

uniform vec3 uColor;

in vec3 vColor;
out vec4 FragColor;

void main(){
// Halo shading //
vec2 radiant = gl_PointCoord - vec2(0.5, 0.5);
float radiusSquare = dot(radiant, radiant);
if(abs(radiant.x) < 0.07 && abs(radiant.y) < 0.07){
FragColor = vec4(uColor, 1.0);
FragColor = vec4(vColor, 1.0);
}
else if(radiusSquare < 0.25){ // from 0.0625 to 0.25
FragColor = vec4(uColor, 0.25 - radiusSquare);
FragColor = vec4(vColor, 0.25 - radiusSquare);
}
else{
discard;
}
// FragColor = vec4(uColor, 1.0);
// FragColor = vec4(vColor, 1.0);
}
Loading

0 comments on commit f71773d

Please sign in to comment.