LeeMcQueen / GameDemo

Demo
0 stars 0 forks source link

normalMap function #18

Open LeeMcQueen opened 3 years ago

LeeMcQueen commented 3 years ago

include

include

include

struct Vec3{

double x;
double y;
double z;

Vec3(void){
    x = 0.0;
    y = 0.0;
    z = 0.0;
}
Vec3(double x0, double y0, double z0){
    x = x0;
    y = y0;
    z = z0;
}
~Vec3(){}

Vec3 operator-(Vec3 v){
    return Vec3(x-v.x,y-v.y,z-v.z);
}

};

struct Vec2{

double x;
double y;

Vec2(void){
    x = 0.0;
    y = 0.0;
};
Vec2(double x0, double y0){
    x = x0;
    y = y0;
};
~Vec2(){}

Vec2 operator+(Vec2 v){
    return Vec2(x+v.x,y+v.y);
}
Vec2 operator-(Vec2 v){
    return Vec2(x-v.x,y-v.y);
}

};

class Node{

public:

    Vec3 position;

    Node(Vec3 pos){
        position = pos;
    }
    ~Node(void){}

};

int main(){

//basic triangle infomation
Vec3 pos1(-1.0, 1.0, 0.0);
Vec3 pos2(-1.0, -1.0, 0.0);
Vec3 pos3(1.0, -1.0, 0.0);
Vec3 pos4(1.0, 1.0, 0.0);
Vec2 uv1(0.0, 1.0);
Vec2 uv2(0.0, 0.0);
Vec2 uv3(1.0, 0.0);
Vec2 uv4(1.0, 1.0);
Vec3 nm(0.0, 0.0, 1.0);
//tangent
Vec3 tangent1, bitangent1;
Vec3 tangent2, bitangent2;

Vec3 edge1 = pos2 - pos1;
Vec3 edge2 = pos3 - pos1;
Vec2 deltaUV1 = uv2 - uv1;
Vec2 deltaUV2 = uv3 - uv1;

float f = 1.0f / (deltaUV1.x * deltaUV2.y - deltaUV2.x * deltaUV1.y);

printf("\t edge1:(%f ,%f ,%f)\n" , edge1.x, edge1.y , edge1.z);
printf("\t edge2:(%f ,%f ,%f)\n" , edge2.x, edge2.y , edge2.z);
printf("\t deltaUV1:(%f ,%f)\n" , deltaUV1.x, deltaUV1.y);
printf("\t deltaUV2:(%f ,%f)\n" , deltaUV2.x, deltaUV2.y);
printf("\t unitMatrix F:(%f)\n" , f);

};