Git Refactoring
This commit is contained in:
parent
c700911190
commit
55fcb82edd
35 changed files with 2338 additions and 2361 deletions
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
bin/*
|
||||||
|
.project
|
||||||
|
.classpath
|
|
@ -1,7 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<classpath>
|
|
||||||
<classpathentry kind="src" path="src"/>
|
|
||||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
|
||||||
<classpathentry kind="con" path="org.eclipse.jdt.USER_LIBRARY/LWJGL3"/>
|
|
||||||
<classpathentry kind="output" path="bin"/>
|
|
||||||
</classpath>
|
|
|
@ -1,17 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<projectDescription>
|
|
||||||
<name>Diffuse light</name>
|
|
||||||
<comment></comment>
|
|
||||||
<projects>
|
|
||||||
</projects>
|
|
||||||
<buildSpec>
|
|
||||||
<buildCommand>
|
|
||||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
|
||||||
<arguments>
|
|
||||||
</arguments>
|
|
||||||
</buildCommand>
|
|
||||||
</buildSpec>
|
|
||||||
<natures>
|
|
||||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
|
||||||
</natures>
|
|
||||||
</projectDescription>
|
|
2
Diffuse light/bin/.gitignore
vendored
2
Diffuse light/bin/.gitignore
vendored
|
@ -1,2 +0,0 @@
|
||||||
/fr/
|
|
||||||
/mrdev023/
|
|
|
@ -1,78 +1,78 @@
|
||||||
#version 150
|
#version 150
|
||||||
//precision highp float;
|
//precision highp float;
|
||||||
uniform mat4 transform;
|
uniform mat4 transform;
|
||||||
uniform sampler2D materialTex;
|
uniform sampler2D materialTex;
|
||||||
uniform float materialShininess;
|
uniform float materialShininess;
|
||||||
uniform vec3 materialSpecularColor;
|
uniform vec3 materialSpecularColor;
|
||||||
uniform vec3 cameraPosition;
|
uniform vec3 cameraPosition;
|
||||||
|
|
||||||
#define MAX_LIGHTS 10
|
#define MAX_LIGHTS 10
|
||||||
uniform int numLights;
|
uniform int numLights;
|
||||||
uniform struct Light {
|
uniform struct Light {
|
||||||
vec4 position;
|
vec4 position;
|
||||||
vec3 intensities; //a.k.a the color of the light
|
vec3 intensities; //a.k.a the color of the light
|
||||||
float attenuation;
|
float attenuation;
|
||||||
float ambientCoefficient;
|
float ambientCoefficient;
|
||||||
float coneAngle;
|
float coneAngle;
|
||||||
vec3 coneDirection;
|
vec3 coneDirection;
|
||||||
} allLights[MAX_LIGHTS];
|
} allLights[MAX_LIGHTS];
|
||||||
|
|
||||||
in vec2 fragTexCoord;
|
in vec2 fragTexCoord;
|
||||||
in vec3 fragNormal;
|
in vec3 fragNormal;
|
||||||
in vec3 fragVert;
|
in vec3 fragVert;
|
||||||
|
|
||||||
out vec4 finalColor;
|
out vec4 finalColor;
|
||||||
|
|
||||||
vec3 ApplyLight(Light light, vec3 surfaceColor, vec3 normal, vec3 surfacePos, vec3 surfaceToCamera) {
|
vec3 ApplyLight(Light light, vec3 surfaceColor, vec3 normal, vec3 surfacePos, vec3 surfaceToCamera) {
|
||||||
vec3 surfaceToLight;
|
vec3 surfaceToLight;
|
||||||
float attenuation = 1.0;
|
float attenuation = 1.0;
|
||||||
if(light.position.w == 0.0) {
|
if(light.position.w == 0.0) {
|
||||||
//directional light
|
//directional light
|
||||||
surfaceToLight = normalize(light.position.xyz);
|
surfaceToLight = normalize(light.position.xyz);
|
||||||
attenuation = 1.0; //no attenuation for directional lights
|
attenuation = 1.0; //no attenuation for directional lights
|
||||||
} else {
|
} else {
|
||||||
//point light
|
//point light
|
||||||
surfaceToLight = normalize(light.position.xyz - surfacePos);
|
surfaceToLight = normalize(light.position.xyz - surfacePos);
|
||||||
float distanceToLight = length(light.position.xyz - surfacePos);
|
float distanceToLight = length(light.position.xyz - surfacePos);
|
||||||
attenuation = 1.0 / (1.0 + light.attenuation * pow(distanceToLight, 2));
|
attenuation = 1.0 / (1.0 + light.attenuation * pow(distanceToLight, 2));
|
||||||
|
|
||||||
//cone restrictions (affects attenuation)
|
//cone restrictions (affects attenuation)
|
||||||
float lightToSurfaceAngle = degrees(acos(dot(-surfaceToLight, normalize(light.coneDirection))));
|
float lightToSurfaceAngle = degrees(acos(dot(-surfaceToLight, normalize(light.coneDirection))));
|
||||||
if(lightToSurfaceAngle > light.coneAngle){
|
if(lightToSurfaceAngle > light.coneAngle){
|
||||||
attenuation = 0.0;
|
attenuation = 0.0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//ambient
|
//ambient
|
||||||
vec3 ambient = light.ambientCoefficient * surfaceColor.rgb * light.intensities;
|
vec3 ambient = light.ambientCoefficient * surfaceColor.rgb * light.intensities;
|
||||||
|
|
||||||
//diffuse
|
//diffuse
|
||||||
float diffuseCoefficient = max(0.0, dot(normal, surfaceToLight));
|
float diffuseCoefficient = max(0.0, dot(normal, surfaceToLight));
|
||||||
vec3 diffuse = diffuseCoefficient * surfaceColor.rgb * light.intensities;
|
vec3 diffuse = diffuseCoefficient * surfaceColor.rgb * light.intensities;
|
||||||
|
|
||||||
//specular
|
//specular
|
||||||
float specularCoefficient = 0.0;
|
float specularCoefficient = 0.0;
|
||||||
if(diffuseCoefficient > 0.0)
|
if(diffuseCoefficient > 0.0)
|
||||||
specularCoefficient = pow(max(0.0, dot(surfaceToCamera, reflect(-surfaceToLight, normal))), materialShininess);
|
specularCoefficient = pow(max(0.0, dot(surfaceToCamera, reflect(-surfaceToLight, normal))), materialShininess);
|
||||||
vec3 specular = specularCoefficient * materialSpecularColor * light.intensities;
|
vec3 specular = specularCoefficient * materialSpecularColor * light.intensities;
|
||||||
|
|
||||||
//linear color (color before gamma correction)
|
//linear color (color before gamma correction)
|
||||||
return ambient + attenuation*(diffuse + specular);
|
return ambient + attenuation*(diffuse + specular);
|
||||||
}
|
}
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
vec3 normal = normalize(transpose(inverse(mat3(transform))) * fragNormal);
|
vec3 normal = normalize(transpose(inverse(mat3(transform))) * fragNormal);
|
||||||
vec3 surfacePos = vec3(transform * vec4(fragVert, 1));
|
vec3 surfacePos = vec3(transform * vec4(fragVert, 1));
|
||||||
vec4 surfaceColor = texture(materialTex, fragTexCoord);
|
vec4 surfaceColor = texture(materialTex, fragTexCoord);
|
||||||
vec3 surfaceToCamera = normalize(cameraPosition - surfacePos);
|
vec3 surfaceToCamera = normalize(cameraPosition - surfacePos);
|
||||||
|
|
||||||
//combine color from all the lights
|
//combine color from all the lights
|
||||||
vec3 linearColor = vec3(0);
|
vec3 linearColor = vec3(0);
|
||||||
for(int i = 0; i < numLights; ++i){
|
for(int i = 0; i < numLights; ++i){
|
||||||
linearColor += ApplyLight(allLights[i], surfaceColor.rgb, normal, surfacePos, surfaceToCamera);
|
linearColor += ApplyLight(allLights[i], surfaceColor.rgb, normal, surfacePos, surfaceToCamera);
|
||||||
}
|
}
|
||||||
|
|
||||||
//final color (after gamma correction)
|
//final color (after gamma correction)
|
||||||
vec3 gamma = vec3(1.0/2.2);
|
vec3 gamma = vec3(1.0/2.2);
|
||||||
finalColor = vec4(pow(linearColor, gamma), surfaceColor.a);
|
finalColor = vec4(pow(linearColor, gamma), surfaceColor.a);
|
||||||
}
|
}
|
|
@ -1,23 +1,23 @@
|
||||||
#version 150
|
#version 150
|
||||||
|
|
||||||
uniform mat4 projection;
|
uniform mat4 projection;
|
||||||
uniform mat4 camera;
|
uniform mat4 camera;
|
||||||
uniform mat4 transform;
|
uniform mat4 transform;
|
||||||
|
|
||||||
in vec3 vert;
|
in vec3 vert;
|
||||||
in vec2 vertTexCoord;
|
in vec2 vertTexCoord;
|
||||||
in vec3 vertNormal;
|
in vec3 vertNormal;
|
||||||
|
|
||||||
out vec3 fragVert;
|
out vec3 fragVert;
|
||||||
out vec2 fragTexCoord;
|
out vec2 fragTexCoord;
|
||||||
out vec3 fragNormal;
|
out vec3 fragNormal;
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
// Pass some variables to the fragment shader
|
// Pass some variables to the fragment shader
|
||||||
fragTexCoord = vertTexCoord;
|
fragTexCoord = vertTexCoord;
|
||||||
fragNormal = vertNormal;
|
fragNormal = vertNormal;
|
||||||
fragVert = vert;
|
fragVert = vert;
|
||||||
|
|
||||||
// Apply all matrix transformations to vert
|
// Apply all matrix transformations to vert
|
||||||
gl_Position = projection * camera * transform * vec4(vert, 1);
|
gl_Position = projection * camera * transform * vec4(vert, 1);
|
||||||
}
|
}
|
Before Width: | Height: | Size: 49 KiB After Width: | Height: | Size: 49 KiB |
|
@ -1,113 +1,113 @@
|
||||||
package fr.technicalgames;
|
package fr.technicalgames;
|
||||||
|
|
||||||
//http://www.tomdalling.com/blog/modern-opengl/08-even-more-lighting-directional-lights-spotlights-multiple-lights/
|
//http://www.tomdalling.com/blog/modern-opengl/08-even-more-lighting-directional-lights-spotlights-multiple-lights/
|
||||||
|
|
||||||
import static org.lwjgl.glfw.GLFW.*;
|
import static org.lwjgl.glfw.GLFW.*;
|
||||||
import static org.lwjgl.opengl.GL11.*;
|
import static org.lwjgl.opengl.GL11.*;
|
||||||
import static org.lwjgl.system.MemoryUtil.*;
|
import static org.lwjgl.system.MemoryUtil.*;
|
||||||
|
|
||||||
import org.lwjgl.glfw.*;
|
import org.lwjgl.glfw.*;
|
||||||
import org.lwjgl.opengl.*;
|
import org.lwjgl.opengl.*;
|
||||||
|
|
||||||
import fr.technicalgames.audio.*;
|
import fr.technicalgames.audio.*;
|
||||||
import fr.technicalgames.game.*;
|
import fr.technicalgames.game.*;
|
||||||
import fr.technicalgames.input.*;
|
import fr.technicalgames.input.*;
|
||||||
import fr.technicalgames.math.*;
|
import fr.technicalgames.math.*;
|
||||||
import fr.technicalgames.render.*;
|
import fr.technicalgames.render.*;
|
||||||
|
|
||||||
public class Main {
|
public class Main {
|
||||||
|
|
||||||
//Valeur de la fenetre
|
//Valeur de la fenetre
|
||||||
public static final int WIDTH = 800,HEIGHT = 600;
|
public static final int WIDTH = 800,HEIGHT = 600;
|
||||||
public static final String TITLE = "Test Shader OpenGL";
|
public static final String TITLE = "Test Shader OpenGL";
|
||||||
|
|
||||||
//Variable pour la gestion de la fenetre
|
//Variable pour la gestion de la fenetre
|
||||||
public static long windowID = 0;
|
public static long windowID = 0;
|
||||||
public static float mousePositionX = 0,mousePositionY = 0,dMouseX = 0,dMouseY = 0;
|
public static float mousePositionX = 0,mousePositionY = 0,dMouseX = 0,dMouseY = 0;
|
||||||
public static GLFWErrorCallback errorCallback;
|
public static GLFWErrorCallback errorCallback;
|
||||||
|
|
||||||
//variable du moteur du jeu
|
//variable du moteur du jeu
|
||||||
public static float delta = 0;
|
public static float delta = 0;
|
||||||
public static Game game;
|
public static Game game;
|
||||||
public static long previous = System.currentTimeMillis(),previousInfo = System.currentTimeMillis(),previousTicks = System.currentTimeMillis();
|
public static long previous = System.currentTimeMillis(),previousInfo = System.currentTimeMillis(),previousTicks = System.currentTimeMillis();
|
||||||
public static int FPS = 0,TICKS = 0;
|
public static int FPS = 0,TICKS = 0;
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
//Creation de la fenetre
|
//Creation de la fenetre
|
||||||
//------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------
|
||||||
errorCallback = new GLFWErrorCallback() {
|
errorCallback = new GLFWErrorCallback() {
|
||||||
public void invoke(int error, long description) {
|
public void invoke(int error, long description) {
|
||||||
System.err.println("ID : " + error + " | Description :" + description);
|
System.err.println("ID : " + error + " | Description :" + description);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
// glfwSetErrorCallback(errorCallback);
|
// glfwSetErrorCallback(errorCallback);
|
||||||
|
|
||||||
if(glfwInit() != GL11.GL_TRUE)throw new Exception("GLFW not init");
|
if(glfwInit() != GL11.GL_TRUE)throw new Exception("GLFW not init");
|
||||||
glfwDefaultWindowHints();
|
glfwDefaultWindowHints();
|
||||||
glfwWindowHint(GLFW_VISIBLE, GL11.GL_FALSE);
|
glfwWindowHint(GLFW_VISIBLE, GL11.GL_FALSE);
|
||||||
glfwWindowHint(GLFW_RESIZABLE, GL11.GL_FALSE);
|
glfwWindowHint(GLFW_RESIZABLE, GL11.GL_FALSE);
|
||||||
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
|
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
|
||||||
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
||||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
||||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
|
||||||
windowID = glfwCreateWindow(WIDTH,HEIGHT,TITLE,NULL,NULL);
|
windowID = glfwCreateWindow(WIDTH,HEIGHT,TITLE,NULL,NULL);
|
||||||
GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor());
|
GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor());
|
||||||
glfwSetWindowPos(windowID,(vidmode.width()-WIDTH)/2,(vidmode.height()-HEIGHT)/2);
|
glfwSetWindowPos(windowID,(vidmode.width()-WIDTH)/2,(vidmode.height()-HEIGHT)/2);
|
||||||
glfwShowWindow(windowID);
|
glfwShowWindow(windowID);
|
||||||
glfwMakeContextCurrent(windowID);
|
glfwMakeContextCurrent(windowID);
|
||||||
GL.createCapabilities();
|
GL.createCapabilities();
|
||||||
System.out.println("OpenGL Version :" + glGetString(GL_VERSION));
|
System.out.println("OpenGL Version :" + glGetString(GL_VERSION));
|
||||||
System.out.println("GLSL Shader Version :" + glGetString(GL20.GL_SHADING_LANGUAGE_VERSION));
|
System.out.println("GLSL Shader Version :" + glGetString(GL20.GL_SHADING_LANGUAGE_VERSION));
|
||||||
//------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------
|
||||||
|
|
||||||
//Creation du device audio
|
//Creation du device audio
|
||||||
//------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------
|
||||||
Audio.create();
|
Audio.create();
|
||||||
//------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------
|
||||||
|
|
||||||
//initialisation
|
//initialisation
|
||||||
//------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------
|
||||||
Input.init();
|
Input.init();
|
||||||
game = new MainGame();
|
game = new MainGame();
|
||||||
|
|
||||||
Camera.rot = new Vector3f(-3.0f,-338.0f,0.0f);
|
Camera.rot = new Vector3f(-3.0f,-338.0f,0.0f);
|
||||||
Camera.pos = new Vector3f(1.5242399f,0.0f,-13.456063f);
|
Camera.pos = new Vector3f(1.5242399f,0.0f,-13.456063f);
|
||||||
Camera.transform();
|
Camera.transform();
|
||||||
//------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------
|
||||||
|
|
||||||
while(glfwWindowShouldClose(windowID) == GL11.GL_FALSE){
|
while(glfwWindowShouldClose(windowID) == GL11.GL_FALSE){
|
||||||
|
|
||||||
if(System.currentTimeMillis() - previousTicks >= 1000/60){//Update TICKS
|
if(System.currentTimeMillis() - previousTicks >= 1000/60){//Update TICKS
|
||||||
glfwPollEvents();
|
glfwPollEvents();
|
||||||
Input.update();
|
Input.update();
|
||||||
game.update();
|
game.update();
|
||||||
previousTicks = System.currentTimeMillis();
|
previousTicks = System.currentTimeMillis();
|
||||||
delta = (float)(System.currentTimeMillis() - previous)/1000.0f;
|
delta = (float)(System.currentTimeMillis() - previous)/1000.0f;
|
||||||
previous = System.currentTimeMillis();
|
previous = System.currentTimeMillis();
|
||||||
TICKS++;
|
TICKS++;
|
||||||
}else{//Update FPS
|
}else{//Update FPS
|
||||||
DisplayManager.clear();
|
DisplayManager.clear();
|
||||||
DisplayManager.preRender3D();
|
DisplayManager.preRender3D();
|
||||||
DisplayManager.render3D();
|
DisplayManager.render3D();
|
||||||
DisplayManager.preRender2D();
|
DisplayManager.preRender2D();
|
||||||
DisplayManager.render2D();
|
DisplayManager.render2D();
|
||||||
DisplayManager.preRenderGUI();
|
DisplayManager.preRenderGUI();
|
||||||
DisplayManager.renderGUI();
|
DisplayManager.renderGUI();
|
||||||
glfwSwapBuffers(windowID);
|
glfwSwapBuffers(windowID);
|
||||||
FPS++;
|
FPS++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(System.currentTimeMillis() - previousInfo >= 1000){
|
if(System.currentTimeMillis() - previousInfo >= 1000){
|
||||||
glfwSetWindowTitle(windowID, TITLE + " | FPS:" + FPS + " TICKS:" + TICKS);
|
glfwSetWindowTitle(windowID, TITLE + " | FPS:" + FPS + " TICKS:" + TICKS);
|
||||||
FPS = 0;
|
FPS = 0;
|
||||||
TICKS = 0;
|
TICKS = 0;
|
||||||
previousInfo = System.currentTimeMillis();
|
previousInfo = System.currentTimeMillis();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Audio.destroy();
|
Audio.destroy();
|
||||||
glfwDestroyWindow(windowID);
|
glfwDestroyWindow(windowID);
|
||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,341 +1,341 @@
|
||||||
package fr.technicalgames.audio;
|
package fr.technicalgames.audio;
|
||||||
|
|
||||||
import static org.lwjgl.openal.AL10.*;
|
import static org.lwjgl.openal.AL10.*;
|
||||||
import static org.lwjgl.openal.ALC10.*;
|
import static org.lwjgl.openal.ALC10.*;
|
||||||
import static org.lwjgl.openal.ALC11.*;
|
import static org.lwjgl.openal.ALC11.*;
|
||||||
import static org.lwjgl.openal.ALUtil.*;
|
import static org.lwjgl.openal.ALUtil.*;
|
||||||
import static org.lwjgl.stb.STBVorbis.*;
|
import static org.lwjgl.stb.STBVorbis.*;
|
||||||
import static org.lwjgl.system.MemoryUtil.*;
|
import static org.lwjgl.system.MemoryUtil.*;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.nio.*;
|
import java.nio.*;
|
||||||
import java.nio.channels.*;
|
import java.nio.channels.*;
|
||||||
|
|
||||||
import javax.sound.sampled.*;
|
import javax.sound.sampled.*;
|
||||||
|
|
||||||
import org.lwjgl.*;
|
import org.lwjgl.*;
|
||||||
import org.lwjgl.openal.*;
|
import org.lwjgl.openal.*;
|
||||||
|
|
||||||
|
|
||||||
import org.lwjgl.stb.STBVorbisInfo;
|
import org.lwjgl.stb.STBVorbisInfo;
|
||||||
|
|
||||||
public abstract class Audio {
|
public abstract class Audio {
|
||||||
|
|
||||||
//Variables global
|
//Variables global
|
||||||
//------------------------------------------------------
|
//------------------------------------------------------
|
||||||
public static ALDevice device;
|
public static ALDevice device;
|
||||||
public static ALCCapabilities caps;
|
public static ALCCapabilities caps;
|
||||||
public static ALContext context;
|
public static ALContext context;
|
||||||
public static final int INITIAL_STATE = 4113,PAUSED_STATE = 4115,STOPPED_STATE = 4116,PLAYING_STATE = 4114;
|
public static final int INITIAL_STATE = 4113,PAUSED_STATE = 4115,STOPPED_STATE = 4116,PLAYING_STATE = 4114;
|
||||||
//------------------------------------------------------
|
//------------------------------------------------------
|
||||||
|
|
||||||
//Variable de l'objet audio ou du son a lire
|
//Variable de l'objet audio ou du son a lire
|
||||||
//------------------------------------------------------
|
//------------------------------------------------------
|
||||||
private int buffer,source;
|
private int buffer,source;
|
||||||
private String fileName;
|
private String fileName;
|
||||||
private String format;
|
private String format;
|
||||||
//------------------------------------------------------
|
//------------------------------------------------------
|
||||||
|
|
||||||
//Fonction global
|
//Fonction global
|
||||||
//------------------------------------------------------
|
//------------------------------------------------------
|
||||||
public static void create(){
|
public static void create(){
|
||||||
device = ALDevice.create(null);
|
device = ALDevice.create(null);
|
||||||
if ( device == null )
|
if ( device == null )
|
||||||
throw new IllegalStateException("Failed to open the default device.");
|
throw new IllegalStateException("Failed to open the default device.");
|
||||||
caps = device.getCapabilities();
|
caps = device.getCapabilities();
|
||||||
System.out.println("---------------------------- Create Audio Device -------------------------------------");
|
System.out.println("---------------------------- Create Audio Device -------------------------------------");
|
||||||
System.out.println("OpenALC10: " + caps.OpenALC10);
|
System.out.println("OpenALC10: " + caps.OpenALC10);
|
||||||
System.out.println("OpenALC11: " + caps.OpenALC11);
|
System.out.println("OpenALC11: " + caps.OpenALC11);
|
||||||
System.out.println("caps.ALC_EXT_EFX = " + caps.ALC_EXT_EFX);
|
System.out.println("caps.ALC_EXT_EFX = " + caps.ALC_EXT_EFX);
|
||||||
|
|
||||||
String defaultDeviceSpecifier = alcGetString(0L, ALC_DEFAULT_DEVICE_SPECIFIER);
|
String defaultDeviceSpecifier = alcGetString(0L, ALC_DEFAULT_DEVICE_SPECIFIER);
|
||||||
System.out.println("Default device: " + defaultDeviceSpecifier);
|
System.out.println("Default device: " + defaultDeviceSpecifier);
|
||||||
|
|
||||||
context = ALContext.create(device);
|
context = ALContext.create(device);
|
||||||
|
|
||||||
System.out.println("ALC_FREQUENCY: " + alcGetInteger(device.address(), ALC_FREQUENCY) + "Hz");
|
System.out.println("ALC_FREQUENCY: " + alcGetInteger(device.address(), ALC_FREQUENCY) + "Hz");
|
||||||
System.out.println("ALC_REFRESH: " + alcGetInteger(device.address(), ALC_REFRESH) + "Hz");
|
System.out.println("ALC_REFRESH: " + alcGetInteger(device.address(), ALC_REFRESH) + "Hz");
|
||||||
System.out.println("ALC_SYNC: " + (alcGetInteger(device.address(), ALC_SYNC) == ALC_TRUE));
|
System.out.println("ALC_SYNC: " + (alcGetInteger(device.address(), ALC_SYNC) == ALC_TRUE));
|
||||||
System.out.println("ALC_MONO_SOURCES: " + alcGetInteger(device.address(), ALC_MONO_SOURCES));
|
System.out.println("ALC_MONO_SOURCES: " + alcGetInteger(device.address(), ALC_MONO_SOURCES));
|
||||||
System.out.println("ALC_STEREO_SOURCES: " + alcGetInteger(device.address(), ALC_STEREO_SOURCES));
|
System.out.println("ALC_STEREO_SOURCES: " + alcGetInteger(device.address(), ALC_STEREO_SOURCES));
|
||||||
System.out.println("---------------------------------------------------------------------------------------");
|
System.out.println("---------------------------------------------------------------------------------------");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void destroy(){
|
public static void destroy(){
|
||||||
context.destroy();
|
context.destroy();
|
||||||
device.destroy();
|
device.destroy();
|
||||||
}
|
}
|
||||||
//------------------------------------------------------
|
//------------------------------------------------------
|
||||||
|
|
||||||
//Fonction de l'objet audio ou du son a lire
|
//Fonction de l'objet audio ou du son a lire
|
||||||
//------------------------------------------------------
|
//------------------------------------------------------
|
||||||
|
|
||||||
public Audio(String fileName) throws Exception{
|
public Audio(String fileName) throws Exception{
|
||||||
this.fileName = fileName;
|
this.fileName = fileName;
|
||||||
setSound();
|
setSound();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setSound() throws Exception{
|
private void setSound() throws Exception{
|
||||||
if(fileName.endsWith(".ogg")){
|
if(fileName.endsWith(".ogg")){
|
||||||
loadOGGFormat();
|
loadOGGFormat();
|
||||||
format = "OGG";
|
format = "OGG";
|
||||||
}else if(fileName.endsWith(".wav")){
|
}else if(fileName.endsWith(".wav")){
|
||||||
loadWavFormat();
|
loadWavFormat();
|
||||||
format = "WAV";
|
format = "WAV";
|
||||||
}else{
|
}else{
|
||||||
throw new Exception("Format not supported !");
|
throw new Exception("Format not supported !");
|
||||||
}
|
}
|
||||||
alSourcei(source, AL_BUFFER, buffer);
|
alSourcei(source, AL_BUFFER, buffer);
|
||||||
checkALError();
|
checkALError();
|
||||||
int size = alGetBufferi(buffer,AL_SIZE);
|
int size = alGetBufferi(buffer,AL_SIZE);
|
||||||
int bits = alGetBufferi(buffer, AL_BITS);
|
int bits = alGetBufferi(buffer, AL_BITS);
|
||||||
int channels = alGetBufferi(buffer, AL_CHANNELS);
|
int channels = alGetBufferi(buffer, AL_CHANNELS);
|
||||||
int freq = alGetBufferi(buffer, AL_FREQUENCY);
|
int freq = alGetBufferi(buffer, AL_FREQUENCY);
|
||||||
System.out.println(fileName + " loaded !" + " | TIME : " + (size/channels/(bits/8)/freq) + "s | BITS : " + bits + " | CHANNELS : " + channels + " | FREQUENCE : " + freq + " FORMAT : " + format);
|
System.out.println(fileName + " loaded !" + " | TIME : " + (size/channels/(bits/8)/freq) + "s | BITS : " + bits + " | CHANNELS : " + channels + " | FREQUENCE : " + freq + " FORMAT : " + format);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loadWavFormat() throws Exception{
|
public void loadWavFormat() throws Exception{
|
||||||
AudioInputStream ais = AudioSystem.getAudioInputStream(new BufferedInputStream(new FileInputStream(fileName)));
|
AudioInputStream ais = AudioSystem.getAudioInputStream(new BufferedInputStream(new FileInputStream(fileName)));
|
||||||
AudioFormat audioformat = ais.getFormat();
|
AudioFormat audioformat = ais.getFormat();
|
||||||
|
|
||||||
// get channels
|
// get channels
|
||||||
int channels = 0;
|
int channels = 0;
|
||||||
if (audioformat.getChannels() == 1) {
|
if (audioformat.getChannels() == 1) {
|
||||||
if (audioformat.getSampleSizeInBits() == 8) {
|
if (audioformat.getSampleSizeInBits() == 8) {
|
||||||
channels = AL10.AL_FORMAT_MONO8;
|
channels = AL10.AL_FORMAT_MONO8;
|
||||||
} else if (audioformat.getSampleSizeInBits() == 16) {
|
} else if (audioformat.getSampleSizeInBits() == 16) {
|
||||||
channels = AL10.AL_FORMAT_MONO16;
|
channels = AL10.AL_FORMAT_MONO16;
|
||||||
} else {
|
} else {
|
||||||
assert false : "Illegal sample size";
|
assert false : "Illegal sample size";
|
||||||
}
|
}
|
||||||
} else if (audioformat.getChannels() == 2) {
|
} else if (audioformat.getChannels() == 2) {
|
||||||
if (audioformat.getSampleSizeInBits() == 8) {
|
if (audioformat.getSampleSizeInBits() == 8) {
|
||||||
channels = AL10.AL_FORMAT_STEREO8;
|
channels = AL10.AL_FORMAT_STEREO8;
|
||||||
} else if (audioformat.getSampleSizeInBits() == 16) {
|
} else if (audioformat.getSampleSizeInBits() == 16) {
|
||||||
channels = AL10.AL_FORMAT_STEREO16;
|
channels = AL10.AL_FORMAT_STEREO16;
|
||||||
} else {
|
} else {
|
||||||
assert false : "Illegal sample size";
|
assert false : "Illegal sample size";
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
assert false : "Only mono or stereo is supported";
|
assert false : "Only mono or stereo is supported";
|
||||||
}
|
}
|
||||||
|
|
||||||
int available = ais.available();
|
int available = ais.available();
|
||||||
if(available <= 0) {
|
if(available <= 0) {
|
||||||
available = ais.getFormat().getChannels() * (int) ais.getFrameLength() * ais.getFormat().getSampleSizeInBits() / 8;
|
available = ais.getFormat().getChannels() * (int) ais.getFrameLength() * ais.getFormat().getSampleSizeInBits() / 8;
|
||||||
}
|
}
|
||||||
byte[] buf = new byte[ais.available()];
|
byte[] buf = new byte[ais.available()];
|
||||||
int read = 0, total = 0;
|
int read = 0, total = 0;
|
||||||
while ((read = ais.read(buf, total, buf.length - total)) != -1
|
while ((read = ais.read(buf, total, buf.length - total)) != -1
|
||||||
&& total < buf.length) {
|
&& total < buf.length) {
|
||||||
total += read;
|
total += read;
|
||||||
}
|
}
|
||||||
byte[] audio_bytes = buf;
|
byte[] audio_bytes = buf;
|
||||||
boolean two_bytes_data = audioformat.getSampleSizeInBits() == 16;
|
boolean two_bytes_data = audioformat.getSampleSizeInBits() == 16;
|
||||||
ByteOrder order = audioformat.isBigEndian() ? ByteOrder.BIG_ENDIAN : ByteOrder.LITTLE_ENDIAN;
|
ByteOrder order = audioformat.isBigEndian() ? ByteOrder.BIG_ENDIAN : ByteOrder.LITTLE_ENDIAN;
|
||||||
ByteBuffer dest = ByteBuffer.allocateDirect(audio_bytes.length);
|
ByteBuffer dest = ByteBuffer.allocateDirect(audio_bytes.length);
|
||||||
dest.order(ByteOrder.nativeOrder());
|
dest.order(ByteOrder.nativeOrder());
|
||||||
ByteBuffer src = ByteBuffer.wrap(audio_bytes);
|
ByteBuffer src = ByteBuffer.wrap(audio_bytes);
|
||||||
src.order(order);
|
src.order(order);
|
||||||
if (two_bytes_data) {
|
if (two_bytes_data) {
|
||||||
ShortBuffer dest_short = dest.asShortBuffer();
|
ShortBuffer dest_short = dest.asShortBuffer();
|
||||||
ShortBuffer src_short = src.asShortBuffer();
|
ShortBuffer src_short = src.asShortBuffer();
|
||||||
while (src_short.hasRemaining())
|
while (src_short.hasRemaining())
|
||||||
dest_short.put(src_short.get());
|
dest_short.put(src_short.get());
|
||||||
} else {
|
} else {
|
||||||
while (src.hasRemaining())
|
while (src.hasRemaining())
|
||||||
dest.put(src.get());
|
dest.put(src.get());
|
||||||
}
|
}
|
||||||
dest.rewind();
|
dest.rewind();
|
||||||
|
|
||||||
this.buffer = alGenBuffers();
|
this.buffer = alGenBuffers();
|
||||||
this.source = alGenSources();
|
this.source = alGenSources();
|
||||||
alBufferData(this.buffer, channels, dest, (int)audioformat.getSampleRate());
|
alBufferData(this.buffer, channels, dest, (int)audioformat.getSampleRate());
|
||||||
dest.clear();
|
dest.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loadOGGFormat(){
|
public void loadOGGFormat(){
|
||||||
STBVorbisInfo info = STBVorbisInfo.malloc();
|
STBVorbisInfo info = STBVorbisInfo.malloc();
|
||||||
ByteBuffer buff = BufferUtils.createByteBuffer(0);
|
ByteBuffer buff = BufferUtils.createByteBuffer(0);
|
||||||
//lecture du fichier
|
//lecture du fichier
|
||||||
//----------------------------------------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------------------------------------
|
||||||
try {
|
try {
|
||||||
File file = new File(fileName);
|
File file = new File(fileName);
|
||||||
if ( file.isFile() ) {
|
if ( file.isFile() ) {
|
||||||
FileInputStream fis = new FileInputStream(file);
|
FileInputStream fis = new FileInputStream(file);
|
||||||
FileChannel fc = fis.getChannel();
|
FileChannel fc = fis.getChannel();
|
||||||
buff = BufferUtils.createByteBuffer((int)fc.size() + 1);
|
buff = BufferUtils.createByteBuffer((int)fc.size() + 1);
|
||||||
|
|
||||||
while ( fc.read(buff) != -1 ) ;
|
while ( fc.read(buff) != -1 ) ;
|
||||||
|
|
||||||
fis.close();
|
fis.close();
|
||||||
fc.close();
|
fc.close();
|
||||||
} else {
|
} else {
|
||||||
System.err.println("File not found !");
|
System.err.println("File not found !");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
buff.flip();
|
buff.flip();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
//----------------------------------------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
IntBuffer error = BufferUtils.createIntBuffer(1);
|
IntBuffer error = BufferUtils.createIntBuffer(1);
|
||||||
long decoder = stb_vorbis_open_memory(buff, error, null);
|
long decoder = stb_vorbis_open_memory(buff, error, null);
|
||||||
if ( decoder == NULL )
|
if ( decoder == NULL )
|
||||||
throw new RuntimeException("Failed to open Ogg Vorbis file. Error: " + error.get(0));
|
throw new RuntimeException("Failed to open Ogg Vorbis file. Error: " + error.get(0));
|
||||||
|
|
||||||
stb_vorbis_get_info(decoder, info);
|
stb_vorbis_get_info(decoder, info);
|
||||||
|
|
||||||
int channels = info.channels();
|
int channels = info.channels();
|
||||||
|
|
||||||
stb_vorbis_seek_start(decoder);
|
stb_vorbis_seek_start(decoder);
|
||||||
int lengthSamples = stb_vorbis_stream_length_in_samples(decoder);
|
int lengthSamples = stb_vorbis_stream_length_in_samples(decoder);
|
||||||
|
|
||||||
ByteBuffer pcm = BufferUtils.createByteBuffer(lengthSamples * 2 * channels);
|
ByteBuffer pcm = BufferUtils.createByteBuffer(lengthSamples * 2 * channels);
|
||||||
|
|
||||||
stb_vorbis_get_samples_short_interleaved(decoder, channels, pcm, lengthSamples);
|
stb_vorbis_get_samples_short_interleaved(decoder, channels, pcm, lengthSamples);
|
||||||
stb_vorbis_close(decoder);
|
stb_vorbis_close(decoder);
|
||||||
|
|
||||||
buffer = alGenBuffers();
|
buffer = alGenBuffers();
|
||||||
checkALError();
|
checkALError();
|
||||||
|
|
||||||
source = alGenSources();
|
source = alGenSources();
|
||||||
checkALError();
|
checkALError();
|
||||||
|
|
||||||
if(channels == 1)alBufferData(buffer, AL_FORMAT_MONO16, pcm, info.sample_rate());
|
if(channels == 1)alBufferData(buffer, AL_FORMAT_MONO16, pcm, info.sample_rate());
|
||||||
else alBufferData(buffer, AL_FORMAT_STEREO16, pcm, info.sample_rate());
|
else alBufferData(buffer, AL_FORMAT_STEREO16, pcm, info.sample_rate());
|
||||||
checkALError();
|
checkALError();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void playSound(){
|
public void playSound(){
|
||||||
if(source == 0 || buffer == 0) return;
|
if(source == 0 || buffer == 0) return;
|
||||||
alSourcePlay(source);
|
alSourcePlay(source);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getPosition(){
|
public int getPosition(){
|
||||||
return alGetSourcei(source, AL_POSITION);
|
return alGetSourcei(source, AL_POSITION);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getDurationInSeconds(){
|
public int getDurationInSeconds(){
|
||||||
if(source == 0 || buffer == 0) return 0;
|
if(source == 0 || buffer == 0) return 0;
|
||||||
int size = alGetBufferi(buffer,AL_SIZE);
|
int size = alGetBufferi(buffer,AL_SIZE);
|
||||||
int bits = alGetBufferi(buffer, AL_BITS);
|
int bits = alGetBufferi(buffer, AL_BITS);
|
||||||
int channels = alGetBufferi(buffer, AL_CHANNELS);
|
int channels = alGetBufferi(buffer, AL_CHANNELS);
|
||||||
int freq = alGetBufferi(buffer, AL_FREQUENCY);
|
int freq = alGetBufferi(buffer, AL_FREQUENCY);
|
||||||
return size/channels/(bits/8)/freq;
|
return size/channels/(bits/8)/freq;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getStateSound(){
|
public int getStateSound(){
|
||||||
if(source == 0 || buffer == 0) return 0;
|
if(source == 0 || buffer == 0) return 0;
|
||||||
return alGetSourcei(source, AL_SOURCE_STATE);
|
return alGetSourcei(source, AL_SOURCE_STATE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isStopped(){
|
public boolean isStopped(){
|
||||||
if(source == 0 || buffer == 0) return false;
|
if(source == 0 || buffer == 0) return false;
|
||||||
if(alGetSourcei(source, AL_SOURCE_STATE) == STOPPED_STATE)return true;
|
if(alGetSourcei(source, AL_SOURCE_STATE) == STOPPED_STATE)return true;
|
||||||
else return false;
|
else return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isPaused(){
|
public boolean isPaused(){
|
||||||
if(source == 0 || buffer == 0) return false;
|
if(source == 0 || buffer == 0) return false;
|
||||||
if(alGetSourcei(source, AL_SOURCE_STATE) == PAUSED_STATE)return true;
|
if(alGetSourcei(source, AL_SOURCE_STATE) == PAUSED_STATE)return true;
|
||||||
else return false;
|
else return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isPlaying(){
|
public boolean isPlaying(){
|
||||||
if(source == 0 || buffer == 0) return false;
|
if(source == 0 || buffer == 0) return false;
|
||||||
if(alGetSourcei(source, AL_SOURCE_STATE) == PLAYING_STATE)return true;
|
if(alGetSourcei(source, AL_SOURCE_STATE) == PLAYING_STATE)return true;
|
||||||
else return false;
|
else return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isInitial(){
|
public boolean isInitial(){
|
||||||
if(source == 0 || buffer == 0) return false;
|
if(source == 0 || buffer == 0) return false;
|
||||||
if(alGetSourcei(source, AL_SOURCE_STATE) == INITIAL_STATE)return true;
|
if(alGetSourcei(source, AL_SOURCE_STATE) == INITIAL_STATE)return true;
|
||||||
else return false;
|
else return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void stopSound(){
|
public void stopSound(){
|
||||||
if(source == 0 || buffer == 0) return;
|
if(source == 0 || buffer == 0) return;
|
||||||
alSourceStop(source);
|
alSourceStop(source);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void pauseSound(){
|
public void pauseSound(){
|
||||||
if(source == 0 || buffer == 0) return;
|
if(source == 0 || buffer == 0) return;
|
||||||
alSourcePause(source);
|
alSourcePause(source);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void rewindSound(){
|
public void rewindSound(){
|
||||||
if(source == 0 || buffer == 0) return;
|
if(source == 0 || buffer == 0) return;
|
||||||
alSourceRewind(source);
|
alSourceRewind(source);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setGain(float gain){
|
public void setGain(float gain){
|
||||||
if(source == 0 || buffer == 0) return;
|
if(source == 0 || buffer == 0) return;
|
||||||
if(gain > 1.0f)gain = 1.0f;
|
if(gain > 1.0f)gain = 1.0f;
|
||||||
if(gain < 0.0f)gain = 0.0f;
|
if(gain < 0.0f)gain = 0.0f;
|
||||||
alSourcef(source, AL_GAIN, gain);
|
alSourcef(source, AL_GAIN, gain);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPitch(float pitch){
|
public void setPitch(float pitch){
|
||||||
if(source == 0 || buffer == 0) return;
|
if(source == 0 || buffer == 0) return;
|
||||||
if(pitch < 0.0f)pitch = 0.0f;
|
if(pitch < 0.0f)pitch = 0.0f;
|
||||||
alSourcef(source, AL_PITCH, pitch);
|
alSourcef(source, AL_PITCH, pitch);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public float getGain(){
|
public float getGain(){
|
||||||
if(source == 0 || buffer == 0) return 0;
|
if(source == 0 || buffer == 0) return 0;
|
||||||
return alGetSourcef(source, AL_GAIN);
|
return alGetSourcef(source, AL_GAIN);
|
||||||
}
|
}
|
||||||
|
|
||||||
public float getPitch(){
|
public float getPitch(){
|
||||||
if(source == 0 || buffer == 0) return 0;
|
if(source == 0 || buffer == 0) return 0;
|
||||||
return alGetSourcef(source, AL_PITCH);
|
return alGetSourcef(source, AL_PITCH);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLooping(boolean looping){
|
public void setLooping(boolean looping){
|
||||||
if(source == 0 || buffer == 0) return;
|
if(source == 0 || buffer == 0) return;
|
||||||
if(looping){
|
if(looping){
|
||||||
alSourcef(source, AL_LOOPING, AL_TRUE);
|
alSourcef(source, AL_LOOPING, AL_TRUE);
|
||||||
}else{
|
}else{
|
||||||
alSourcef(source, AL_LOOPING, AL_FALSE);
|
alSourcef(source, AL_LOOPING, AL_FALSE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void destroySound(){
|
public void destroySound(){
|
||||||
alDeleteSources(source);
|
alDeleteSources(source);
|
||||||
alDeleteBuffers(buffer);
|
alDeleteBuffers(buffer);
|
||||||
source = 0;
|
source = 0;
|
||||||
buffer = 0;
|
buffer = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getFileName() {
|
public String getFileName() {
|
||||||
return fileName;
|
return fileName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setFileName(String fileName) throws Exception {
|
public void setFileName(String fileName) throws Exception {
|
||||||
this.fileName = fileName;
|
this.fileName = fileName;
|
||||||
destroySound();
|
destroySound();
|
||||||
setSound();
|
setSound();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getBuffer() {
|
public int getBuffer() {
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setBuffer(int buffer) {
|
public void setBuffer(int buffer) {
|
||||||
this.buffer = buffer;
|
this.buffer = buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getSource() {
|
public int getSource() {
|
||||||
return source;
|
return source;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSource(int source) {
|
public void setSource(int source) {
|
||||||
this.source = source;
|
this.source = source;
|
||||||
}
|
}
|
||||||
//------------------------------------------------------
|
//------------------------------------------------------
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,11 +1,11 @@
|
||||||
package fr.technicalgames.audio;
|
package fr.technicalgames.audio;
|
||||||
|
|
||||||
import fr.technicalgames.math.*;
|
import fr.technicalgames.math.*;
|
||||||
|
|
||||||
public class Sound3D extends Audio{
|
public class Sound3D extends Audio{
|
||||||
|
|
||||||
public Sound3D(String fileName,Vector3f position) throws Exception {
|
public Sound3D(String fileName,Vector3f position) throws Exception {
|
||||||
super(fileName);
|
super(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,26 +1,26 @@
|
||||||
package fr.technicalgames.game;
|
package fr.technicalgames.game;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
import fr.technicalgames.light.*;
|
import fr.technicalgames.light.*;
|
||||||
import fr.technicalgames.render.*;
|
import fr.technicalgames.render.*;
|
||||||
|
|
||||||
public abstract class Game {
|
public abstract class Game {
|
||||||
|
|
||||||
public static ArrayList<Asset> assets = new ArrayList<Asset>();
|
public static ArrayList<Asset> assets = new ArrayList<Asset>();
|
||||||
public static ArrayList<Light> lights = new ArrayList<Light>();
|
public static ArrayList<Light> lights = new ArrayList<Light>();
|
||||||
|
|
||||||
public Game(){
|
public Game(){
|
||||||
init();
|
init();
|
||||||
System.out.println(this.getClass().getSimpleName() + " loaded with " + assets.size() + " assets and with " + lights.size() + " lights !");
|
System.out.println(this.getClass().getSimpleName() + " loaded with " + assets.size() + " assets and with " + lights.size() + " lights !");
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract void init();
|
public abstract void init();
|
||||||
public abstract void update();
|
public abstract void update();
|
||||||
public abstract void render2D();
|
public abstract void render2D();
|
||||||
public abstract void render3D();
|
public abstract void render3D();
|
||||||
public abstract void renderGUI();
|
public abstract void renderGUI();
|
||||||
public abstract void destroy();
|
public abstract void destroy();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,77 +1,77 @@
|
||||||
package fr.technicalgames.game;
|
package fr.technicalgames.game;
|
||||||
|
|
||||||
import fr.technicalgames.*;
|
import fr.technicalgames.*;
|
||||||
import fr.technicalgames.light.*;
|
import fr.technicalgames.light.*;
|
||||||
import fr.technicalgames.math.*;
|
import fr.technicalgames.math.*;
|
||||||
import fr.technicalgames.render.*;
|
import fr.technicalgames.render.*;
|
||||||
|
|
||||||
public class MainGame extends Game{
|
public class MainGame extends Game{
|
||||||
|
|
||||||
private float value = 0;
|
private float value = 0;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void init() {
|
public void init() {
|
||||||
|
|
||||||
lights.add(new SpotLight(new Vector3f(-4,0,10),new Vector3f(2,2,2),0.1f,0.0f,15.0f,new Vector3f(0,0,-1)));
|
lights.add(new SpotLight(new Vector3f(-4,0,10),new Vector3f(2,2,2),0.1f,0.0f,15.0f,new Vector3f(0,0,-1)));
|
||||||
lights.add(new DirectionalLight(new Vector3f(4,5,-10), new Vector3f(0.4f,0.3f,0.1f), 0.06f));
|
lights.add(new DirectionalLight(new Vector3f(4,5,-10), new Vector3f(0.4f,0.3f,0.1f), 0.06f));
|
||||||
|
|
||||||
|
|
||||||
Asset as = new Asset();
|
Asset as = new Asset();
|
||||||
as.transform = (new Matrix4f());
|
as.transform = (new Matrix4f());
|
||||||
assets.add(as);
|
assets.add(as);
|
||||||
as = new Asset();
|
as = new Asset();
|
||||||
as.transform = (new Matrix4f()).tranlate(0, -4, 0).scale(1, 2, 1);
|
as.transform = (new Matrix4f()).tranlate(0, -4, 0).scale(1, 2, 1);
|
||||||
assets.add(as);
|
assets.add(as);
|
||||||
as = new Asset();
|
as = new Asset();
|
||||||
as.transform = (new Matrix4f()).tranlate(-8,0,0).scale(1, 6, 1);
|
as.transform = (new Matrix4f()).tranlate(-8,0,0).scale(1, 6, 1);
|
||||||
assets.add(as);
|
assets.add(as);
|
||||||
as = new Asset();
|
as = new Asset();
|
||||||
as.transform = (new Matrix4f()).tranlate(-4,0,0).scale(1, 6, 1);
|
as.transform = (new Matrix4f()).tranlate(-4,0,0).scale(1, 6, 1);
|
||||||
assets.add(as);
|
assets.add(as);
|
||||||
as = new Asset();
|
as = new Asset();
|
||||||
as.transform = (new Matrix4f()).tranlate(-6,0,0).scale(2,1,0.8f);
|
as.transform = (new Matrix4f()).tranlate(-6,0,0).scale(2,1,0.8f);
|
||||||
assets.add(as);
|
assets.add(as);
|
||||||
as = new Asset();
|
as = new Asset();
|
||||||
as.transform = (new Matrix4f()).tranlate(-9, -10, -1).scale(20, .5f, 20);
|
as.transform = (new Matrix4f()).tranlate(-9, -10, -1).scale(20, .5f, 20);
|
||||||
assets.add(as);
|
assets.add(as);
|
||||||
as = null;
|
as = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update() {
|
public void update() {
|
||||||
Camera.update();
|
Camera.update();
|
||||||
Camera.transform();
|
Camera.transform();
|
||||||
|
|
||||||
lights.get(0).position.y = Mathf.cos(value) * 6f;
|
lights.get(0).position.y = Mathf.cos(value) * 6f;
|
||||||
lights.get(0).position.x = Mathf.sin(value) * 3f - 4f;
|
lights.get(0).position.x = Mathf.sin(value) * 3f - 4f;
|
||||||
value += Main.delta * 1.0f;
|
value += Main.delta * 1.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render2D() {
|
public void render2D() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render3D() {
|
public void render3D() {
|
||||||
for(Asset a : assets){
|
for(Asset a : assets){
|
||||||
a.render(lights);
|
a.render(lights);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void renderGUI() {
|
public void renderGUI() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void destroy() {
|
public void destroy() {
|
||||||
for(Asset a : assets){
|
for(Asset a : assets){
|
||||||
a.destroy();
|
a.destroy();
|
||||||
}
|
}
|
||||||
for(Light l : lights){
|
for(Light l : lights){
|
||||||
l.destroy();
|
l.destroy();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,17 +1,17 @@
|
||||||
package fr.technicalgames.input;
|
package fr.technicalgames.input;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
|
||||||
public class IO {
|
public class IO {
|
||||||
|
|
||||||
public static String loadFile(String path) throws Exception{
|
public static String loadFile(String path) throws Exception{
|
||||||
String r = "";
|
String r = "";
|
||||||
BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(path)));
|
BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(path)));
|
||||||
String buffer = "";
|
String buffer = "";
|
||||||
while ((buffer = reader.readLine()) != null) {
|
while ((buffer = reader.readLine()) != null) {
|
||||||
r += buffer + "\n";
|
r += buffer + "\n";
|
||||||
}
|
}
|
||||||
reader.close();
|
reader.close();
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,245 +1,245 @@
|
||||||
package fr.technicalgames.input;
|
package fr.technicalgames.input;
|
||||||
|
|
||||||
|
|
||||||
import static org.lwjgl.glfw.GLFW.*;
|
import static org.lwjgl.glfw.GLFW.*;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.Map.*;
|
import java.util.Map.*;
|
||||||
|
|
||||||
import org.lwjgl.glfw.*;
|
import org.lwjgl.glfw.*;
|
||||||
|
|
||||||
import fr.technicalgames.*;
|
import fr.technicalgames.*;
|
||||||
import fr.technicalgames.math.*;
|
import fr.technicalgames.math.*;
|
||||||
|
|
||||||
public class Input{
|
public class Input{
|
||||||
|
|
||||||
public static GLFWScrollCallback scroll;
|
public static GLFWScrollCallback scroll;
|
||||||
public static GLFWCursorPosCallback mousePos;
|
public static GLFWCursorPosCallback mousePos;
|
||||||
|
|
||||||
private static Vector2f mousePosition = new Vector2f();
|
private static Vector2f mousePosition = new Vector2f();
|
||||||
private static Vector2f dMouse = new Vector2f();
|
private static Vector2f dMouse = new Vector2f();
|
||||||
private static Vector2f previousDMouse = new Vector2f();
|
private static Vector2f previousDMouse = new Vector2f();
|
||||||
|
|
||||||
public static final int NONE = 0,PRESSED = 1,RELEASED = 2,REPEATED = 3,UP = 4,DOWN = 5,
|
public static final int NONE = 0,PRESSED = 1,RELEASED = 2,REPEATED = 3,UP = 4,DOWN = 5,
|
||||||
NBRE_KEY = 0x15D,NBRE_BUTTON = 10,
|
NBRE_KEY = 0x15D,NBRE_BUTTON = 10,
|
||||||
MOUSE_OFFSET = NBRE_KEY + 1,MOUSE_WHEEL_OFFSET = MOUSE_OFFSET + 1;
|
MOUSE_OFFSET = NBRE_KEY + 1,MOUSE_WHEEL_OFFSET = MOUSE_OFFSET + 1;
|
||||||
|
|
||||||
private static HashMap<Integer,Integer> state = new HashMap<Integer,Integer>();
|
private static HashMap<Integer,Integer> state = new HashMap<Integer,Integer>();
|
||||||
|
|
||||||
private static double ywheel = 0;
|
private static double ywheel = 0;
|
||||||
|
|
||||||
public static void init(){
|
public static void init(){
|
||||||
glfwSetScrollCallback(Main.windowID, scroll = new GLFWScrollCallback() {
|
glfwSetScrollCallback(Main.windowID, scroll = new GLFWScrollCallback() {
|
||||||
public void invoke(long window, double xoffset, double yoffset) {
|
public void invoke(long window, double xoffset, double yoffset) {
|
||||||
scroll(window, xoffset, yoffset);
|
scroll(window, xoffset, yoffset);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
glfwSetCursorPosCallback(Main.windowID, mousePos = new GLFWCursorPosCallback() {
|
glfwSetCursorPosCallback(Main.windowID, mousePos = new GLFWCursorPosCallback() {
|
||||||
public void invoke(long window, double xpos, double ypos) {
|
public void invoke(long window, double xpos, double ypos) {
|
||||||
mousepos(window, xpos, ypos);
|
mousepos(window, xpos, ypos);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
for(int i = 0;i < NBRE_KEY;i++){
|
for(int i = 0;i < NBRE_KEY;i++){
|
||||||
state.put(i, NONE);
|
state.put(i, NONE);
|
||||||
}
|
}
|
||||||
for(int i = 0;i < NBRE_BUTTON;i++){
|
for(int i = 0;i < NBRE_BUTTON;i++){
|
||||||
state.put(i + MOUSE_OFFSET, NONE);
|
state.put(i + MOUSE_OFFSET, NONE);
|
||||||
}
|
}
|
||||||
state.put(MOUSE_WHEEL_OFFSET, NONE);
|
state.put(MOUSE_WHEEL_OFFSET, NONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void update(){
|
public static void update(){
|
||||||
for(Entry<Integer, Integer> set : state.entrySet()){
|
for(Entry<Integer, Integer> set : state.entrySet()){
|
||||||
int i = set.getKey();
|
int i = set.getKey();
|
||||||
int st = set.getValue();
|
int st = set.getValue();
|
||||||
if(i > -1 && i < NBRE_KEY){
|
if(i > -1 && i < NBRE_KEY){
|
||||||
if(glfwGetKey(Main.windowID, i) == 0 && st == NONE)continue;
|
if(glfwGetKey(Main.windowID, i) == 0 && st == NONE)continue;
|
||||||
if(glfwGetKey(Main.windowID, i) == 1 && st == NONE){
|
if(glfwGetKey(Main.windowID, i) == 1 && st == NONE){
|
||||||
state.replace(i, PRESSED);
|
state.replace(i, PRESSED);
|
||||||
}else if(glfwGetKey(Main.windowID, i) == 1 && st == PRESSED){
|
}else if(glfwGetKey(Main.windowID, i) == 1 && st == PRESSED){
|
||||||
state.replace(i, REPEATED);
|
state.replace(i, REPEATED);
|
||||||
}else if(glfwGetKey(Main.windowID, i) == 0 && (st == PRESSED || st == REPEATED)){
|
}else if(glfwGetKey(Main.windowID, i) == 0 && (st == PRESSED || st == REPEATED)){
|
||||||
state.replace(i, RELEASED);
|
state.replace(i, RELEASED);
|
||||||
}else if(glfwGetKey(Main.windowID, i) == 0 && st == RELEASED){
|
}else if(glfwGetKey(Main.windowID, i) == 0 && st == RELEASED){
|
||||||
state.replace(i, NONE);
|
state.replace(i, NONE);
|
||||||
}
|
}
|
||||||
}else if(i >= MOUSE_OFFSET && i < MOUSE_OFFSET + NBRE_BUTTON){
|
}else if(i >= MOUSE_OFFSET && i < MOUSE_OFFSET + NBRE_BUTTON){
|
||||||
if(glfwGetMouseButton(Main.windowID, i - MOUSE_OFFSET) == 0 && st == NONE)continue;
|
if(glfwGetMouseButton(Main.windowID, i - MOUSE_OFFSET) == 0 && st == NONE)continue;
|
||||||
if(glfwGetMouseButton(Main.windowID, i - MOUSE_OFFSET) == 1 && st == NONE){
|
if(glfwGetMouseButton(Main.windowID, i - MOUSE_OFFSET) == 1 && st == NONE){
|
||||||
state.replace(i, PRESSED);
|
state.replace(i, PRESSED);
|
||||||
}else if(glfwGetMouseButton(Main.windowID, i - MOUSE_OFFSET) == 1 && st == PRESSED){
|
}else if(glfwGetMouseButton(Main.windowID, i - MOUSE_OFFSET) == 1 && st == PRESSED){
|
||||||
state.replace(i, REPEATED);
|
state.replace(i, REPEATED);
|
||||||
}else if(glfwGetMouseButton(Main.windowID, i - MOUSE_OFFSET) == 0 && (st == PRESSED || st == REPEATED)){
|
}else if(glfwGetMouseButton(Main.windowID, i - MOUSE_OFFSET) == 0 && (st == PRESSED || st == REPEATED)){
|
||||||
state.replace(i, RELEASED);
|
state.replace(i, RELEASED);
|
||||||
}else if(glfwGetMouseButton(Main.windowID, i - MOUSE_OFFSET) == 0 && st == RELEASED){
|
}else if(glfwGetMouseButton(Main.windowID, i - MOUSE_OFFSET) == 0 && st == RELEASED){
|
||||||
state.replace(i, NONE);
|
state.replace(i, NONE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
int st = state.get(MOUSE_WHEEL_OFFSET);
|
int st = state.get(MOUSE_WHEEL_OFFSET);
|
||||||
if(ywheel > 0 && (st == NONE || st == UP)){
|
if(ywheel > 0 && (st == NONE || st == UP)){
|
||||||
state.replace(MOUSE_WHEEL_OFFSET, UP);
|
state.replace(MOUSE_WHEEL_OFFSET, UP);
|
||||||
}else if(ywheel < 0 && (st == NONE || st == DOWN)){
|
}else if(ywheel < 0 && (st == NONE || st == DOWN)){
|
||||||
state.replace(MOUSE_WHEEL_OFFSET, DOWN);
|
state.replace(MOUSE_WHEEL_OFFSET, DOWN);
|
||||||
}else if(ywheel == 0 && (st == DOWN || st == UP)){
|
}else if(ywheel == 0 && (st == DOWN || st == UP)){
|
||||||
state.replace(MOUSE_WHEEL_OFFSET, NONE);
|
state.replace(MOUSE_WHEEL_OFFSET, NONE);
|
||||||
}
|
}
|
||||||
ywheel = 0;
|
ywheel = 0;
|
||||||
if(dMouse.equals(previousDMouse)){
|
if(dMouse.equals(previousDMouse)){
|
||||||
dMouse = new Vector2f();
|
dMouse = new Vector2f();
|
||||||
}else{
|
}else{
|
||||||
previousDMouse = dMouse;
|
previousDMouse = dMouse;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void destroy(){
|
public static void destroy(){
|
||||||
mousePos.release();
|
mousePos.release();
|
||||||
scroll.release();
|
scroll.release();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void scroll(long window, double xoffset, double yoffset) {
|
public static void scroll(long window, double xoffset, double yoffset) {
|
||||||
ywheel = yoffset;
|
ywheel = yoffset;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void mousepos(long window, double xpos, double ypos) {
|
public static void mousepos(long window, double xpos, double ypos) {
|
||||||
dMouse.x = (float) (xpos - mousePosition.x);
|
dMouse.x = (float) (xpos - mousePosition.x);
|
||||||
dMouse.y = (float) (ypos - mousePosition.y);
|
dMouse.y = (float) (ypos - mousePosition.y);
|
||||||
mousePosition.x = (float) xpos;
|
mousePosition.x = (float) xpos;
|
||||||
mousePosition.y = (float) ypos;
|
mousePosition.y = (float) ypos;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isButtonDown(int button){
|
public static boolean isButtonDown(int button){
|
||||||
return state.get(button + MOUSE_OFFSET) == PRESSED;
|
return state.get(button + MOUSE_OFFSET) == PRESSED;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isButtonUp(int button){
|
public static boolean isButtonUp(int button){
|
||||||
return state.get(button + MOUSE_OFFSET) == RELEASED;
|
return state.get(button + MOUSE_OFFSET) == RELEASED;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isButton(int button){
|
public static boolean isButton(int button){
|
||||||
return state.get(button + MOUSE_OFFSET) == PRESSED || state.get(button + MOUSE_OFFSET) == REPEATED;
|
return state.get(button + MOUSE_OFFSET) == PRESSED || state.get(button + MOUSE_OFFSET) == REPEATED;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int isButtonState(int button){
|
public static int isButtonState(int button){
|
||||||
return state.get(button + MOUSE_OFFSET);
|
return state.get(button + MOUSE_OFFSET);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isKeyDown(int key){
|
public static boolean isKeyDown(int key){
|
||||||
return state.get(key) == PRESSED;
|
return state.get(key) == PRESSED;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isKeyUp(int key){
|
public static boolean isKeyUp(int key){
|
||||||
return state.get(key) == RELEASED;
|
return state.get(key) == RELEASED;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isKey(int key){
|
public static boolean isKey(int key){
|
||||||
return state.get(key) == PRESSED || state.get(key) == REPEATED;
|
return state.get(key) == PRESSED || state.get(key) == REPEATED;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int isKeyState(int key){
|
public static int isKeyState(int key){
|
||||||
return state.get(key);
|
return state.get(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int isMouseWheelState(){
|
public static int isMouseWheelState(){
|
||||||
return state.get(MOUSE_WHEEL_OFFSET);
|
return state.get(MOUSE_WHEEL_OFFSET);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isMouseWheelUp(){
|
public static boolean isMouseWheelUp(){
|
||||||
return state.get(MOUSE_WHEEL_OFFSET) == UP;
|
return state.get(MOUSE_WHEEL_OFFSET) == UP;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isMouseWheelDown(){
|
public static boolean isMouseWheelDown(){
|
||||||
return state.get(MOUSE_WHEEL_OFFSET) == DOWN;
|
return state.get(MOUSE_WHEEL_OFFSET) == DOWN;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static GLFWScrollCallback getScroll() {
|
public static GLFWScrollCallback getScroll() {
|
||||||
return scroll;
|
return scroll;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setScroll(GLFWScrollCallback scroll) {
|
public static void setScroll(GLFWScrollCallback scroll) {
|
||||||
Input.scroll = scroll;
|
Input.scroll = scroll;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static GLFWCursorPosCallback getMousePos() {
|
public static GLFWCursorPosCallback getMousePos() {
|
||||||
return mousePos;
|
return mousePos;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setMousePos(GLFWCursorPosCallback mousePos) {
|
public static void setMousePos(GLFWCursorPosCallback mousePos) {
|
||||||
Input.mousePos = mousePos;
|
Input.mousePos = mousePos;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Vector2f getMousePosition() {
|
public static Vector2f getMousePosition() {
|
||||||
return mousePosition;
|
return mousePosition;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setMousePosition(Vector2f mousePosition) {
|
public static void setMousePosition(Vector2f mousePosition) {
|
||||||
Input.mousePosition = mousePosition;
|
Input.mousePosition = mousePosition;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Vector2f getDMouse() {
|
public static Vector2f getDMouse() {
|
||||||
return dMouse;
|
return dMouse;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setDMouse(Vector2f dMouse) {
|
public static void setDMouse(Vector2f dMouse) {
|
||||||
Input.dMouse = dMouse;
|
Input.dMouse = dMouse;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static HashMap<Integer, Integer> getState() {
|
public static HashMap<Integer, Integer> getState() {
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setState(HashMap<Integer, Integer> state) {
|
public static void setState(HashMap<Integer, Integer> state) {
|
||||||
Input.state = state;
|
Input.state = state;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static double getYwheel() {
|
public static double getYwheel() {
|
||||||
return ywheel;
|
return ywheel;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setYwheel(double ywheel) {
|
public static void setYwheel(double ywheel) {
|
||||||
Input.ywheel = ywheel;
|
Input.ywheel = ywheel;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getNone() {
|
public static int getNone() {
|
||||||
return NONE;
|
return NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getPressed() {
|
public static int getPressed() {
|
||||||
return PRESSED;
|
return PRESSED;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getReleased() {
|
public static int getReleased() {
|
||||||
return RELEASED;
|
return RELEASED;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getRepeated() {
|
public static int getRepeated() {
|
||||||
return REPEATED;
|
return REPEATED;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getUp() {
|
public static int getUp() {
|
||||||
return UP;
|
return UP;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getDown() {
|
public static int getDown() {
|
||||||
return DOWN;
|
return DOWN;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getNbreKey() {
|
public static int getNbreKey() {
|
||||||
return NBRE_KEY;
|
return NBRE_KEY;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getNbreButton() {
|
public static int getNbreButton() {
|
||||||
return NBRE_BUTTON;
|
return NBRE_BUTTON;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getMouseOffset() {
|
public static int getMouseOffset() {
|
||||||
return MOUSE_OFFSET;
|
return MOUSE_OFFSET;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getMouseWheelOffset() {
|
public static int getMouseWheelOffset() {
|
||||||
return MOUSE_WHEEL_OFFSET;
|
return MOUSE_WHEEL_OFFSET;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,18 +1,18 @@
|
||||||
package fr.technicalgames.light;
|
package fr.technicalgames.light;
|
||||||
|
|
||||||
import fr.technicalgames.math.*;
|
import fr.technicalgames.math.*;
|
||||||
|
|
||||||
public class DirectionalLight extends Light{
|
public class DirectionalLight extends Light{
|
||||||
|
|
||||||
public DirectionalLight(Vector3f position, Vector3f intensities,float ambientCoefficient) {
|
public DirectionalLight(Vector3f position, Vector3f intensities,float ambientCoefficient) {
|
||||||
super(new Vector4f(position,0), intensities, 1.0f, ambientCoefficient, 0.0f, new Vector3f());
|
super(new Vector4f(position,0), intensities, 1.0f, ambientCoefficient, 0.0f, new Vector3f());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update() {
|
public void update() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,76 +1,76 @@
|
||||||
package fr.technicalgames.light;
|
package fr.technicalgames.light;
|
||||||
import fr.technicalgames.math.*;
|
import fr.technicalgames.math.*;
|
||||||
import fr.technicalgames.shadow.*;
|
import fr.technicalgames.shadow.*;
|
||||||
|
|
||||||
public abstract class Light extends Shadow{
|
public abstract class Light extends Shadow{
|
||||||
|
|
||||||
public Vector4f position;//w == 0 si c une directional light
|
public Vector4f position;//w == 0 si c une directional light
|
||||||
public Vector3f intensities;
|
public Vector3f intensities;
|
||||||
public float attenuation;
|
public float attenuation;
|
||||||
public float ambientCoefficient;
|
public float ambientCoefficient;
|
||||||
public float coneAngle;
|
public float coneAngle;
|
||||||
public Vector3f coneDirection;
|
public Vector3f coneDirection;
|
||||||
|
|
||||||
public Light(Vector4f position,Vector3f intensities,float attenuation,float ambientCoefficient,float coneAngle,Vector3f coneDirection){
|
public Light(Vector4f position,Vector3f intensities,float attenuation,float ambientCoefficient,float coneAngle,Vector3f coneDirection){
|
||||||
super();
|
super();
|
||||||
this.position = position;
|
this.position = position;
|
||||||
this.intensities = intensities;
|
this.intensities = intensities;
|
||||||
this.attenuation = attenuation;
|
this.attenuation = attenuation;
|
||||||
this.ambientCoefficient = ambientCoefficient;
|
this.ambientCoefficient = ambientCoefficient;
|
||||||
this.coneAngle = coneAngle;
|
this.coneAngle = coneAngle;
|
||||||
this.coneDirection = coneDirection;
|
this.coneDirection = coneDirection;
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract void update();
|
public abstract void update();
|
||||||
|
|
||||||
public Vector4f getPosition() {
|
public Vector4f getPosition() {
|
||||||
return position;
|
return position;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPosition(Vector4f position) {
|
public void setPosition(Vector4f position) {
|
||||||
this.position = position;
|
this.position = position;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Vector3f getIntensities() {
|
public Vector3f getIntensities() {
|
||||||
return intensities;
|
return intensities;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setIntensities(Vector3f intensities) {
|
public void setIntensities(Vector3f intensities) {
|
||||||
this.intensities = intensities;
|
this.intensities = intensities;
|
||||||
}
|
}
|
||||||
|
|
||||||
public float getAttenuation() {
|
public float getAttenuation() {
|
||||||
return attenuation;
|
return attenuation;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAttenuation(float attenuation) {
|
public void setAttenuation(float attenuation) {
|
||||||
this.attenuation = attenuation;
|
this.attenuation = attenuation;
|
||||||
}
|
}
|
||||||
|
|
||||||
public float getAmbientCoefficient() {
|
public float getAmbientCoefficient() {
|
||||||
return ambientCoefficient;
|
return ambientCoefficient;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAmbientCoefficient(float ambientCoefficient) {
|
public void setAmbientCoefficient(float ambientCoefficient) {
|
||||||
this.ambientCoefficient = ambientCoefficient;
|
this.ambientCoefficient = ambientCoefficient;
|
||||||
}
|
}
|
||||||
|
|
||||||
public float getConeAngle() {
|
public float getConeAngle() {
|
||||||
return coneAngle;
|
return coneAngle;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setConeAngle(float coneAngle) {
|
public void setConeAngle(float coneAngle) {
|
||||||
this.coneAngle = coneAngle;
|
this.coneAngle = coneAngle;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Vector3f getConeDirection() {
|
public Vector3f getConeDirection() {
|
||||||
return coneDirection;
|
return coneDirection;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setConeDirection(Vector3f coneDirection) {
|
public void setConeDirection(Vector3f coneDirection) {
|
||||||
this.coneDirection = coneDirection;
|
this.coneDirection = coneDirection;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,17 +1,17 @@
|
||||||
package fr.technicalgames.light;
|
package fr.technicalgames.light;
|
||||||
|
|
||||||
import fr.technicalgames.math.*;
|
import fr.technicalgames.math.*;
|
||||||
|
|
||||||
public class SpotLight extends Light{
|
public class SpotLight extends Light{
|
||||||
|
|
||||||
public SpotLight(Vector3f position, Vector3f intensities, float attenuation, float ambientCoefficient,
|
public SpotLight(Vector3f position, Vector3f intensities, float attenuation, float ambientCoefficient,
|
||||||
float coneAngle, Vector3f coneDirection) {
|
float coneAngle, Vector3f coneDirection) {
|
||||||
super(new Vector4f(position,1), intensities, attenuation, ambientCoefficient, coneAngle, coneDirection);
|
super(new Vector4f(position,1), intensities, attenuation, ambientCoefficient, coneAngle, coneDirection);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update() {
|
public void update() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,11 +1,11 @@
|
||||||
package fr.technicalgames.material;
|
package fr.technicalgames.material;
|
||||||
|
|
||||||
import fr.technicalgames.math.*;
|
import fr.technicalgames.math.*;
|
||||||
|
|
||||||
public class DefaultMaterial extends Material{
|
public class DefaultMaterial extends Material{
|
||||||
|
|
||||||
public DefaultMaterial() {
|
public DefaultMaterial() {
|
||||||
super(80.0f, new Vector3f(1,1,1));
|
super(80.0f, new Vector3f(1,1,1));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,31 +1,31 @@
|
||||||
package fr.technicalgames.material;
|
package fr.technicalgames.material;
|
||||||
|
|
||||||
import fr.technicalgames.math.*;
|
import fr.technicalgames.math.*;
|
||||||
|
|
||||||
public abstract class Material {
|
public abstract class Material {
|
||||||
|
|
||||||
public float shininess;
|
public float shininess;
|
||||||
public Vector3f specularColor;
|
public Vector3f specularColor;
|
||||||
|
|
||||||
public Material(float shininess,Vector3f specularColor){
|
public Material(float shininess,Vector3f specularColor){
|
||||||
this.shininess = shininess;
|
this.shininess = shininess;
|
||||||
this.specularColor = specularColor;
|
this.specularColor = specularColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
public float getShininess() {
|
public float getShininess() {
|
||||||
return shininess;
|
return shininess;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setShininess(float shininess) {
|
public void setShininess(float shininess) {
|
||||||
this.shininess = shininess;
|
this.shininess = shininess;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Vector3f getSpecularColor() {
|
public Vector3f getSpecularColor() {
|
||||||
return specularColor;
|
return specularColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSpecularColor(Vector3f specularColor) {
|
public void setSpecularColor(Vector3f specularColor) {
|
||||||
this.specularColor = specularColor;
|
this.specularColor = specularColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,110 +1,110 @@
|
||||||
package fr.technicalgames.math;
|
package fr.technicalgames.math;
|
||||||
|
|
||||||
|
|
||||||
import static org.lwjgl.opengl.GL11.*;
|
import static org.lwjgl.opengl.GL11.*;
|
||||||
|
|
||||||
public class Color4f {
|
public class Color4f {
|
||||||
|
|
||||||
public static final Color4f
|
public static final Color4f
|
||||||
RED = new Color4f(1,0,0,1),
|
RED = new Color4f(1,0,0,1),
|
||||||
BLUE = new Color4f(0,0,1,1),
|
BLUE = new Color4f(0,0,1,1),
|
||||||
GREEN = new Color4f(0,1,0,1),
|
GREEN = new Color4f(0,1,0,1),
|
||||||
YELLOW = new Color4f(1,1,0,1),
|
YELLOW = new Color4f(1,1,0,1),
|
||||||
PURPLE = new Color4f(1,0,1,1),
|
PURPLE = new Color4f(1,0,1,1),
|
||||||
CYAN = new Color4f(0,1,1,1),
|
CYAN = new Color4f(0,1,1,1),
|
||||||
BLACK = new Color4f(0,0,0,1),
|
BLACK = new Color4f(0,0,0,1),
|
||||||
WHITE = new Color4f(1,1,1,1);
|
WHITE = new Color4f(1,1,1,1);
|
||||||
|
|
||||||
public float r,g,b,a;
|
public float r,g,b,a;
|
||||||
|
|
||||||
public Color4f(float r,float g,float b,float a){
|
public Color4f(float r,float g,float b,float a){
|
||||||
this.r = r;
|
this.r = r;
|
||||||
this.g = g;
|
this.g = g;
|
||||||
this.b = b;
|
this.b = b;
|
||||||
this.a = a;
|
this.a = a;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Color4f mul (Color4f a, float b){
|
public static Color4f mul (Color4f a, float b){
|
||||||
return new Color4f(a.r * b,a.g * b,a.b * b,a.a * b);
|
return new Color4f(a.r * b,a.g * b,a.b * b,a.a * b);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Color4f mul (float o,Color4f... a){
|
public static Color4f mul (float o,Color4f... a){
|
||||||
float r = 0;
|
float r = 0;
|
||||||
float b = 0;
|
float b = 0;
|
||||||
float g = 0;
|
float g = 0;
|
||||||
float al = 0;
|
float al = 0;
|
||||||
for(Color4f c : a){
|
for(Color4f c : a){
|
||||||
r += c.r;
|
r += c.r;
|
||||||
g += c.g;
|
g += c.g;
|
||||||
b += c.b;
|
b += c.b;
|
||||||
al += c.a;
|
al += c.a;
|
||||||
}
|
}
|
||||||
r /= a.length;
|
r /= a.length;
|
||||||
g /= a.length;
|
g /= a.length;
|
||||||
b /= a.length;
|
b /= a.length;
|
||||||
al /= a.length;
|
al /= a.length;
|
||||||
return new Color4f(r * o,g * o,b * o,al * o);
|
return new Color4f(r * o,g * o,b * o,al * o);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Color4f mul (Color4f... a){
|
public static Color4f mul (Color4f... a){
|
||||||
float r = 0;
|
float r = 0;
|
||||||
float b = 0;
|
float b = 0;
|
||||||
float g = 0;
|
float g = 0;
|
||||||
float al = 0;
|
float al = 0;
|
||||||
for(Color4f c : a){
|
for(Color4f c : a){
|
||||||
r += c.r;
|
r += c.r;
|
||||||
g += c.g;
|
g += c.g;
|
||||||
b += c.b;
|
b += c.b;
|
||||||
al += c.a;
|
al += c.a;
|
||||||
}
|
}
|
||||||
r /= a.length;
|
r /= a.length;
|
||||||
g /= a.length;
|
g /= a.length;
|
||||||
b /= a.length;
|
b /= a.length;
|
||||||
al /= a.length;
|
al /= a.length;
|
||||||
return new Color4f(r,g,b,al);
|
return new Color4f(r,g,b,al);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Color4f() {
|
public Color4f() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public float getR() {
|
public float getR() {
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setR(float r) {
|
public void setR(float r) {
|
||||||
this.r = r;
|
this.r = r;
|
||||||
}
|
}
|
||||||
|
|
||||||
public float getG() {
|
public float getG() {
|
||||||
return g;
|
return g;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setG(float g) {
|
public void setG(float g) {
|
||||||
this.g = g;
|
this.g = g;
|
||||||
}
|
}
|
||||||
|
|
||||||
public float getB() {
|
public float getB() {
|
||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setB(float b) {
|
public void setB(float b) {
|
||||||
this.b = b;
|
this.b = b;
|
||||||
}
|
}
|
||||||
|
|
||||||
public float getA() {
|
public float getA() {
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setA(float a) {
|
public void setA(float a) {
|
||||||
this.a = a;
|
this.a = a;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void bind(){
|
public void bind(){
|
||||||
glColor4f(r,g,b,a);
|
glColor4f(r,g,b,a);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void unbind(){
|
public void unbind(){
|
||||||
BLACK.bind();
|
BLACK.bind();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,67 +1,67 @@
|
||||||
package fr.technicalgames.math;
|
package fr.technicalgames.math;
|
||||||
|
|
||||||
|
|
||||||
public class Mathf {
|
public class Mathf {
|
||||||
|
|
||||||
public static final float PI = 3.14159265358979323846f;
|
public static final float PI = 3.14159265358979323846f;
|
||||||
public static final float EPSILON = 1.401298e-45f;
|
public static final float EPSILON = 1.401298e-45f;
|
||||||
|
|
||||||
public static float cos(float angle){
|
public static float cos(float angle){
|
||||||
return (float)Math.cos(angle);
|
return (float)Math.cos(angle);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static float acos(float angle){
|
public static float acos(float angle){
|
||||||
return (float)Math.acos(angle);
|
return (float)Math.acos(angle);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static float sin(float angle){
|
public static float sin(float angle){
|
||||||
return (float)Math.sin(angle);
|
return (float)Math.sin(angle);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static float asin(float angle){
|
public static float asin(float angle){
|
||||||
return (float)Math.asin(angle);
|
return (float)Math.asin(angle);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static float toRadians(float angle){
|
public static float toRadians(float angle){
|
||||||
return (float)Math.toRadians(angle);
|
return (float)Math.toRadians(angle);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static float toDegrees(float angle){
|
public static float toDegrees(float angle){
|
||||||
return (float)Math.toDegrees(angle);
|
return (float)Math.toDegrees(angle);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static float atan2(float a,float b){
|
public static float atan2(float a,float b){
|
||||||
return (float)Math.atan2(a,b);
|
return (float)Math.atan2(a,b);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static float cut(float nbre,float a){
|
public static float cut(float nbre,float a){
|
||||||
return (float)((int)(nbre*Math.pow(10, a))/Math.pow(10, a));
|
return (float)((int)(nbre*Math.pow(10, a))/Math.pow(10, a));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean equals(float a,float b,float tolerance){
|
public static boolean equals(float a,float b,float tolerance){
|
||||||
return (a + tolerance >= b) && (a - tolerance <= b);
|
return (a + tolerance >= b) && (a - tolerance <= b);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static float sqrt(float a){
|
public static float sqrt(float a){
|
||||||
return (float)Math.sqrt(a);
|
return (float)Math.sqrt(a);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static float exp(float a){
|
public static float exp(float a){
|
||||||
return (float)Math.sqrt(a);
|
return (float)Math.sqrt(a);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static float log(float a){
|
public static float log(float a){
|
||||||
return (float)Math.log(a);
|
return (float)Math.log(a);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static float clamp(float value, float min, float max) {
|
public static float clamp(float value, float min, float max) {
|
||||||
if(value < min){
|
if(value < min){
|
||||||
value = min;
|
value = min;
|
||||||
}
|
}
|
||||||
if(value > max){
|
if(value > max){
|
||||||
value = max;
|
value = max;
|
||||||
}
|
}
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,189 +1,189 @@
|
||||||
package fr.technicalgames.math;
|
package fr.technicalgames.math;
|
||||||
|
|
||||||
|
|
||||||
import java.nio.*;
|
import java.nio.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
import org.lwjgl.*;
|
import org.lwjgl.*;
|
||||||
|
|
||||||
public class Matrix4f {
|
public class Matrix4f {
|
||||||
|
|
||||||
public float[][] m = null;
|
public float[][] m = null;
|
||||||
|
|
||||||
public Matrix4f(){
|
public Matrix4f(){
|
||||||
m = new float[][]{
|
m = new float[][]{
|
||||||
{1,0,0,0},
|
{1,0,0,0},
|
||||||
{0,1,0,0},
|
{0,1,0,0},
|
||||||
{0,0,1,0},
|
{0,0,1,0},
|
||||||
{0,0,0,1}
|
{0,0,0,1}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public Matrix4f(float[][] m){
|
public Matrix4f(float[][] m){
|
||||||
this.m = m;
|
this.m = m;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Matrix4f loadIdentity(){
|
public Matrix4f loadIdentity(){
|
||||||
m = new float[][]{
|
m = new float[][]{
|
||||||
{1,0,0,0},
|
{1,0,0,0},
|
||||||
{0,1,0,0},
|
{0,1,0,0},
|
||||||
{0,0,1,0},
|
{0,0,1,0},
|
||||||
{0,0,0,1}
|
{0,0,0,1}
|
||||||
};
|
};
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Matrix4f rotate(Quaternion q){
|
public Matrix4f rotate(Quaternion q){
|
||||||
Matrix4f rot = q.toMatrixRotation();
|
Matrix4f rot = q.toMatrixRotation();
|
||||||
m = mul(rot).getM();
|
m = mul(rot).getM();
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void rotate(float x,float y,float z){
|
public void rotate(float x,float y,float z){
|
||||||
x = Mathf.toRadians(x);
|
x = Mathf.toRadians(x);
|
||||||
y = Mathf.toRadians(y);
|
y = Mathf.toRadians(y);
|
||||||
z = Mathf.toRadians(z);
|
z = Mathf.toRadians(z);
|
||||||
Matrix4f rx = new Matrix4f(new float[][]{
|
Matrix4f rx = new Matrix4f(new float[][]{
|
||||||
{1,0,0,0},
|
{1,0,0,0},
|
||||||
{0,Mathf.cos(x),-Mathf.sin(x),0},
|
{0,Mathf.cos(x),-Mathf.sin(x),0},
|
||||||
{0,Mathf.sin(x),Mathf.cos(x),0},
|
{0,Mathf.sin(x),Mathf.cos(x),0},
|
||||||
{0,0,0,1}
|
{0,0,0,1}
|
||||||
});
|
});
|
||||||
|
|
||||||
Matrix4f ry = new Matrix4f(new float[][]{
|
Matrix4f ry = new Matrix4f(new float[][]{
|
||||||
{Mathf.cos(y),0,Mathf.sin(y),0},
|
{Mathf.cos(y),0,Mathf.sin(y),0},
|
||||||
{0,1,0,0},
|
{0,1,0,0},
|
||||||
{-Mathf.sin(y),0,Mathf.cos(y),0},
|
{-Mathf.sin(y),0,Mathf.cos(y),0},
|
||||||
{0,0,0,1}
|
{0,0,0,1}
|
||||||
});
|
});
|
||||||
|
|
||||||
Matrix4f rz = new Matrix4f(new float[][]{
|
Matrix4f rz = new Matrix4f(new float[][]{
|
||||||
{Mathf.cos(z),-Mathf.sin(z),0,0},
|
{Mathf.cos(z),-Mathf.sin(z),0,0},
|
||||||
{Mathf.sin(z),Mathf.cos(z),0,0},
|
{Mathf.sin(z),Mathf.cos(z),0,0},
|
||||||
{0,0,1,0},
|
{0,0,1,0},
|
||||||
{0,0,0,1}
|
{0,0,0,1}
|
||||||
});
|
});
|
||||||
Matrix4f m1 = (rz.mul(ry.mul(rx)));
|
Matrix4f m1 = (rz.mul(ry.mul(rx)));
|
||||||
m = mul(m1).getM();
|
m = mul(m1).getM();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Matrix4f rotate(Vector3f forward, Vector3f up, Vector3f right)
|
public static Matrix4f rotate(Vector3f forward, Vector3f up, Vector3f right)
|
||||||
{
|
{
|
||||||
Matrix4f mat = new Matrix4f(new float[][]{
|
Matrix4f mat = new Matrix4f(new float[][]{
|
||||||
{right.getX(), right.getY(), right.getZ() ,0},
|
{right.getX(), right.getY(), right.getZ() ,0},
|
||||||
{up.getX(), up.getY(), up.getZ() ,0},
|
{up.getX(), up.getY(), up.getZ() ,0},
|
||||||
{forward.getX(),forward.getY(), forward.getZ() ,0},
|
{forward.getX(),forward.getY(), forward.getZ() ,0},
|
||||||
{0,0,0,1}
|
{0,0,0,1}
|
||||||
});
|
});
|
||||||
return mat;
|
return mat;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Matrix4f tranlate(float x,float y,float z){
|
public Matrix4f tranlate(float x,float y,float z){
|
||||||
Matrix4f mat = new Matrix4f(new float[][]{
|
Matrix4f mat = new Matrix4f(new float[][]{
|
||||||
{1,0,0,x},
|
{1,0,0,x},
|
||||||
{0,1,0,y},
|
{0,1,0,y},
|
||||||
{0,0,1,z},
|
{0,0,1,z},
|
||||||
{0,0,0,1}
|
{0,0,0,1}
|
||||||
});
|
});
|
||||||
m = mul(mat).getM();
|
m = mul(mat).getM();
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Matrix4f scale(float x,float y,float z){
|
public Matrix4f scale(float x,float y,float z){
|
||||||
Matrix4f mat = new Matrix4f(new float[][]{
|
Matrix4f mat = new Matrix4f(new float[][]{
|
||||||
{x,0,0,0},
|
{x,0,0,0},
|
||||||
{0,y,0,0},
|
{0,y,0,0},
|
||||||
{0,0,z,0},
|
{0,0,z,0},
|
||||||
{0,0,0,1}
|
{0,0,0,1}
|
||||||
});
|
});
|
||||||
m = mul(mat).getM();
|
m = mul(mat).getM();
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Matrix4f mul(Matrix4f mat){
|
public Matrix4f mul(Matrix4f mat){
|
||||||
Matrix4f ma = new Matrix4f();
|
Matrix4f ma = new Matrix4f();
|
||||||
for(int i = 0;i < 4;i++){
|
for(int i = 0;i < 4;i++){
|
||||||
for(int j = 0;j < 4;j++){
|
for(int j = 0;j < 4;j++){
|
||||||
ma.m[i][j] = m[i][0] * mat.m[0][j] +
|
ma.m[i][j] = m[i][0] * mat.m[0][j] +
|
||||||
m[i][1] * mat.m[1][j] +
|
m[i][1] * mat.m[1][j] +
|
||||||
m[i][2] * mat.m[2][j] +
|
m[i][2] * mat.m[2][j] +
|
||||||
m[i][3] * mat.m[3][j];
|
m[i][3] * mat.m[3][j];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ma;
|
return ma;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Matrix4f Ortho2D(float left, float right, float bottom, float top, float near, float far)
|
public Matrix4f Ortho2D(float left, float right, float bottom, float top, float near, float far)
|
||||||
{
|
{
|
||||||
float width = right - left;
|
float width = right - left;
|
||||||
float height = top - bottom;
|
float height = top - bottom;
|
||||||
float depth = far - near;
|
float depth = far - near;
|
||||||
|
|
||||||
m = new float[][]{
|
m = new float[][]{
|
||||||
{2/width,0,0,-(right + left)/width},
|
{2/width,0,0,-(right + left)/width},
|
||||||
{0,2/height,0,-(top + bottom)/height},
|
{0,2/height,0,-(top + bottom)/height},
|
||||||
{0,0,-2/depth,-(far + near)/depth},
|
{0,0,-2/depth,-(far + near)/depth},
|
||||||
{0,0,0,1}
|
{0,0,0,1}
|
||||||
};
|
};
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Matrix4f perspective(float fov, float aspectRatio, float zNear, float zFar)
|
public Matrix4f perspective(float fov, float aspectRatio, float zNear, float zFar)
|
||||||
{
|
{
|
||||||
float f = fov;
|
float f = fov;
|
||||||
fov = Mathf.toRadians(f);
|
fov = Mathf.toRadians(f);
|
||||||
float tanHalfFOV = (float)Math.tan(fov / 2);
|
float tanHalfFOV = (float)Math.tan(fov / 2);
|
||||||
float zRange = zNear - zFar;
|
float zRange = zNear - zFar;
|
||||||
|
|
||||||
m = new float[][]{
|
m = new float[][]{
|
||||||
{1.0f / (tanHalfFOV * aspectRatio),0,0,0},
|
{1.0f / (tanHalfFOV * aspectRatio),0,0,0},
|
||||||
{0,1.0f / tanHalfFOV,0,0},
|
{0,1.0f / tanHalfFOV,0,0},
|
||||||
{0,0,(-zNear -zFar)/zRange,2.0f * zFar * zNear / zRange},
|
{0,0,(-zNear -zFar)/zRange,2.0f * zFar * zNear / zRange},
|
||||||
{0,0,1,0}
|
{0,0,1,0}
|
||||||
};
|
};
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public FloatBuffer getBuffer(){
|
public FloatBuffer getBuffer(){
|
||||||
FloatBuffer buffer = BufferUtils.createFloatBuffer(4 * 4);
|
FloatBuffer buffer = BufferUtils.createFloatBuffer(4 * 4);
|
||||||
for(int i = 0;i < 4;i++){
|
for(int i = 0;i < 4;i++){
|
||||||
buffer.put(m[i]);
|
buffer.put(m[i]);
|
||||||
}
|
}
|
||||||
buffer.flip();
|
buffer.flip();
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toString(){
|
public String toString(){
|
||||||
int size = 3;
|
int size = 3;
|
||||||
int max = 10;
|
int max = 10;
|
||||||
StringJoiner st = new StringJoiner("\n","--------Mat4-Begin--------\n","\n--------Mat4-End----------");
|
StringJoiner st = new StringJoiner("\n","--------Mat4-Begin--------\n","\n--------Mat4-End----------");
|
||||||
for(int i = 0;i < 4;i++){
|
for(int i = 0;i < 4;i++){
|
||||||
StringJoiner st2 = new StringJoiner(" | ");
|
StringJoiner st2 = new StringJoiner(" | ");
|
||||||
for(int j = 0;j < 4;j++){
|
for(int j = 0;j < 4;j++){
|
||||||
String value = Mathf.cut(m[i][j], size) + "";
|
String value = Mathf.cut(m[i][j], size) + "";
|
||||||
for(int k = value.length();k < max;k++){
|
for(int k = value.length();k < max;k++){
|
||||||
value += " ";
|
value += " ";
|
||||||
}
|
}
|
||||||
st2.add(value);
|
st2.add(value);
|
||||||
}
|
}
|
||||||
st.add(st2.toString());
|
st.add(st2.toString());
|
||||||
}
|
}
|
||||||
return st.toString();
|
return st.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public float[][] getM() {
|
public float[][] getM() {
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setM(float[][] m) {
|
public void setM(float[][] m) {
|
||||||
this.m = m;
|
this.m = m;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Matrix4f copy(){
|
public Matrix4f copy(){
|
||||||
return new Matrix4f(this.getM());
|
return new Matrix4f(this.getM());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,132 +1,132 @@
|
||||||
package fr.technicalgames.math;
|
package fr.technicalgames.math;
|
||||||
|
|
||||||
|
|
||||||
public class Quaternion {
|
public class Quaternion {
|
||||||
|
|
||||||
public float x,y,z,w;
|
public float x,y,z,w;
|
||||||
|
|
||||||
public Quaternion(){
|
public Quaternion(){
|
||||||
x = 0;
|
x = 0;
|
||||||
y = 0;
|
y = 0;
|
||||||
z = 0;
|
z = 0;
|
||||||
w = 0;
|
w = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Quaternion(Vector3f axis,float angle){
|
public Quaternion(Vector3f axis,float angle){
|
||||||
float sin = Mathf.sin(Mathf.toRadians(angle/2.0f));
|
float sin = Mathf.sin(Mathf.toRadians(angle/2.0f));
|
||||||
float cos = Mathf.cos(Mathf.toRadians(angle/2.0f));
|
float cos = Mathf.cos(Mathf.toRadians(angle/2.0f));
|
||||||
x = axis.getX() * sin;
|
x = axis.getX() * sin;
|
||||||
y = axis.getY() * sin;
|
y = axis.getY() * sin;
|
||||||
z = axis.getZ() * sin;
|
z = axis.getZ() * sin;
|
||||||
w = cos;
|
w = cos;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Quaternion(Vector3f rot){
|
public Quaternion(Vector3f rot){
|
||||||
this(rot.x,rot.y,rot.z);
|
this(rot.x,rot.y,rot.z);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Quaternion (float yaw, float roll, float pitch) {
|
public Quaternion (float yaw, float roll, float pitch) {
|
||||||
yaw = Mathf.toRadians(yaw);
|
yaw = Mathf.toRadians(yaw);
|
||||||
roll = Mathf.toRadians(roll);
|
roll = Mathf.toRadians(roll);
|
||||||
pitch = Mathf.toRadians(pitch);
|
pitch = Mathf.toRadians(pitch);
|
||||||
float angle;
|
float angle;
|
||||||
float sinRoll, sinPitch, sinYaw, cosRoll, cosPitch, cosYaw;
|
float sinRoll, sinPitch, sinYaw, cosRoll, cosPitch, cosYaw;
|
||||||
angle = pitch * 0.5f;
|
angle = pitch * 0.5f;
|
||||||
sinPitch = Mathf.sin(angle);
|
sinPitch = Mathf.sin(angle);
|
||||||
cosPitch = Mathf.cos(angle);
|
cosPitch = Mathf.cos(angle);
|
||||||
angle = roll * 0.5f;
|
angle = roll * 0.5f;
|
||||||
sinRoll = Mathf.sin(angle);
|
sinRoll = Mathf.sin(angle);
|
||||||
cosRoll = Mathf.cos(angle);
|
cosRoll = Mathf.cos(angle);
|
||||||
angle = yaw * 0.5f;
|
angle = yaw * 0.5f;
|
||||||
sinYaw = Mathf.sin(angle);
|
sinYaw = Mathf.sin(angle);
|
||||||
cosYaw = Mathf.cos(angle);
|
cosYaw = Mathf.cos(angle);
|
||||||
|
|
||||||
// variables used to reduce multiplication calls.
|
// variables used to reduce multiplication calls.
|
||||||
float cosRollXcosPitch = cosRoll * cosPitch;
|
float cosRollXcosPitch = cosRoll * cosPitch;
|
||||||
float sinRollXsinPitch = sinRoll * sinPitch;
|
float sinRollXsinPitch = sinRoll * sinPitch;
|
||||||
float cosRollXsinPitch = cosRoll * sinPitch;
|
float cosRollXsinPitch = cosRoll * sinPitch;
|
||||||
float sinRollXcosPitch = sinRoll * cosPitch;
|
float sinRollXcosPitch = sinRoll * cosPitch;
|
||||||
|
|
||||||
w = (cosRollXcosPitch * cosYaw - sinRollXsinPitch * sinYaw);
|
w = (cosRollXcosPitch * cosYaw - sinRollXsinPitch * sinYaw);
|
||||||
x = (cosRollXcosPitch * sinYaw + sinRollXsinPitch * cosYaw);
|
x = (cosRollXcosPitch * sinYaw + sinRollXsinPitch * cosYaw);
|
||||||
y = (sinRollXcosPitch * cosYaw + cosRollXsinPitch * sinYaw);
|
y = (sinRollXcosPitch * cosYaw + cosRollXsinPitch * sinYaw);
|
||||||
z = (cosRollXsinPitch * cosYaw - sinRollXcosPitch * sinYaw);
|
z = (cosRollXsinPitch * cosYaw - sinRollXcosPitch * sinYaw);
|
||||||
|
|
||||||
normalize();
|
normalize();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void normalize(){
|
public void normalize(){
|
||||||
float n = (float)(1.0/Math.sqrt(norm()));
|
float n = (float)(1.0/Math.sqrt(norm()));
|
||||||
x *= n;
|
x *= n;
|
||||||
y *= n;
|
y *= n;
|
||||||
z *= n;
|
z *= n;
|
||||||
w *= n;
|
w *= n;
|
||||||
}
|
}
|
||||||
|
|
||||||
public float norm(){
|
public float norm(){
|
||||||
return w * w + x * x + y * y + z * z;
|
return w * w + x * x + y * y + z * z;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Quaternion Euler(Vector3f rot) {
|
public Quaternion Euler(Vector3f rot) {
|
||||||
x = Mathf.toRadians(rot.x);
|
x = Mathf.toRadians(rot.x);
|
||||||
y = Mathf.toRadians(rot.y);
|
y = Mathf.toRadians(rot.y);
|
||||||
z = Mathf.toRadians(rot.z);
|
z = Mathf.toRadians(rot.z);
|
||||||
float c1 = Mathf.cos(y/2);
|
float c1 = Mathf.cos(y/2);
|
||||||
float s1 = Mathf.sin(y/2);
|
float s1 = Mathf.sin(y/2);
|
||||||
float c2 = Mathf.cos(z/2);
|
float c2 = Mathf.cos(z/2);
|
||||||
float s2 = Mathf.sin(z/2);
|
float s2 = Mathf.sin(z/2);
|
||||||
float c3 = Mathf.cos(x/2);
|
float c3 = Mathf.cos(x/2);
|
||||||
float s3 = Mathf.sin(x/2);
|
float s3 = Mathf.sin(x/2);
|
||||||
float c1c2 = c1*c2;
|
float c1c2 = c1*c2;
|
||||||
float s1s2 = s1*s2;
|
float s1s2 = s1*s2;
|
||||||
this.w =c1c2*c3 - s1s2*s3;
|
this.w =c1c2*c3 - s1s2*s3;
|
||||||
this.x =c1c2*s3 + s1s2*c3;
|
this.x =c1c2*s3 + s1s2*c3;
|
||||||
this.y =s1*c2*c3 + c1*s2*s3;
|
this.y =s1*c2*c3 + c1*s2*s3;
|
||||||
this.z =c1*s2*c3 - s1*c2*s3;
|
this.z =c1*s2*c3 - s1*c2*s3;
|
||||||
return new Quaternion(x, y, z, w);
|
return new Quaternion(x, y, z, w);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Vector3f toEulerAngles(){
|
public Vector3f toEulerAngles(){
|
||||||
Vector3f euler = new Vector3f();
|
Vector3f euler = new Vector3f();
|
||||||
|
|
||||||
float sqw = w * w;
|
float sqw = w * w;
|
||||||
float sqx = x * x;
|
float sqx = x * x;
|
||||||
float sqy = y * y;
|
float sqy = y * y;
|
||||||
float sqz = z * z;
|
float sqz = z * z;
|
||||||
float unit = sqx + sqy + sqz + sqw; // if normalized is one, otherwise
|
float unit = sqx + sqy + sqz + sqw; // if normalized is one, otherwise
|
||||||
// is correction factor
|
// is correction factor
|
||||||
float test = x * y + z * w;
|
float test = x * y + z * w;
|
||||||
if (test > 0.499 * unit) { // singularity at north pole
|
if (test > 0.499 * unit) { // singularity at north pole
|
||||||
euler.y = 2 * Mathf.atan2(x, w);
|
euler.y = 2 * Mathf.atan2(x, w);
|
||||||
euler.z = Mathf.PI/2.0f;
|
euler.z = Mathf.PI/2.0f;
|
||||||
euler.x = 0;
|
euler.x = 0;
|
||||||
} else if (test < -0.499 * unit) { // singularity at south pole
|
} else if (test < -0.499 * unit) { // singularity at south pole
|
||||||
euler.y = -2 * Mathf.atan2(x, w);
|
euler.y = -2 * Mathf.atan2(x, w);
|
||||||
euler.z = -Mathf.PI/2.0f;
|
euler.z = -Mathf.PI/2.0f;
|
||||||
euler.x = 0;
|
euler.x = 0;
|
||||||
} else {
|
} else {
|
||||||
euler.y = Mathf.atan2(2 * y * w - 2 * x * z, sqx - sqy - sqz + sqw); // roll or heading
|
euler.y = Mathf.atan2(2 * y * w - 2 * x * z, sqx - sqy - sqz + sqw); // roll or heading
|
||||||
euler.z = Mathf.asin(2 * test / unit); // pitch or attitude
|
euler.z = Mathf.asin(2 * test / unit); // pitch or attitude
|
||||||
euler.x = Mathf.atan2(2 * x * w - 2 * y * z, -sqx + sqy - sqz + sqw); // yaw or bank
|
euler.x = Mathf.atan2(2 * x * w - 2 * y * z, -sqx + sqy - sqz + sqw); // yaw or bank
|
||||||
}
|
}
|
||||||
return euler.toDegrees();
|
return euler.toDegrees();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Quaternion(float axisX,float axisY,float axisZ,float angle){
|
public Quaternion(float axisX,float axisY,float axisZ,float angle){
|
||||||
float sin = Mathf.sin(Mathf.toRadians(angle/2.0f));
|
float sin = Mathf.sin(Mathf.toRadians(angle/2.0f));
|
||||||
float cos = Mathf.cos(Mathf.toRadians(angle/2.0f));
|
float cos = Mathf.cos(Mathf.toRadians(angle/2.0f));
|
||||||
x = axisX * sin;
|
x = axisX * sin;
|
||||||
y = axisY * sin;
|
y = axisY * sin;
|
||||||
z = axisZ * sin;
|
z = axisZ * sin;
|
||||||
w = cos;
|
w = cos;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Matrix4f toMatrixRotation(){
|
public Matrix4f toMatrixRotation(){
|
||||||
Vector3f forward = new Vector3f(2.0f * (x * z - w * y), 2.0f * (y * z + w * x), 1.0f - 2.0f * (x * x + y * y));
|
Vector3f forward = new Vector3f(2.0f * (x * z - w * y), 2.0f * (y * z + w * x), 1.0f - 2.0f * (x * x + y * y));
|
||||||
Vector3f up = new Vector3f(2.0f * (x * y + w * z), 1.0f - 2.0f * (x * x + z * z), 2.0f * (y * z - w * x));
|
Vector3f up = new Vector3f(2.0f * (x * y + w * z), 1.0f - 2.0f * (x * x + z * z), 2.0f * (y * z - w * x));
|
||||||
Vector3f right = new Vector3f(1.0f - 2.0f * (y * y + z * z), 2.0f * (x * y - w * z), 2.0f * (x * z + w * y));
|
Vector3f right = new Vector3f(1.0f - 2.0f * (y * y + z * z), 2.0f * (x * y - w * z), 2.0f * (x * z + w * y));
|
||||||
|
|
||||||
return Matrix4f.rotate(forward, up, right);
|
return Matrix4f.rotate(forward, up, right);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,42 +1,42 @@
|
||||||
package fr.technicalgames.math;
|
package fr.technicalgames.math;
|
||||||
|
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
public class Vector2f {
|
public class Vector2f {
|
||||||
|
|
||||||
public float x,y;
|
public float x,y;
|
||||||
|
|
||||||
public Vector2f(){
|
public Vector2f(){
|
||||||
x = 0;
|
x = 0;
|
||||||
y = 0;
|
y = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Vector2f(float x,float y){
|
public Vector2f(float x,float y){
|
||||||
this.x = x;
|
this.x = x;
|
||||||
this.y = y;
|
this.y = y;
|
||||||
}
|
}
|
||||||
|
|
||||||
public float getX() {
|
public float getX() {
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setX(float x) {
|
public void setX(float x) {
|
||||||
this.x = x;
|
this.x = x;
|
||||||
}
|
}
|
||||||
|
|
||||||
public float getY() {
|
public float getY() {
|
||||||
return y;
|
return y;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setY(float y) {
|
public void setY(float y) {
|
||||||
this.y = y;
|
this.y = y;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toString(){
|
public String toString(){
|
||||||
StringJoiner st = new StringJoiner(",","vec2(",")");
|
StringJoiner st = new StringJoiner(",","vec2(",")");
|
||||||
st.add("" + x);
|
st.add("" + x);
|
||||||
st.add("" + y);
|
st.add("" + y);
|
||||||
return st.toString();
|
return st.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,104 +1,104 @@
|
||||||
package fr.technicalgames.math;
|
package fr.technicalgames.math;
|
||||||
|
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
public class Vector3f {
|
public class Vector3f {
|
||||||
|
|
||||||
public float x,y,z;
|
public float x,y,z;
|
||||||
|
|
||||||
public Vector3f(){
|
public Vector3f(){
|
||||||
x = 0;
|
x = 0;
|
||||||
y = 0;
|
y = 0;
|
||||||
z = 0;
|
z = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Vector3f(float x,float y,float z){
|
public Vector3f(float x,float y,float z){
|
||||||
this.x = x;
|
this.x = x;
|
||||||
this.y = y;
|
this.y = y;
|
||||||
this.z = z;
|
this.z = z;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Vector3f(Vector2f vec,float z){
|
public Vector3f(Vector2f vec,float z){
|
||||||
this(vec.x,vec.y,z);
|
this(vec.x,vec.y,z);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Vector3f(Vector3f vec){
|
public Vector3f(Vector3f vec){
|
||||||
this(vec.x,vec.y,vec.z);
|
this(vec.x,vec.y,vec.z);
|
||||||
}
|
}
|
||||||
|
|
||||||
public float getX() {
|
public float getX() {
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setX(float x) {
|
public void setX(float x) {
|
||||||
this.x = x;
|
this.x = x;
|
||||||
}
|
}
|
||||||
|
|
||||||
public float getY() {
|
public float getY() {
|
||||||
return y;
|
return y;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setY(float y) {
|
public void setY(float y) {
|
||||||
this.y = y;
|
this.y = y;
|
||||||
}
|
}
|
||||||
|
|
||||||
public float getZ() {
|
public float getZ() {
|
||||||
return z;
|
return z;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setZ(float z) {
|
public void setZ(float z) {
|
||||||
this.z = z;
|
this.z = z;
|
||||||
}
|
}
|
||||||
|
|
||||||
public float length(){
|
public float length(){
|
||||||
return Mathf.sqrt(x * x + y * y + z * z);
|
return Mathf.sqrt(x * x + y * y + z * z);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Vector3f lookAt(Vector3f d){
|
public Vector3f lookAt(Vector3f d){
|
||||||
Vector3f rot = new Vector3f();
|
Vector3f rot = new Vector3f();
|
||||||
float x1 = d.x - x;
|
float x1 = d.x - x;
|
||||||
float y1 = d.y - y;
|
float y1 = d.y - y;
|
||||||
float z1 = d.z - z;
|
float z1 = d.z - z;
|
||||||
|
|
||||||
return rot;
|
return rot;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Vector3f normalize(){
|
public Vector3f normalize(){
|
||||||
float length = length();
|
float length = length();
|
||||||
x /= length;
|
x /= length;
|
||||||
y /= length;
|
y /= length;
|
||||||
z /= length;
|
z /= length;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Vector3f mul(float m){
|
public Vector3f mul(float m){
|
||||||
x *= m;
|
x *= m;
|
||||||
y *= m;
|
y *= m;
|
||||||
z *= m;
|
z *= m;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toString(){
|
public String toString(){
|
||||||
StringJoiner st = new StringJoiner(",","vec3(",")");
|
StringJoiner st = new StringJoiner(",","vec3(",")");
|
||||||
st.add("" + x);
|
st.add("" + x);
|
||||||
st.add("" + y);
|
st.add("" + y);
|
||||||
st.add("" + z);
|
st.add("" + z);
|
||||||
return st.toString();
|
return st.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Vector3f toRadians() {
|
public Vector3f toRadians() {
|
||||||
x = Mathf.toRadians(x);
|
x = Mathf.toRadians(x);
|
||||||
y = Mathf.toRadians(y);
|
y = Mathf.toRadians(y);
|
||||||
z = Mathf.toRadians(z);
|
z = Mathf.toRadians(z);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Vector3f toDegrees() {
|
public Vector3f toDegrees() {
|
||||||
x = Mathf.toDegrees(x);
|
x = Mathf.toDegrees(x);
|
||||||
y = Mathf.toDegrees(y);
|
y = Mathf.toDegrees(y);
|
||||||
z = Mathf.toDegrees(z);
|
z = Mathf.toDegrees(z);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,56 +1,56 @@
|
||||||
package fr.technicalgames.math;
|
package fr.technicalgames.math;
|
||||||
|
|
||||||
public class Vector4f {
|
public class Vector4f {
|
||||||
|
|
||||||
public float x,y,z,w;
|
public float x,y,z,w;
|
||||||
|
|
||||||
public Vector4f(float x,float y,float z,float w){
|
public Vector4f(float x,float y,float z,float w){
|
||||||
this.x = x;
|
this.x = x;
|
||||||
this.y = y;
|
this.y = y;
|
||||||
this.z = z;
|
this.z = z;
|
||||||
this.w = w;
|
this.w = w;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Vector4f(Vector3f v,float w){
|
public Vector4f(Vector3f v,float w){
|
||||||
this.x = v.x;
|
this.x = v.x;
|
||||||
this.y = v.y;
|
this.y = v.y;
|
||||||
this.z = v.z;
|
this.z = v.z;
|
||||||
this.w = w;
|
this.w = w;
|
||||||
}
|
}
|
||||||
|
|
||||||
public float getX() {
|
public float getX() {
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setX(float x) {
|
public void setX(float x) {
|
||||||
this.x = x;
|
this.x = x;
|
||||||
}
|
}
|
||||||
|
|
||||||
public float getY() {
|
public float getY() {
|
||||||
return y;
|
return y;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setY(float y) {
|
public void setY(float y) {
|
||||||
this.y = y;
|
this.y = y;
|
||||||
}
|
}
|
||||||
|
|
||||||
public float getZ() {
|
public float getZ() {
|
||||||
return z;
|
return z;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setZ(float z) {
|
public void setZ(float z) {
|
||||||
this.z = z;
|
this.z = z;
|
||||||
}
|
}
|
||||||
|
|
||||||
public float getW() {
|
public float getW() {
|
||||||
return w;
|
return w;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setW(float w) {
|
public void setW(float w) {
|
||||||
this.w = w;
|
this.w = w;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,133 +1,133 @@
|
||||||
package fr.technicalgames.render;
|
package fr.technicalgames.render;
|
||||||
import java.nio.*;
|
import java.nio.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
import org.lwjgl.*;
|
import org.lwjgl.*;
|
||||||
import org.lwjgl.opengl.*;
|
import org.lwjgl.opengl.*;
|
||||||
|
|
||||||
import fr.technicalgames.light.*;
|
import fr.technicalgames.light.*;
|
||||||
import fr.technicalgames.material.*;
|
import fr.technicalgames.material.*;
|
||||||
import fr.technicalgames.math.*;
|
import fr.technicalgames.math.*;
|
||||||
|
|
||||||
public class Asset {
|
public class Asset {
|
||||||
|
|
||||||
public int vbo,vao;
|
public int vbo,vao;
|
||||||
public Texture texture;
|
public Texture texture;
|
||||||
public Matrix4f transform;
|
public Matrix4f transform;
|
||||||
public Material material;
|
public Material material;
|
||||||
private int size;
|
private int size;
|
||||||
|
|
||||||
public Asset(){
|
public Asset(){
|
||||||
texture = Texture.WOOD;
|
texture = Texture.WOOD;
|
||||||
transform = new Matrix4f();
|
transform = new Matrix4f();
|
||||||
material = new DefaultMaterial();
|
material = new DefaultMaterial();
|
||||||
vao = GL30.glGenVertexArrays();
|
vao = GL30.glGenVertexArrays();
|
||||||
vbo = GL15.glGenBuffers();
|
vbo = GL15.glGenBuffers();
|
||||||
float[] a = new float[]{
|
float[] a = new float[]{
|
||||||
// X Y Z U V Normal
|
// X Y Z U V Normal
|
||||||
// bottom
|
// bottom
|
||||||
-1.0f,-1.0f,-1.0f, 0.0f, 0.0f, 0.0f, -1.0f, 0.0f,
|
-1.0f,-1.0f,-1.0f, 0.0f, 0.0f, 0.0f, -1.0f, 0.0f,
|
||||||
1.0f,-1.0f,-1.0f, 1.0f, 0.0f, 0.0f, -1.0f, 0.0f,
|
1.0f,-1.0f,-1.0f, 1.0f, 0.0f, 0.0f, -1.0f, 0.0f,
|
||||||
-1.0f,-1.0f, 1.0f, 0.0f, 1.0f, 0.0f, -1.0f, 0.0f,
|
-1.0f,-1.0f, 1.0f, 0.0f, 1.0f, 0.0f, -1.0f, 0.0f,
|
||||||
1.0f,-1.0f,-1.0f, 1.0f, 0.0f, 0.0f, -1.0f, 0.0f,
|
1.0f,-1.0f,-1.0f, 1.0f, 0.0f, 0.0f, -1.0f, 0.0f,
|
||||||
1.0f,-1.0f, 1.0f, 1.0f, 1.0f, 0.0f, -1.0f, 0.0f,
|
1.0f,-1.0f, 1.0f, 1.0f, 1.0f, 0.0f, -1.0f, 0.0f,
|
||||||
-1.0f,-1.0f, 1.0f, 0.0f, 1.0f, 0.0f, -1.0f, 0.0f,
|
-1.0f,-1.0f, 1.0f, 0.0f, 1.0f, 0.0f, -1.0f, 0.0f,
|
||||||
|
|
||||||
// top
|
// top
|
||||||
-1.0f, 1.0f,-1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f,
|
-1.0f, 1.0f,-1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f,
|
||||||
-1.0f, 1.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f,
|
-1.0f, 1.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f,
|
||||||
1.0f, 1.0f,-1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f,
|
1.0f, 1.0f,-1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f,
|
||||||
1.0f, 1.0f,-1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f,
|
1.0f, 1.0f,-1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f,
|
||||||
-1.0f, 1.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f,
|
-1.0f, 1.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f,
|
||||||
1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f, 0.0f,
|
1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f, 0.0f,
|
||||||
|
|
||||||
// front
|
// front
|
||||||
-1.0f,-1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f,
|
-1.0f,-1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f,
|
||||||
1.0f,-1.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f,
|
1.0f,-1.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f,
|
||||||
-1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f,
|
-1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f,
|
||||||
1.0f,-1.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f,
|
1.0f,-1.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f,
|
||||||
1.0f, 1.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f,
|
1.0f, 1.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f,
|
||||||
-1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f,
|
-1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f,
|
||||||
|
|
||||||
// back
|
// back
|
||||||
-1.0f,-1.0f,-1.0f, 0.0f, 0.0f, 0.0f, 0.0f, -1.0f,
|
-1.0f,-1.0f,-1.0f, 0.0f, 0.0f, 0.0f, 0.0f, -1.0f,
|
||||||
-1.0f, 1.0f,-1.0f, 0.0f, 1.0f, 0.0f, 0.0f, -1.0f,
|
-1.0f, 1.0f,-1.0f, 0.0f, 1.0f, 0.0f, 0.0f, -1.0f,
|
||||||
1.0f,-1.0f,-1.0f, 1.0f, 0.0f, 0.0f, 0.0f, -1.0f,
|
1.0f,-1.0f,-1.0f, 1.0f, 0.0f, 0.0f, 0.0f, -1.0f,
|
||||||
1.0f,-1.0f,-1.0f, 1.0f, 0.0f, 0.0f, 0.0f, -1.0f,
|
1.0f,-1.0f,-1.0f, 1.0f, 0.0f, 0.0f, 0.0f, -1.0f,
|
||||||
-1.0f, 1.0f,-1.0f, 0.0f, 1.0f, 0.0f, 0.0f, -1.0f,
|
-1.0f, 1.0f,-1.0f, 0.0f, 1.0f, 0.0f, 0.0f, -1.0f,
|
||||||
1.0f, 1.0f,-1.0f, 1.0f, 1.0f, 0.0f, 0.0f, -1.0f,
|
1.0f, 1.0f,-1.0f, 1.0f, 1.0f, 0.0f, 0.0f, -1.0f,
|
||||||
|
|
||||||
// left
|
// left
|
||||||
-1.0f,-1.0f, 1.0f, 0.0f, 1.0f, -1.0f, 0.0f, 0.0f,
|
-1.0f,-1.0f, 1.0f, 0.0f, 1.0f, -1.0f, 0.0f, 0.0f,
|
||||||
-1.0f, 1.0f,-1.0f, 1.0f, 0.0f, -1.0f, 0.0f, 0.0f,
|
-1.0f, 1.0f,-1.0f, 1.0f, 0.0f, -1.0f, 0.0f, 0.0f,
|
||||||
-1.0f,-1.0f,-1.0f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f,
|
-1.0f,-1.0f,-1.0f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f,
|
||||||
-1.0f,-1.0f, 1.0f, 0.0f, 1.0f, -1.0f, 0.0f, 0.0f,
|
-1.0f,-1.0f, 1.0f, 0.0f, 1.0f, -1.0f, 0.0f, 0.0f,
|
||||||
-1.0f, 1.0f, 1.0f, 1.0f, 1.0f, -1.0f, 0.0f, 0.0f,
|
-1.0f, 1.0f, 1.0f, 1.0f, 1.0f, -1.0f, 0.0f, 0.0f,
|
||||||
-1.0f, 1.0f,-1.0f, 1.0f, 0.0f, -1.0f, 0.0f, 0.0f,
|
-1.0f, 1.0f,-1.0f, 1.0f, 0.0f, -1.0f, 0.0f, 0.0f,
|
||||||
|
|
||||||
// right
|
// right
|
||||||
1.0f,-1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f,
|
1.0f,-1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f,
|
||||||
1.0f,-1.0f,-1.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f,
|
1.0f,-1.0f,-1.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f,
|
||||||
1.0f, 1.0f,-1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f,
|
1.0f, 1.0f,-1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f,
|
||||||
1.0f,-1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f,
|
1.0f,-1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f,
|
||||||
1.0f, 1.0f,-1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f,
|
1.0f, 1.0f,-1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f,
|
||||||
1.0f, 1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f
|
1.0f, 1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f
|
||||||
};
|
};
|
||||||
FloatBuffer buffer = BufferUtils.createFloatBuffer(a.length);
|
FloatBuffer buffer = BufferUtils.createFloatBuffer(a.length);
|
||||||
buffer.put(a).flip();
|
buffer.put(a).flip();
|
||||||
size = a.length/(3+2+3);
|
size = a.length/(3+2+3);
|
||||||
GL30.glBindVertexArray(vao);
|
GL30.glBindVertexArray(vao);
|
||||||
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vbo);
|
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vbo);
|
||||||
GL15.glBufferData(GL15.GL_ARRAY_BUFFER, buffer, GL15.GL_STATIC_DRAW);
|
GL15.glBufferData(GL15.GL_ARRAY_BUFFER, buffer, GL15.GL_STATIC_DRAW);
|
||||||
|
|
||||||
GL20.glEnableVertexAttribArray(Shaders.MAIN_LIGHT.getAttribLocation("vert"));
|
GL20.glEnableVertexAttribArray(Shaders.MAIN_LIGHT.getAttribLocation("vert"));
|
||||||
GL20.glVertexAttribPointer(Shaders.MAIN_LIGHT.getAttribLocation("vert"), 3, GL11.GL_FLOAT, false, 8*4, 0);
|
GL20.glVertexAttribPointer(Shaders.MAIN_LIGHT.getAttribLocation("vert"), 3, GL11.GL_FLOAT, false, 8*4, 0);
|
||||||
|
|
||||||
GL20.glEnableVertexAttribArray(Shaders.MAIN_LIGHT.getAttribLocation("vertTexCoord"));
|
GL20.glEnableVertexAttribArray(Shaders.MAIN_LIGHT.getAttribLocation("vertTexCoord"));
|
||||||
GL20.glVertexAttribPointer(Shaders.MAIN_LIGHT.getAttribLocation("vertTexCoord"), 2, GL11.GL_FLOAT, true, 8*4, 3*4);
|
GL20.glVertexAttribPointer(Shaders.MAIN_LIGHT.getAttribLocation("vertTexCoord"), 2, GL11.GL_FLOAT, true, 8*4, 3*4);
|
||||||
|
|
||||||
GL20.glEnableVertexAttribArray(Shaders.MAIN_LIGHT.getAttribLocation("vertNormal"));
|
GL20.glEnableVertexAttribArray(Shaders.MAIN_LIGHT.getAttribLocation("vertNormal"));
|
||||||
GL20.glVertexAttribPointer(Shaders.MAIN_LIGHT.getAttribLocation("vertNormal"), 3, GL11.GL_FLOAT, true, 8*4, 5*4);
|
GL20.glVertexAttribPointer(Shaders.MAIN_LIGHT.getAttribLocation("vertNormal"), 3, GL11.GL_FLOAT, true, 8*4, 5*4);
|
||||||
|
|
||||||
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
|
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
|
||||||
GL30.glBindVertexArray(0);
|
GL30.glBindVertexArray(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void render(ArrayList<Light> lights){
|
public void render(ArrayList<Light> lights){
|
||||||
Shaders.MAIN_LIGHT.bind();
|
Shaders.MAIN_LIGHT.bind();
|
||||||
Shaders.MAIN_LIGHT.uniform("camera", Camera.matrix);
|
Shaders.MAIN_LIGHT.uniform("camera", Camera.matrix);
|
||||||
Shaders.MAIN_LIGHT.uniform("transform", transform);
|
Shaders.MAIN_LIGHT.uniform("transform", transform);
|
||||||
Shaders.MAIN_LIGHT.uniform("projection", DisplayManager.projection);
|
Shaders.MAIN_LIGHT.uniform("projection", DisplayManager.projection);
|
||||||
Shaders.MAIN_LIGHT.uniform("materialTex", 0); //set to 0 because the texture will be bound to GL_TEXTURE0
|
Shaders.MAIN_LIGHT.uniform("materialTex", 0); //set to 0 because the texture will be bound to GL_TEXTURE0
|
||||||
Shaders.MAIN_LIGHT.uniform("materialShininess", material.shininess);
|
Shaders.MAIN_LIGHT.uniform("materialShininess", material.shininess);
|
||||||
Shaders.MAIN_LIGHT.uniform("materialSpecularColor", material.specularColor);
|
Shaders.MAIN_LIGHT.uniform("materialSpecularColor", material.specularColor);
|
||||||
Shaders.MAIN_LIGHT.uniform("numLights", lights.size());
|
Shaders.MAIN_LIGHT.uniform("numLights", lights.size());
|
||||||
Shaders.MAIN_LIGHT.uniform("cameraPosition", Camera.pos);
|
Shaders.MAIN_LIGHT.uniform("cameraPosition", Camera.pos);
|
||||||
|
|
||||||
for(int i = 0;i < lights.size();i++){
|
for(int i = 0;i < lights.size();i++){
|
||||||
Shaders.MAIN_LIGHT.uniform("allLights["+i+"].position", lights.get(i).position);
|
Shaders.MAIN_LIGHT.uniform("allLights["+i+"].position", lights.get(i).position);
|
||||||
Shaders.MAIN_LIGHT.uniform("allLights["+i+"].intensities", lights.get(i).intensities);
|
Shaders.MAIN_LIGHT.uniform("allLights["+i+"].intensities", lights.get(i).intensities);
|
||||||
Shaders.MAIN_LIGHT.uniform("allLights["+i+"].attenuation", lights.get(i).attenuation);
|
Shaders.MAIN_LIGHT.uniform("allLights["+i+"].attenuation", lights.get(i).attenuation);
|
||||||
Shaders.MAIN_LIGHT.uniform("allLights["+i+"].ambientCoefficient", lights.get(i).ambientCoefficient);
|
Shaders.MAIN_LIGHT.uniform("allLights["+i+"].ambientCoefficient", lights.get(i).ambientCoefficient);
|
||||||
Shaders.MAIN_LIGHT.uniform("allLights["+i+"].coneAngle", lights.get(i).coneAngle);
|
Shaders.MAIN_LIGHT.uniform("allLights["+i+"].coneAngle", lights.get(i).coneAngle);
|
||||||
Shaders.MAIN_LIGHT.uniform("allLights["+i+"].coneDirection", lights.get(i).coneDirection);
|
Shaders.MAIN_LIGHT.uniform("allLights["+i+"].coneDirection", lights.get(i).coneDirection);
|
||||||
}
|
}
|
||||||
|
|
||||||
GL13.glActiveTexture(GL13.GL_TEXTURE0);
|
GL13.glActiveTexture(GL13.GL_TEXTURE0);
|
||||||
texture.bind();
|
texture.bind();
|
||||||
|
|
||||||
GL30.glBindVertexArray(vao);
|
GL30.glBindVertexArray(vao);
|
||||||
GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, size);
|
GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, size);
|
||||||
GL30.glBindVertexArray(0);
|
GL30.glBindVertexArray(0);
|
||||||
texture.unbind();
|
texture.unbind();
|
||||||
Shaders.MAIN_LIGHT.unbind();
|
Shaders.MAIN_LIGHT.unbind();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void destroy(){
|
public void destroy(){
|
||||||
GL15.glDeleteBuffers(vbo);
|
GL15.glDeleteBuffers(vbo);
|
||||||
GL30.glBindVertexArray(vao);
|
GL30.glBindVertexArray(vao);
|
||||||
texture.destroy();
|
texture.destroy();
|
||||||
transform = null;
|
transform = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,67 +1,67 @@
|
||||||
package fr.technicalgames.render;
|
package fr.technicalgames.render;
|
||||||
import static org.lwjgl.glfw.GLFW.*;
|
import static org.lwjgl.glfw.GLFW.*;
|
||||||
|
|
||||||
import org.lwjgl.glfw.*;
|
import org.lwjgl.glfw.*;
|
||||||
import org.lwjgl.opengl.*;
|
import org.lwjgl.opengl.*;
|
||||||
|
|
||||||
import fr.technicalgames.*;
|
import fr.technicalgames.*;
|
||||||
import fr.technicalgames.input.*;
|
import fr.technicalgames.input.*;
|
||||||
import fr.technicalgames.math.*;
|
import fr.technicalgames.math.*;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public class Camera {
|
public class Camera {
|
||||||
|
|
||||||
public static Matrix4f matrix = new Matrix4f();
|
public static Matrix4f matrix = new Matrix4f();
|
||||||
public static final float SPEED = 1.0f;
|
public static final float SPEED = 1.0f;
|
||||||
public static final float sens = 0.5f;
|
public static final float sens = 0.5f;
|
||||||
public static float speed = 1.0f;
|
public static float speed = 1.0f;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static Vector3f rot = new Vector3f();
|
public static Vector3f rot = new Vector3f();
|
||||||
public static Vector3f pos = new Vector3f();
|
public static Vector3f pos = new Vector3f();
|
||||||
|
|
||||||
public static void update(){
|
public static void update(){
|
||||||
speed = SPEED * Main.delta;
|
speed = SPEED * Main.delta;
|
||||||
if(Input.isKey(GLFW_KEY_LEFT_CONTROL))speed *= 2.0f;
|
if(Input.isKey(GLFW_KEY_LEFT_CONTROL))speed *= 2.0f;
|
||||||
rot.x += -Input.getDMouse().getY() * sens;
|
rot.x += -Input.getDMouse().getY() * sens;
|
||||||
rot.y += -Input.getDMouse().getX() * sens;
|
rot.y += -Input.getDMouse().getX() * sens;
|
||||||
if(rot.x > 90)rot.x = 90;
|
if(rot.x > 90)rot.x = 90;
|
||||||
if(rot.x < -90)rot.x = -90;
|
if(rot.x < -90)rot.x = -90;
|
||||||
if(Input.isKey(GLFW.GLFW_KEY_W)){
|
if(Input.isKey(GLFW.GLFW_KEY_W)){
|
||||||
pos.x += Mathf.cos(Mathf.toRadians(rot.y + 90)) * speed;
|
pos.x += Mathf.cos(Mathf.toRadians(rot.y + 90)) * speed;
|
||||||
pos.z += Mathf.sin(Mathf.toRadians(rot.y + 90)) * speed;
|
pos.z += Mathf.sin(Mathf.toRadians(rot.y + 90)) * speed;
|
||||||
}
|
}
|
||||||
if(Input.isKey(GLFW.GLFW_KEY_S)){
|
if(Input.isKey(GLFW.GLFW_KEY_S)){
|
||||||
pos.x += -Mathf.cos(Mathf.toRadians(rot.y + 90)) * speed;
|
pos.x += -Mathf.cos(Mathf.toRadians(rot.y + 90)) * speed;
|
||||||
pos.z += -Mathf.sin(Mathf.toRadians(rot.y + 90)) * speed;
|
pos.z += -Mathf.sin(Mathf.toRadians(rot.y + 90)) * speed;
|
||||||
}
|
}
|
||||||
if(Input.isKey(GLFW.GLFW_KEY_A)){
|
if(Input.isKey(GLFW.GLFW_KEY_A)){
|
||||||
pos.x += -Mathf.cos(Mathf.toRadians(rot.y)) * speed;
|
pos.x += -Mathf.cos(Mathf.toRadians(rot.y)) * speed;
|
||||||
pos.z += -Mathf.sin(Mathf.toRadians(rot.y)) * speed;
|
pos.z += -Mathf.sin(Mathf.toRadians(rot.y)) * speed;
|
||||||
}
|
}
|
||||||
if(Input.isKey(GLFW.GLFW_KEY_D)){
|
if(Input.isKey(GLFW.GLFW_KEY_D)){
|
||||||
pos.x += Mathf.cos(Mathf.toRadians(rot.y)) * speed;
|
pos.x += Mathf.cos(Mathf.toRadians(rot.y)) * speed;
|
||||||
pos.z += Mathf.sin(Mathf.toRadians(rot.y)) * speed;
|
pos.z += Mathf.sin(Mathf.toRadians(rot.y)) * speed;
|
||||||
}
|
}
|
||||||
if(Input.isKey(GLFW.GLFW_KEY_LEFT_SHIFT)){
|
if(Input.isKey(GLFW.GLFW_KEY_LEFT_SHIFT)){
|
||||||
pos.y -= speed;
|
pos.y -= speed;
|
||||||
}
|
}
|
||||||
if(Input.isKey(GLFW.GLFW_KEY_SPACE)){
|
if(Input.isKey(GLFW.GLFW_KEY_SPACE)){
|
||||||
pos.y += speed;
|
pos.y += speed;
|
||||||
}
|
}
|
||||||
if(Input.isKeyDown(GLFW_KEY_ESCAPE))glfwSetWindowShouldClose(Main.windowID, GL11.GL_TRUE);
|
if(Input.isKeyDown(GLFW_KEY_ESCAPE))glfwSetWindowShouldClose(Main.windowID, GL11.GL_TRUE);
|
||||||
if(Input.isButtonDown(0))glfwSetInputMode(Main.windowID, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
|
if(Input.isButtonDown(0))glfwSetInputMode(Main.windowID, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
|
||||||
if(Input.isButtonDown(1))glfwSetInputMode(Main.windowID, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
|
if(Input.isButtonDown(1))glfwSetInputMode(Main.windowID, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void transform(){
|
public static void transform(){
|
||||||
matrix.loadIdentity();
|
matrix.loadIdentity();
|
||||||
matrix.rotate(new Quaternion(new Vector3f(1,0,0),rot.x));
|
matrix.rotate(new Quaternion(new Vector3f(1,0,0),rot.x));
|
||||||
matrix.rotate(new Quaternion(new Vector3f(0,1,0),rot.y));
|
matrix.rotate(new Quaternion(new Vector3f(0,1,0),rot.y));
|
||||||
matrix.rotate(new Quaternion(new Vector3f(0,0,1),rot.z));
|
matrix.rotate(new Quaternion(new Vector3f(0,0,1),rot.z));
|
||||||
matrix.tranlate(-pos.x, -pos.y, -pos.z);
|
matrix.tranlate(-pos.x, -pos.y, -pos.z);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,55 +1,55 @@
|
||||||
package fr.technicalgames.render;
|
package fr.technicalgames.render;
|
||||||
|
|
||||||
import static org.lwjgl.opengl.GL11.*;
|
import static org.lwjgl.opengl.GL11.*;
|
||||||
|
|
||||||
import fr.technicalgames.*;
|
import fr.technicalgames.*;
|
||||||
import fr.technicalgames.math.*;
|
import fr.technicalgames.math.*;
|
||||||
|
|
||||||
public class DisplayManager {
|
public class DisplayManager {
|
||||||
|
|
||||||
public static Matrix4f projection = new Matrix4f();
|
public static Matrix4f projection = new Matrix4f();
|
||||||
|
|
||||||
public static void clear(){
|
public static void clear(){
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void preRender2D(){
|
public static void preRender2D(){
|
||||||
projection.loadIdentity();
|
projection.loadIdentity();
|
||||||
projection.Ortho2D(0, Main.WIDTH, 0, Main.HEIGHT, -1, 1);
|
projection.Ortho2D(0, Main.WIDTH, 0, Main.HEIGHT, -1, 1);
|
||||||
glEnable(GL_DEPTH_TEST);
|
glEnable(GL_DEPTH_TEST);
|
||||||
glDepthFunc(GL_LESS);
|
glDepthFunc(GL_LESS);
|
||||||
glEnable(GL_BLEND);
|
glEnable(GL_BLEND);
|
||||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void preRender3D(){
|
public static void preRender3D(){
|
||||||
projection.loadIdentity();
|
projection.loadIdentity();
|
||||||
projection.perspective(50.0f, (float)Main.WIDTH/(float)Main.HEIGHT, 0.1f,100.0f);
|
projection.perspective(50.0f, (float)Main.WIDTH/(float)Main.HEIGHT, 0.1f,100.0f);
|
||||||
glEnable(GL_DEPTH_TEST);
|
glEnable(GL_DEPTH_TEST);
|
||||||
glDepthFunc(GL_LESS);
|
glDepthFunc(GL_LESS);
|
||||||
glEnable(GL_BLEND);
|
glEnable(GL_BLEND);
|
||||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void preRenderGUI(){
|
public static void preRenderGUI(){
|
||||||
projection.loadIdentity();
|
projection.loadIdentity();
|
||||||
projection.Ortho2D(0, Main.WIDTH, 0, Main.HEIGHT, -1, 1);
|
projection.Ortho2D(0, Main.WIDTH, 0, Main.HEIGHT, -1, 1);
|
||||||
glEnable(GL_DEPTH_TEST);
|
glEnable(GL_DEPTH_TEST);
|
||||||
glDepthFunc(GL_LESS);
|
glDepthFunc(GL_LESS);
|
||||||
glEnable(GL_BLEND);
|
glEnable(GL_BLEND);
|
||||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void render2D(){
|
public static void render2D(){
|
||||||
Main.game.render2D();
|
Main.game.render2D();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void render3D(){
|
public static void render3D(){
|
||||||
Main.game.render3D();
|
Main.game.render3D();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void renderGUI(){
|
public static void renderGUI(){
|
||||||
Main.game.renderGUI();
|
Main.game.renderGUI();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,96 +1,96 @@
|
||||||
package fr.technicalgames.render;
|
package fr.technicalgames.render;
|
||||||
import static org.lwjgl.opengl.GL11.*;
|
import static org.lwjgl.opengl.GL11.*;
|
||||||
import static org.lwjgl.opengl.GL20.*;
|
import static org.lwjgl.opengl.GL20.*;
|
||||||
|
|
||||||
import fr.technicalgames.input.*;
|
import fr.technicalgames.input.*;
|
||||||
import fr.technicalgames.math.*;
|
import fr.technicalgames.math.*;
|
||||||
|
|
||||||
public class Shaders {
|
public class Shaders {
|
||||||
|
|
||||||
public int program;
|
public int program;
|
||||||
|
|
||||||
public static Shaders MAIN_LIGHT;
|
public static Shaders MAIN_LIGHT;
|
||||||
|
|
||||||
static{
|
static{
|
||||||
try {
|
try {
|
||||||
MAIN_LIGHT = new Shaders("res/shaders/light.vert","res/shaders/light.frag");
|
MAIN_LIGHT = new Shaders("res/shaders/light.vert","res/shaders/light.frag");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Shaders(String vertexFile,String fragmentFile) throws Exception{
|
public Shaders(String vertexFile,String fragmentFile) throws Exception{
|
||||||
String fragmentShader = IO.loadFile(fragmentFile);
|
String fragmentShader = IO.loadFile(fragmentFile);
|
||||||
String vertexShader = IO.loadFile(vertexFile);
|
String vertexShader = IO.loadFile(vertexFile);
|
||||||
|
|
||||||
if(program != -1)glDeleteProgram(program);
|
if(program != -1)glDeleteProgram(program);
|
||||||
program = glCreateProgram();
|
program = glCreateProgram();
|
||||||
int vert = glCreateShader(GL_VERTEX_SHADER);
|
int vert = glCreateShader(GL_VERTEX_SHADER);
|
||||||
int frag = glCreateShader(GL_FRAGMENT_SHADER);
|
int frag = glCreateShader(GL_FRAGMENT_SHADER);
|
||||||
glShaderSource(vert, vertexShader);
|
glShaderSource(vert, vertexShader);
|
||||||
glShaderSource(frag, fragmentShader);
|
glShaderSource(frag, fragmentShader);
|
||||||
glCompileShader(vert);
|
glCompileShader(vert);
|
||||||
if (glGetShaderi(vert, GL_COMPILE_STATUS) == GL_FALSE) {
|
if (glGetShaderi(vert, GL_COMPILE_STATUS) == GL_FALSE) {
|
||||||
System.err.println(glGetShaderInfoLog(vert, 2048));
|
System.err.println(glGetShaderInfoLog(vert, 2048));
|
||||||
System.exit(1);
|
System.exit(1);
|
||||||
}else{
|
}else{
|
||||||
System.out.println("Vertex compiled !");
|
System.out.println("Vertex compiled !");
|
||||||
}
|
}
|
||||||
glCompileShader(frag);
|
glCompileShader(frag);
|
||||||
if (glGetShaderi(frag, GL_COMPILE_STATUS) == GL_FALSE) {
|
if (glGetShaderi(frag, GL_COMPILE_STATUS) == GL_FALSE) {
|
||||||
System.err.println(glGetShaderInfoLog(frag, 2048));
|
System.err.println(glGetShaderInfoLog(frag, 2048));
|
||||||
System.exit(1);
|
System.exit(1);
|
||||||
}else{
|
}else{
|
||||||
System.out.println("Fragment compiled !");
|
System.out.println("Fragment compiled !");
|
||||||
}
|
}
|
||||||
glAttachShader(program, vert);
|
glAttachShader(program, vert);
|
||||||
glAttachShader(program, frag);
|
glAttachShader(program, frag);
|
||||||
glLinkProgram(program);
|
glLinkProgram(program);
|
||||||
glValidateProgram(program);
|
glValidateProgram(program);
|
||||||
glDeleteShader(frag);
|
glDeleteShader(frag);
|
||||||
glDeleteShader(vert);
|
glDeleteShader(vert);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void bind(){
|
public void bind(){
|
||||||
glUseProgram(program);
|
glUseProgram(program);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void unbind(){
|
public void unbind(){
|
||||||
glUseProgram(0);
|
glUseProgram(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getAttribLocation(String name){
|
public int getAttribLocation(String name){
|
||||||
return glGetAttribLocation(program, name);
|
return glGetAttribLocation(program, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void destroy(){
|
public void destroy(){
|
||||||
if(program == 0)return;
|
if(program == 0)return;
|
||||||
if(glIsProgram(program))unbind();
|
if(glIsProgram(program))unbind();
|
||||||
glDeleteProgram(program);
|
glDeleteProgram(program);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void uniform(String name,float v){
|
public void uniform(String name,float v){
|
||||||
glUniform1f(glGetUniformLocation(program, name), v);
|
glUniform1f(glGetUniformLocation(program, name), v);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void uniform(String name,Vector3f vec){
|
public void uniform(String name,Vector3f vec){
|
||||||
glUniform3f(glGetUniformLocation(program, name), vec.x,vec.y,vec.z);
|
glUniform3f(glGetUniformLocation(program, name), vec.x,vec.y,vec.z);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void uniform(String name,Vector4f vec){
|
public void uniform(String name,Vector4f vec){
|
||||||
glUniform4f(glGetUniformLocation(program, name), vec.x,vec.y,vec.z,vec.w);
|
glUniform4f(glGetUniformLocation(program, name), vec.x,vec.y,vec.z,vec.w);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void uniform(String name,Matrix4f mat){
|
public void uniform(String name,Matrix4f mat){
|
||||||
glUniformMatrix4fv(glGetUniformLocation(program, name),true, mat.getBuffer());
|
glUniformMatrix4fv(glGetUniformLocation(program, name),true, mat.getBuffer());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void uniform(String name, Color4f v) {
|
public void uniform(String name, Color4f v) {
|
||||||
glUniform4f(glGetUniformLocation(program, name), v.getR(),v.getG(),v.getB(),v.getA());
|
glUniform4f(glGetUniformLocation(program, name), v.getR(),v.getG(),v.getB(),v.getA());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void uniform(String name,int v){
|
public void uniform(String name,int v){
|
||||||
glUniform1i(glGetUniformLocation(program,name), v);
|
glUniform1i(glGetUniformLocation(program,name), v);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,96 +1,96 @@
|
||||||
package fr.technicalgames.render;
|
package fr.technicalgames.render;
|
||||||
import static org.lwjgl.opengl.GL11.*;
|
import static org.lwjgl.opengl.GL11.*;
|
||||||
import static org.lwjgl.opengl.GL12.*;
|
import static org.lwjgl.opengl.GL12.*;
|
||||||
|
|
||||||
import java.awt.image.*;
|
import java.awt.image.*;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.nio.*;
|
import java.nio.*;
|
||||||
|
|
||||||
import javax.imageio.*;
|
import javax.imageio.*;
|
||||||
|
|
||||||
import org.lwjgl.*;
|
import org.lwjgl.*;
|
||||||
|
|
||||||
public class Texture {
|
public class Texture {
|
||||||
|
|
||||||
|
|
||||||
public static Texture WOOD = loadTexture("res/textures/wooden-crate.jpg");
|
public static Texture WOOD = loadTexture("res/textures/wooden-crate.jpg");
|
||||||
|
|
||||||
int width, height;
|
int width, height;
|
||||||
int id;
|
int id;
|
||||||
|
|
||||||
public Texture(int width,int height,int id){
|
public Texture(int width,int height,int id){
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.width = width;
|
this.width = width;
|
||||||
this.height = height;
|
this.height = height;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Texture loadTexture(String path){
|
public static Texture loadTexture(String path){
|
||||||
try {
|
try {
|
||||||
BufferedImage image = ImageIO.read(new File(path));
|
BufferedImage image = ImageIO.read(new File(path));
|
||||||
int width = image.getWidth();
|
int width = image.getWidth();
|
||||||
int height = image.getHeight();
|
int height = image.getHeight();
|
||||||
int[] pixels = new int[width * height];
|
int[] pixels = new int[width * height];
|
||||||
|
|
||||||
image.getRGB(0, 0, width, height, pixels, 0,width);
|
image.getRGB(0, 0, width, height, pixels, 0,width);
|
||||||
|
|
||||||
int[] data = new int[pixels.length];
|
int[] data = new int[pixels.length];
|
||||||
for (int i = 0; i < data.length; i++) {
|
for (int i = 0; i < data.length; i++) {
|
||||||
int a = (pixels[i] & 0xff000000) >> 24;
|
int a = (pixels[i] & 0xff000000) >> 24;
|
||||||
int r = (pixels[i] & 0xff0000) >> 16;
|
int r = (pixels[i] & 0xff0000) >> 16;
|
||||||
int g = (pixels[i] & 0xff00) >> 8;
|
int g = (pixels[i] & 0xff00) >> 8;
|
||||||
int b = (pixels[i] & 0xff);
|
int b = (pixels[i] & 0xff);
|
||||||
|
|
||||||
data[i] = a << 24 | b << 16 | g << 8 | r;
|
data[i] = a << 24 | b << 16 | g << 8 | r;
|
||||||
}
|
}
|
||||||
|
|
||||||
IntBuffer buffer = BufferUtils.createIntBuffer(data.length);
|
IntBuffer buffer = BufferUtils.createIntBuffer(data.length);
|
||||||
buffer.put(data);
|
buffer.put(data);
|
||||||
buffer.flip();
|
buffer.flip();
|
||||||
|
|
||||||
int id = glGenTextures();
|
int id = glGenTextures();
|
||||||
glBindTexture(GL_TEXTURE_2D, id);
|
glBindTexture(GL_TEXTURE_2D, id);
|
||||||
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||||
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||||
|
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
|
||||||
|
|
||||||
glBindTexture(GL_TEXTURE_2D, 0);
|
glBindTexture(GL_TEXTURE_2D, 0);
|
||||||
|
|
||||||
System.out.println("Texture loaded ! " + width + "x" + height + " id:" + id);
|
System.out.println("Texture loaded ! " + width + "x" + height + " id:" + id);
|
||||||
|
|
||||||
return new Texture(width, height, id);
|
return new Texture(width, height, id);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getWidth() {
|
public int getWidth() {
|
||||||
return width;
|
return width;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getHeight() {
|
public int getHeight() {
|
||||||
return height;
|
return height;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getID(){
|
public int getID(){
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void bind(){
|
public void bind(){
|
||||||
glBindTexture(GL_TEXTURE_2D, id);
|
glBindTexture(GL_TEXTURE_2D, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void unbind(){
|
public void unbind(){
|
||||||
glBindTexture(GL_TEXTURE_2D, 0);
|
glBindTexture(GL_TEXTURE_2D, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void destroy(){
|
public void destroy(){
|
||||||
glDeleteTextures(id);
|
glDeleteTextures(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,24 +1,24 @@
|
||||||
package fr.technicalgames.render.gui;
|
package fr.technicalgames.render.gui;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.awt.image.*;
|
import java.awt.image.*;
|
||||||
import java.nio.*;
|
import java.nio.*;
|
||||||
|
|
||||||
public class GLFont {
|
public class GLFont {
|
||||||
|
|
||||||
private Font font;
|
private Font font;
|
||||||
private int textureFont;
|
private int textureFont;
|
||||||
|
|
||||||
public GLFont(String name,int style,int size){
|
public GLFont(String name,int style,int size){
|
||||||
this.font = new Font(name, style, size);
|
this.font = new Font(name, style, size);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public GLFont(){
|
public GLFont(){
|
||||||
this("Verdana",Font.BOLD,24);
|
this("Verdana",Font.BOLD,24);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,9 +1,9 @@
|
||||||
package fr.technicalgames.render.gui;
|
package fr.technicalgames.render.gui;
|
||||||
|
|
||||||
import fr.technicalgames.math.*;
|
import fr.technicalgames.math.*;
|
||||||
|
|
||||||
public abstract class GUIComponent {
|
public abstract class GUIComponent {
|
||||||
|
|
||||||
private Vector2f pos;
|
private Vector2f pos;
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,73 +1,73 @@
|
||||||
package fr.technicalgames.shadow;
|
package fr.technicalgames.shadow;
|
||||||
|
|
||||||
import org.lwjgl.opengl.*;
|
import org.lwjgl.opengl.*;
|
||||||
|
|
||||||
public class Shadow {
|
public class Shadow {
|
||||||
|
|
||||||
public static final int SIZE_OF_SHADOW_MAPPING = 1024;
|
public static final int SIZE_OF_SHADOW_MAPPING = 1024;
|
||||||
|
|
||||||
private int frameBuffer;
|
private int frameBuffer;
|
||||||
private int depthTexture;
|
private int depthTexture;
|
||||||
private boolean success = false;
|
private boolean success = false;
|
||||||
|
|
||||||
public Shadow(){
|
public Shadow(){
|
||||||
//Creer et selectionne le buffer
|
//Creer et selectionne le buffer
|
||||||
// this.frameBuffer = GL30.glGenFramebuffers();
|
// this.frameBuffer = GL30.glGenFramebuffers();
|
||||||
// GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, this.frameBuffer);
|
// GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, this.frameBuffer);
|
||||||
//
|
//
|
||||||
// //Creer la texture pour les ombres
|
// //Creer la texture pour les ombres
|
||||||
// this.depthTexture = GL11.glGenTextures();
|
// this.depthTexture = GL11.glGenTextures();
|
||||||
// GL11.glBindTexture(GL11.GL_TEXTURE_2D, this.depthTexture);
|
// GL11.glBindTexture(GL11.GL_TEXTURE_2D, this.depthTexture);
|
||||||
// GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL14.GL_DEPTH_COMPONENT16,SIZE_OF_SHADOW_MAPPING,SIZE_OF_SHADOW_MAPPING,0,GL11.GL_DEPTH_COMPONENT,GL11.GL_FLOAT,0);
|
// GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL14.GL_DEPTH_COMPONENT16,SIZE_OF_SHADOW_MAPPING,SIZE_OF_SHADOW_MAPPING,0,GL11.GL_DEPTH_COMPONENT,GL11.GL_FLOAT,0);
|
||||||
// GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
|
// GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
|
||||||
// GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST);
|
// GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST);
|
||||||
// GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL12.GL_CLAMP_TO_EDGE);
|
// GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL12.GL_CLAMP_TO_EDGE);
|
||||||
// GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL12.GL_CLAMP_TO_EDGE);
|
// GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL12.GL_CLAMP_TO_EDGE);
|
||||||
//
|
//
|
||||||
// GL32.glFramebufferTexture(GL30.GL_FRAMEBUFFER, GL30.GL_DEPTH_ATTACHMENT, depthTexture, 0);
|
// GL32.glFramebufferTexture(GL30.GL_FRAMEBUFFER, GL30.GL_DEPTH_ATTACHMENT, depthTexture, 0);
|
||||||
// GL11.glDrawBuffer(GL11.GL_NONE);
|
// GL11.glDrawBuffer(GL11.GL_NONE);
|
||||||
// GL11.glReadBuffer(GL11.GL_NONE);
|
// GL11.glReadBuffer(GL11.GL_NONE);
|
||||||
// if(GL30.glCheckFramebufferStatus(GL30.GL_FRAMEBUFFER) == GL30.GL_FRAMEBUFFER_COMPLETE){
|
// if(GL30.glCheckFramebufferStatus(GL30.GL_FRAMEBUFFER) == GL30.GL_FRAMEBUFFER_COMPLETE){
|
||||||
// success = true;
|
// success = true;
|
||||||
// }else{
|
// }else{
|
||||||
// success = false;
|
// success = false;
|
||||||
// System.err.println("Shadow not adding to light");
|
// System.err.println("Shadow not adding to light");
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
public void render(){
|
public void render(){
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void destroy(){
|
public void destroy(){
|
||||||
if(this.frameBuffer != 0)GL30.glDeleteFramebuffers(this.frameBuffer);
|
if(this.frameBuffer != 0)GL30.glDeleteFramebuffers(this.frameBuffer);
|
||||||
if(this.depthTexture != 0)GL11.glDeleteTextures(this.depthTexture);
|
if(this.depthTexture != 0)GL11.glDeleteTextures(this.depthTexture);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getFrameBuffer() {
|
public int getFrameBuffer() {
|
||||||
return frameBuffer;
|
return frameBuffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setFrameBuffer(int frameBuffer) {
|
public void setFrameBuffer(int frameBuffer) {
|
||||||
this.frameBuffer = frameBuffer;
|
this.frameBuffer = frameBuffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getDepthTexture() {
|
public int getDepthTexture() {
|
||||||
return depthTexture;
|
return depthTexture;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDepthTexture(int depthTexture) {
|
public void setDepthTexture(int depthTexture) {
|
||||||
this.depthTexture = depthTexture;
|
this.depthTexture = depthTexture;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isSuccess() {
|
public boolean isSuccess() {
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSuccess(boolean success) {
|
public void setSuccess(boolean success) {
|
||||||
this.success = success;
|
this.success = success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
Reference in a new issue