omg ça marche
This commit is contained in:
@@ -16,5 +16,6 @@ public class OpenGLMain {
|
||||
commandExecutor.executeCommand(new NewGameCommand());
|
||||
|
||||
ddd.run();
|
||||
commandExecutor.close();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ public class Camera {
|
||||
private float pitch = 0.0f;
|
||||
|
||||
public Camera() {
|
||||
this.pos = new Vector3f(2, 2.0f, 0);
|
||||
this.pos = new Vector3f(1.5f, 1.5f, 0);
|
||||
setRotation(0.0f, -3.14150f / 2.0f);
|
||||
}
|
||||
|
||||
|
||||
@@ -6,15 +6,7 @@ import chess.model.Coordinate;
|
||||
|
||||
class DDDPlacement {
|
||||
static public Vector2f coordinates_to_vector(Coordinate coo) {
|
||||
// float newX = switch (x) {
|
||||
// case 0 -> -1 + 0.125f;
|
||||
// case 1 -> -1 + 0.375f;
|
||||
// case 2 -> -1 + 0.625f;
|
||||
// case 3 -> -1 + 0.875f;
|
||||
|
||||
// default -> 0;
|
||||
// };
|
||||
return new Vector2f(-1.0f + 0.125f + coo.getX() * 0.250f, -1.0f + 0.125f + coo.getY() * 0.250f);
|
||||
return new Vector2f(1.0f - 0.125f - coo.getX() * 0.250f, 1.0f - 0.125f - coo.getY() * 0.250f);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -124,10 +124,13 @@ public class ModelLoader {
|
||||
|
||||
AIScene scene = Assimp.aiImportFileFromMemory(
|
||||
data,
|
||||
Assimp.aiProcess_Triangulate | Assimp.aiProcess_PreTransformVertices |
|
||||
Assimp.aiProcess_ValidateDataStructure,
|
||||
Assimp.aiProcess_Triangulate | Assimp.aiProcess_PreTransformVertices | Assimp.aiProcess_GlobalScale
|
||||
| Assimp.aiProcess_ValidateDataStructure,
|
||||
"");
|
||||
|
||||
if (scene == null)
|
||||
System.err.println(Assimp.aiGetErrorString());
|
||||
|
||||
List<VertexArray> vertecies = new ArrayList<>();
|
||||
|
||||
processNode(scene.mRootNode(), scene, vertecies);
|
||||
|
||||
@@ -22,7 +22,8 @@ public class PieceModel implements PieceVisitor<String> {
|
||||
public DDDModel getModel(Piece piece) throws IOException {
|
||||
if (piece == null)
|
||||
return null;
|
||||
String path = basePath + colorToString(piece.getColor()) + "-" + visit(piece) + ".glb";
|
||||
|
||||
String path = basePath + colorToString(piece.getColor()) + "-" + visit(piece) + ".fbx";
|
||||
return getModel(path);
|
||||
}
|
||||
|
||||
@@ -47,7 +48,7 @@ public class PieceModel implements PieceVisitor<String> {
|
||||
|
||||
@Override
|
||||
public String visitPiece(King king) {
|
||||
return "knight";
|
||||
return "king";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -80,7 +80,7 @@ public class Renderer {
|
||||
for (int i = 0; i < BOARD_WIDTH; i++) {
|
||||
for (int j = 0; j < BOARD_HEIGHT; j++) {
|
||||
Vector3f color;
|
||||
if ((i + j) % 2 != 0) {
|
||||
if ((i + j) % 2 == 0) {
|
||||
color = new Vector3f(1.0f, 1.0f, 1.0f);
|
||||
} else {
|
||||
color = new Vector3f(0.0f, 0.0f, 0.0f);
|
||||
|
||||
@@ -11,13 +11,19 @@ public class BoardShader extends ShaderProgram {
|
||||
layout(location = 1) in vec3 color;
|
||||
|
||||
uniform mat4 camMatrix;
|
||||
uniform vec3 lightPosition;
|
||||
|
||||
flat out vec3 pass_color;
|
||||
out vec3 toLightVector;
|
||||
|
||||
void main(void){
|
||||
gl_Position = camMatrix * vec4(position, 1.0);
|
||||
|
||||
toLightVector = lightPosition - position;
|
||||
|
||||
pass_color = color;
|
||||
}
|
||||
|
||||
""";
|
||||
|
||||
private static String fragmentShader = """
|
||||
@@ -25,11 +31,34 @@ public class BoardShader extends ShaderProgram {
|
||||
|
||||
flat in vec3 pass_color;
|
||||
|
||||
in vec3 toLightVector;
|
||||
|
||||
out vec4 out_color;
|
||||
|
||||
void main(void){
|
||||
out_color = vec4(pass_color, 1.0);
|
||||
const float shineDamper = 10.0;
|
||||
const float reflectivity = 1.0;
|
||||
|
||||
float lightDistance = length(toLightVector);
|
||||
|
||||
const vec3 attenuation = vec3(0.3, 0.03, 0);
|
||||
float attenuationFactor = attenuation.x + attenuation.y * lightDistance + attenuation.z * lightDistance * lightDistance;
|
||||
|
||||
vec3 unitNormal = vec3(0, 1, 0);
|
||||
vec3 unitLightVector = normalize(toLightVector);
|
||||
|
||||
vec3 lightDirection = -unitLightVector;
|
||||
vec3 reflectedLightDirection = reflect(lightDirection, unitNormal);
|
||||
|
||||
float diffuse = max(0.2, dot(unitNormal, unitLightVector));
|
||||
|
||||
float brightness = diffuse / attenuationFactor;
|
||||
|
||||
out_color = brightness * vec4(pass_color, 1.0);
|
||||
out_color.w = 1.0;
|
||||
|
||||
}
|
||||
|
||||
""";
|
||||
|
||||
private int location_CamMatrix = 0;
|
||||
|
||||
@@ -13,11 +13,20 @@ public class PieceShader extends ShaderProgram {
|
||||
|
||||
uniform mat4 camMatrix;
|
||||
uniform mat4 modelTransform;
|
||||
uniform vec3 lightPosition = vec3(0, 1, 0);
|
||||
|
||||
out vec3 toLightVector;
|
||||
out vec3 surfaceNormal;
|
||||
|
||||
flat out vec3 pass_color;
|
||||
|
||||
void main(void){
|
||||
gl_Position = camMatrix * modelTransform * vec4(position, 1.0);
|
||||
vec4 worldPos = modelTransform * vec4(position, 1.0);
|
||||
|
||||
toLightVector = lightPosition - worldPos.xyz;
|
||||
surfaceNormal = (modelTransform * vec4(normal, 0.0)).xyz;
|
||||
|
||||
gl_Position = camMatrix * worldPos;
|
||||
pass_color = position;
|
||||
}
|
||||
""";
|
||||
@@ -25,12 +34,24 @@ public class PieceShader extends ShaderProgram {
|
||||
private static String fragmentShader = """
|
||||
#version 330
|
||||
|
||||
in vec3 toLightVector;
|
||||
in vec3 surfaceNormal;
|
||||
|
||||
flat in vec3 pass_color;
|
||||
|
||||
out vec4 out_color;
|
||||
|
||||
void main(void){
|
||||
out_color = vec4(pass_color, 1.0);
|
||||
vec3 unitNormal = normalize(surfaceNormal);
|
||||
vec3 unitLightVector = normalize(toLightVector);
|
||||
|
||||
float diffuse = max(0.5, dot(unitNormal, unitLightVector));
|
||||
|
||||
float brightness = diffuse;
|
||||
|
||||
out_color = vec4(pass_color, 1.0) * brightness;
|
||||
out_color.w = 1.0;
|
||||
|
||||
}
|
||||
""";
|
||||
|
||||
|
||||
BIN
app/src/main/resources/3d/black-bishop.fbx
LFS
Normal file
BIN
app/src/main/resources/3d/black-bishop.fbx
LFS
Normal file
Binary file not shown.
BIN
app/src/main/resources/3d/black-king.fbx
LFS
Normal file
BIN
app/src/main/resources/3d/black-king.fbx
LFS
Normal file
Binary file not shown.
BIN
app/src/main/resources/3d/black-knight.fbx
LFS
Normal file
BIN
app/src/main/resources/3d/black-knight.fbx
LFS
Normal file
Binary file not shown.
BIN
app/src/main/resources/3d/black-pawn.fbx
LFS
Normal file
BIN
app/src/main/resources/3d/black-pawn.fbx
LFS
Normal file
Binary file not shown.
BIN
app/src/main/resources/3d/black-queen.fbx
LFS
Normal file
BIN
app/src/main/resources/3d/black-queen.fbx
LFS
Normal file
Binary file not shown.
BIN
app/src/main/resources/3d/black-rook.fbx
LFS
Normal file
BIN
app/src/main/resources/3d/black-rook.fbx
LFS
Normal file
Binary file not shown.
BIN
app/src/main/resources/3d/white-bishop.fbx
LFS
Normal file
BIN
app/src/main/resources/3d/white-bishop.fbx
LFS
Normal file
Binary file not shown.
BIN
app/src/main/resources/3d/white-king.fbx
LFS
Normal file
BIN
app/src/main/resources/3d/white-king.fbx
LFS
Normal file
Binary file not shown.
BIN
app/src/main/resources/3d/white-knight.fbx
LFS
Normal file
BIN
app/src/main/resources/3d/white-knight.fbx
LFS
Normal file
Binary file not shown.
BIN
app/src/main/resources/3d/white-pawn.fbx
LFS
Normal file
BIN
app/src/main/resources/3d/white-pawn.fbx
LFS
Normal file
Binary file not shown.
BIN
app/src/main/resources/3d/white-queen.fbx
LFS
Normal file
BIN
app/src/main/resources/3d/white-queen.fbx
LFS
Normal file
Binary file not shown.
BIN
app/src/main/resources/3d/white-rook.fbx
LFS
Normal file
BIN
app/src/main/resources/3d/white-rook.fbx
LFS
Normal file
Binary file not shown.
Reference in New Issue
Block a user