Add Ant compatibility
This commit is contained in:
parent
55fcb82edd
commit
84f1dca031
24 changed files with 375 additions and 348 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -1,3 +1,4 @@
|
||||||
bin/*
|
bin/*
|
||||||
.project
|
.project
|
||||||
.classpath
|
.classpath
|
||||||
|
*.jar
|
3
.travis.yml
Normal file
3
.travis.yml
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
language: java
|
||||||
|
jdk:
|
||||||
|
- oraclejdk8
|
|
@ -1,4 +1,8 @@
|
||||||
# First-Game-Lighting
|
# First-Game-Lighting
|
||||||
|
|
||||||
|
Compile status: ![Status](https://travis-ci.org/mrdev023/First-Game-Lighting.svg?branch=master)
|
||||||
|
|
||||||
Ce projet est seulement a projet utiliser pour apprendre le forward rendering pour ensuite l'integrer dans mon moteur de jeu qui
|
Ce projet est seulement a projet utiliser pour apprendre le forward rendering pour ensuite l'integrer dans mon moteur de jeu qui
|
||||||
sera conçus avec ces derniere technologie pour ensuite faire des jeux avec celui-ci.
|
sera conçus avec ces derniere technologie pour ensuite faire des jeux avec celui-ci.
|
||||||
|
|
||||||
|
![Image](https://pbs.twimg.com/media/Cc3DuwnWIAII5Zw.jpg:large)
|
||||||
|
|
38
build.xml
Normal file
38
build.xml
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
<project name="lwjgl-examples">
|
||||||
|
|
||||||
|
<property file="build.properties" />
|
||||||
|
<property name="src.dir" value="src" />
|
||||||
|
<property name="build.dir" value="bin"/>
|
||||||
|
<property name="lwjgl_jars.dir" value="./libs/"/>
|
||||||
|
<property name="lwjgl_natives.dir" value="./libs/"/>
|
||||||
|
<property name="build.sysclasspath" value="last"/>
|
||||||
|
|
||||||
|
<path id="my_cp">
|
||||||
|
<fileset dir="${lwjgl_jars.dir}" includes="lwjgl.jar"/>
|
||||||
|
</path>
|
||||||
|
|
||||||
|
<target name="compile">
|
||||||
|
<mkdir dir="${build.dir}"/>
|
||||||
|
<javac srcdir="${src.dir}" destdir="${build.dir}" classpathref="my_cp"/>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<target name="clean">
|
||||||
|
<delete dir="${build.dir}"/>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<target name="test" depends="compile">
|
||||||
|
<!--
|
||||||
|
fork="true" seems to be absolutely
|
||||||
|
necessary for the setting of java.library.path
|
||||||
|
to be effective.-->
|
||||||
|
|
||||||
|
<java fork="true" classname="fr/technicalgames/Main">
|
||||||
|
<classpath>
|
||||||
|
<path refid="my_cp"/>
|
||||||
|
<path location="${build.dir}"/>
|
||||||
|
</classpath>
|
||||||
|
<sysproperty key="java.library.path"
|
||||||
|
value="${lwjgl_natives.dir}"/>
|
||||||
|
</java>
|
||||||
|
</target>
|
||||||
|
</project>
|
BIN
libs/OpenAL.dll
Normal file
BIN
libs/OpenAL.dll
Normal file
Binary file not shown.
BIN
libs/OpenAL32.dll
Normal file
BIN
libs/OpenAL32.dll
Normal file
Binary file not shown.
BIN
libs/glfw.dll
Normal file
BIN
libs/glfw.dll
Normal file
Binary file not shown.
BIN
libs/glfw32.dll
Normal file
BIN
libs/glfw32.dll
Normal file
Binary file not shown.
BIN
libs/jemalloc.dll
Normal file
BIN
libs/jemalloc.dll
Normal file
Binary file not shown.
BIN
libs/jemalloc32.dll
Normal file
BIN
libs/jemalloc32.dll
Normal file
Binary file not shown.
BIN
libs/libglfw.dylib
Normal file
BIN
libs/libglfw.dylib
Normal file
Binary file not shown.
BIN
libs/libglfw.so
Normal file
BIN
libs/libglfw.so
Normal file
Binary file not shown.
BIN
libs/libjemalloc.dylib
Normal file
BIN
libs/libjemalloc.dylib
Normal file
Binary file not shown.
BIN
libs/libjemalloc.so
Normal file
BIN
libs/libjemalloc.so
Normal file
Binary file not shown.
BIN
libs/liblwjgl.dylib
Normal file
BIN
libs/liblwjgl.dylib
Normal file
Binary file not shown.
BIN
libs/liblwjgl.so
Normal file
BIN
libs/liblwjgl.so
Normal file
Binary file not shown.
BIN
libs/libopenal.dylib
Normal file
BIN
libs/libopenal.dylib
Normal file
Binary file not shown.
BIN
libs/libopenal.so
Normal file
BIN
libs/libopenal.so
Normal file
Binary file not shown.
BIN
libs/lwjgl.dll
Normal file
BIN
libs/lwjgl.dll
Normal file
Binary file not shown.
BIN
libs/lwjgl32.dll
Normal file
BIN
libs/lwjgl32.dll
Normal file
Binary file not shown.
|
@ -16,35 +16,35 @@ 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())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);
|
||||||
|
@ -59,24 +59,24 @@ public class Main {
|
||||||
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)){
|
||||||
|
|
||||||
if(System.currentTimeMillis() - previousTicks >= 1000/60){//Update TICKS
|
if(System.currentTimeMillis() - previousTicks >= 1000/60){//Update TICKS
|
||||||
glfwPollEvents();
|
glfwPollEvents();
|
||||||
Input.update();
|
Input.update();
|
||||||
|
@ -96,7 +96,7 @@ public class Main {
|
||||||
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;
|
||||||
|
@ -104,10 +104,10 @@ public class Main {
|
||||||
previousInfo = System.currentTimeMillis();
|
previousInfo = System.currentTimeMillis();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Audio.destroy();
|
Audio.destroy();
|
||||||
glfwDestroyWindow(windowID);
|
glfwDestroyWindow(windowID);
|
||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
package fr.technicalgames.audio;
|
package fr.technicalgames.audio;
|
||||||
|
|
||||||
|
import static org.lwjgl.openal.AL.createCapabilities;
|
||||||
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.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.*;
|
||||||
|
|
||||||
|
@ -19,323 +18,305 @@ import org.lwjgl.openal.*;
|
||||||
|
|
||||||
import org.lwjgl.stb.STBVorbisInfo;
|
import org.lwjgl.stb.STBVorbisInfo;
|
||||||
|
|
||||||
public abstract class Audio {
|
public class Audio {
|
||||||
|
|
||||||
//Variables global
|
|
||||||
//------------------------------------------------------
|
|
||||||
public static ALDevice device;
|
|
||||||
public static ALCCapabilities caps;
|
|
||||||
public static ALContext context;
|
|
||||||
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
|
|
||||||
//------------------------------------------------------
|
|
||||||
private int buffer,source;
|
|
||||||
private String fileName;
|
|
||||||
private String format;
|
|
||||||
//------------------------------------------------------
|
|
||||||
|
|
||||||
//Fonction global
|
//Variables global
|
||||||
//------------------------------------------------------
|
//------------------------------------------------------
|
||||||
public static void create(){
|
public static long device;
|
||||||
device = ALDevice.create(null);
|
public static ALCCapabilities caps;
|
||||||
if ( device == null )
|
public static long context;
|
||||||
throw new IllegalStateException("Failed to open the default device.");
|
public static final int INITIAL_STATE = 4113,PAUSED_STATE = 4115,STOPPED_STATE = 4116,PLAYING_STATE = 4114;
|
||||||
caps = device.getCapabilities();
|
//------------------------------------------------------
|
||||||
System.out.println("---------------------------- Create Audio Device -------------------------------------");
|
|
||||||
System.out.println("OpenALC10: " + caps.OpenALC10);
|
|
||||||
System.out.println("OpenALC11: " + caps.OpenALC11);
|
|
||||||
System.out.println("caps.ALC_EXT_EFX = " + caps.ALC_EXT_EFX);
|
|
||||||
|
|
||||||
String defaultDeviceSpecifier = alcGetString(0L, ALC_DEFAULT_DEVICE_SPECIFIER);
|
|
||||||
System.out.println("Default device: " + defaultDeviceSpecifier);
|
|
||||||
|
|
||||||
context = ALContext.create(device);
|
//Variable de l'objet audio ou du son a lire
|
||||||
|
//------------------------------------------------------
|
||||||
|
private int buffer,source;
|
||||||
|
private String fileName;
|
||||||
|
private String format;
|
||||||
|
//------------------------------------------------------
|
||||||
|
|
||||||
System.out.println("ALC_FREQUENCY: " + alcGetInteger(device.address(), ALC_FREQUENCY) + "Hz");
|
//Fonction global
|
||||||
System.out.println("ALC_REFRESH: " + alcGetInteger(device.address(), ALC_REFRESH) + "Hz");
|
//------------------------------------------------------
|
||||||
System.out.println("ALC_SYNC: " + (alcGetInteger(device.address(), ALC_SYNC) == ALC_TRUE));
|
public static void create(){
|
||||||
System.out.println("ALC_MONO_SOURCES: " + alcGetInteger(device.address(), ALC_MONO_SOURCES));
|
device = alcOpenDevice((ByteBuffer)null);
|
||||||
System.out.println("ALC_STEREO_SOURCES: " + alcGetInteger(device.address(), ALC_STEREO_SOURCES));
|
ALCCapabilities deviceCaps = ALC.createCapabilities(device);
|
||||||
System.out.println("---------------------------------------------------------------------------------------");
|
|
||||||
}
|
context = alcCreateContext(device, (IntBuffer)null);
|
||||||
|
alcMakeContextCurrent(context);
|
||||||
public static void destroy(){
|
createCapabilities(deviceCaps);
|
||||||
context.destroy();
|
}
|
||||||
device.destroy();
|
|
||||||
}
|
public static void destroy(){
|
||||||
//------------------------------------------------------
|
alcCloseDevice(device);
|
||||||
|
alcDestroyContext(context);
|
||||||
//Fonction de l'objet audio ou du son a lire
|
}
|
||||||
//------------------------------------------------------
|
//------------------------------------------------------
|
||||||
|
|
||||||
public Audio(String fileName) throws Exception{
|
//Fonction de l'objet audio ou du son a lire
|
||||||
this.fileName = fileName;
|
//------------------------------------------------------
|
||||||
setSound();
|
|
||||||
}
|
public Audio(String fileName) throws Exception{
|
||||||
|
this.fileName = fileName;
|
||||||
private void setSound() throws Exception{
|
setSound();
|
||||||
if(fileName.endsWith(".ogg")){
|
}
|
||||||
loadOGGFormat();
|
|
||||||
format = "OGG";
|
private void setSound() throws Exception{
|
||||||
}else if(fileName.endsWith(".wav")){
|
if(fileName.endsWith(".ogg")){
|
||||||
loadWavFormat();
|
loadOGGFormat();
|
||||||
format = "WAV";
|
format = "OGG";
|
||||||
}else{
|
}else if(fileName.endsWith(".wav")){
|
||||||
throw new Exception("Format not supported !");
|
loadWavFormat();
|
||||||
}
|
format = "WAV";
|
||||||
|
}else{
|
||||||
|
throw new Exception("Format not supported !");
|
||||||
|
}
|
||||||
alSourcei(source, AL_BUFFER, buffer);
|
alSourcei(source, AL_BUFFER, buffer);
|
||||||
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{
|
|
||||||
AudioInputStream ais = AudioSystem.getAudioInputStream(new BufferedInputStream(new FileInputStream(fileName)));
|
|
||||||
AudioFormat audioformat = ais.getFormat();
|
|
||||||
|
|
||||||
// get channels
|
public void loadWavFormat() throws Exception{
|
||||||
int channels = 0;
|
AudioInputStream ais = AudioSystem.getAudioInputStream(new BufferedInputStream(new FileInputStream(fileName)));
|
||||||
if (audioformat.getChannels() == 1) {
|
AudioFormat audioformat = ais.getFormat();
|
||||||
if (audioformat.getSampleSizeInBits() == 8) {
|
|
||||||
channels = AL10.AL_FORMAT_MONO8;
|
// get channels
|
||||||
} else if (audioformat.getSampleSizeInBits() == 16) {
|
int channels = 0;
|
||||||
channels = AL10.AL_FORMAT_MONO16;
|
if (audioformat.getChannels() == 1) {
|
||||||
} else {
|
if (audioformat.getSampleSizeInBits() == 8) {
|
||||||
assert false : "Illegal sample size";
|
channels = AL10.AL_FORMAT_MONO8;
|
||||||
}
|
} else if (audioformat.getSampleSizeInBits() == 16) {
|
||||||
} else if (audioformat.getChannels() == 2) {
|
channels = AL10.AL_FORMAT_MONO16;
|
||||||
if (audioformat.getSampleSizeInBits() == 8) {
|
} else {
|
||||||
channels = AL10.AL_FORMAT_STEREO8;
|
assert false : "Illegal sample size";
|
||||||
} else if (audioformat.getSampleSizeInBits() == 16) {
|
}
|
||||||
channels = AL10.AL_FORMAT_STEREO16;
|
} else if (audioformat.getChannels() == 2) {
|
||||||
} else {
|
if (audioformat.getSampleSizeInBits() == 8) {
|
||||||
assert false : "Illegal sample size";
|
channels = AL10.AL_FORMAT_STEREO8;
|
||||||
}
|
} else if (audioformat.getSampleSizeInBits() == 16) {
|
||||||
} else {
|
channels = AL10.AL_FORMAT_STEREO16;
|
||||||
assert false : "Only mono or stereo is supported";
|
} else {
|
||||||
}
|
assert false : "Illegal sample size";
|
||||||
|
}
|
||||||
int available = ais.available();
|
} else {
|
||||||
if(available <= 0) {
|
assert false : "Only mono or stereo is supported";
|
||||||
available = ais.getFormat().getChannels() * (int) ais.getFrameLength() * ais.getFormat().getSampleSizeInBits() / 8;
|
}
|
||||||
}
|
|
||||||
byte[] buf = new byte[ais.available()];
|
int available = ais.available();
|
||||||
int read = 0, total = 0;
|
if(available <= 0) {
|
||||||
while ((read = ais.read(buf, total, buf.length - total)) != -1
|
available = ais.getFormat().getChannels() * (int) ais.getFrameLength() * ais.getFormat().getSampleSizeInBits() / 8;
|
||||||
&& total < buf.length) {
|
}
|
||||||
total += read;
|
byte[] buf = new byte[ais.available()];
|
||||||
}
|
int read = 0, total = 0;
|
||||||
byte[] audio_bytes = buf;
|
while ((read = ais.read(buf, total, buf.length - total)) != -1
|
||||||
boolean two_bytes_data = audioformat.getSampleSizeInBits() == 16;
|
&& total < buf.length) {
|
||||||
ByteOrder order = audioformat.isBigEndian() ? ByteOrder.BIG_ENDIAN : ByteOrder.LITTLE_ENDIAN;
|
total += read;
|
||||||
ByteBuffer dest = ByteBuffer.allocateDirect(audio_bytes.length);
|
}
|
||||||
dest.order(ByteOrder.nativeOrder());
|
byte[] audio_bytes = buf;
|
||||||
ByteBuffer src = ByteBuffer.wrap(audio_bytes);
|
boolean two_bytes_data = audioformat.getSampleSizeInBits() == 16;
|
||||||
src.order(order);
|
ByteOrder order = audioformat.isBigEndian() ? ByteOrder.BIG_ENDIAN : ByteOrder.LITTLE_ENDIAN;
|
||||||
if (two_bytes_data) {
|
ByteBuffer dest = ByteBuffer.allocateDirect(audio_bytes.length);
|
||||||
ShortBuffer dest_short = dest.asShortBuffer();
|
dest.order(ByteOrder.nativeOrder());
|
||||||
ShortBuffer src_short = src.asShortBuffer();
|
ByteBuffer src = ByteBuffer.wrap(audio_bytes);
|
||||||
while (src_short.hasRemaining())
|
src.order(order);
|
||||||
dest_short.put(src_short.get());
|
if (two_bytes_data) {
|
||||||
} else {
|
ShortBuffer dest_short = dest.asShortBuffer();
|
||||||
while (src.hasRemaining())
|
ShortBuffer src_short = src.asShortBuffer();
|
||||||
dest.put(src.get());
|
while (src_short.hasRemaining())
|
||||||
}
|
dest_short.put(src_short.get());
|
||||||
dest.rewind();
|
} else {
|
||||||
|
while (src.hasRemaining())
|
||||||
this.buffer = alGenBuffers();
|
dest.put(src.get());
|
||||||
this.source = alGenSources();
|
}
|
||||||
|
dest.rewind();
|
||||||
|
|
||||||
|
this.buffer = alGenBuffers();
|
||||||
|
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(){
|
|
||||||
STBVorbisInfo info = STBVorbisInfo.malloc();
|
|
||||||
ByteBuffer buff = BufferUtils.createByteBuffer(0);
|
|
||||||
//lecture du fichier
|
|
||||||
//----------------------------------------------------------------------------------------------------------------
|
|
||||||
try {
|
|
||||||
File file = new File(fileName);
|
|
||||||
if ( file.isFile() ) {
|
|
||||||
FileInputStream fis = new FileInputStream(file);
|
|
||||||
FileChannel fc = fis.getChannel();
|
|
||||||
buff = BufferUtils.createByteBuffer((int)fc.size() + 1);
|
|
||||||
|
|
||||||
while ( fc.read(buff) != -1 ) ;
|
|
||||||
|
|
||||||
fis.close();
|
|
||||||
fc.close();
|
|
||||||
} else {
|
|
||||||
System.err.println("File not found !");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
buff.flip();
|
public void loadOGGFormat(){
|
||||||
} catch (IOException e) {
|
STBVorbisInfo info = STBVorbisInfo.malloc();
|
||||||
throw new RuntimeException(e);
|
ByteBuffer buff = BufferUtils.createByteBuffer(0);
|
||||||
}
|
//lecture du fichier
|
||||||
//----------------------------------------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------------------------------------
|
||||||
|
try {
|
||||||
|
File file = new File(fileName);
|
||||||
|
if ( file.isFile() ) {
|
||||||
|
FileInputStream fis = new FileInputStream(file);
|
||||||
|
FileChannel fc = fis.getChannel();
|
||||||
|
buff = BufferUtils.createByteBuffer((int)fc.size() + 1);
|
||||||
|
|
||||||
IntBuffer error = BufferUtils.createIntBuffer(1);
|
while ( fc.read(buff) != -1 ) ;
|
||||||
long decoder = stb_vorbis_open_memory(buff, error, null);
|
|
||||||
if ( decoder == NULL )
|
|
||||||
throw new RuntimeException("Failed to open Ogg Vorbis file. Error: " + error.get(0));
|
|
||||||
|
|
||||||
stb_vorbis_get_info(decoder, info);
|
fis.close();
|
||||||
|
fc.close();
|
||||||
|
} else {
|
||||||
|
System.err.println("File not found !");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
int channels = info.channels();
|
buff.flip();
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
//----------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
stb_vorbis_seek_start(decoder);
|
IntBuffer error = BufferUtils.createIntBuffer(1);
|
||||||
int lengthSamples = stb_vorbis_stream_length_in_samples(decoder);
|
long decoder = stb_vorbis_open_memory(buff, error, null);
|
||||||
|
if ( decoder == NULL )
|
||||||
|
throw new RuntimeException("Failed to open Ogg Vorbis file. Error: " + error.get(0));
|
||||||
|
|
||||||
ByteBuffer pcm = BufferUtils.createByteBuffer(lengthSamples * 2 * channels);
|
stb_vorbis_get_info(decoder, info);
|
||||||
|
|
||||||
stb_vorbis_get_samples_short_interleaved(decoder, channels, pcm, lengthSamples);
|
int channels = info.channels();
|
||||||
stb_vorbis_close(decoder);
|
|
||||||
|
|
||||||
buffer = alGenBuffers();
|
|
||||||
checkALError();
|
|
||||||
|
|
||||||
source = alGenSources();
|
|
||||||
checkALError();
|
|
||||||
|
|
||||||
if(channels == 1)alBufferData(buffer, AL_FORMAT_MONO16, pcm, info.sample_rate());
|
|
||||||
else alBufferData(buffer, AL_FORMAT_STEREO16, pcm, info.sample_rate());
|
|
||||||
checkALError();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void playSound(){
|
|
||||||
if(source == 0 || buffer == 0) return;
|
|
||||||
alSourcePlay(source);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getPosition(){
|
|
||||||
return alGetSourcei(source, AL_POSITION);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getDurationInSeconds(){
|
|
||||||
if(source == 0 || buffer == 0) return 0;
|
|
||||||
int size = alGetBufferi(buffer,AL_SIZE);
|
|
||||||
int bits = alGetBufferi(buffer, AL_BITS);
|
|
||||||
int channels = alGetBufferi(buffer, AL_CHANNELS);
|
|
||||||
int freq = alGetBufferi(buffer, AL_FREQUENCY);
|
|
||||||
return size/channels/(bits/8)/freq;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getStateSound(){
|
|
||||||
if(source == 0 || buffer == 0) return 0;
|
|
||||||
return alGetSourcei(source, AL_SOURCE_STATE);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isStopped(){
|
|
||||||
if(source == 0 || buffer == 0) return false;
|
|
||||||
if(alGetSourcei(source, AL_SOURCE_STATE) == STOPPED_STATE)return true;
|
|
||||||
else return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isPaused(){
|
|
||||||
if(source == 0 || buffer == 0) return false;
|
|
||||||
if(alGetSourcei(source, AL_SOURCE_STATE) == PAUSED_STATE)return true;
|
|
||||||
else return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isPlaying(){
|
|
||||||
if(source == 0 || buffer == 0) return false;
|
|
||||||
if(alGetSourcei(source, AL_SOURCE_STATE) == PLAYING_STATE)return true;
|
|
||||||
else return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isInitial(){
|
|
||||||
if(source == 0 || buffer == 0) return false;
|
|
||||||
if(alGetSourcei(source, AL_SOURCE_STATE) == INITIAL_STATE)return true;
|
|
||||||
else return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void stopSound(){
|
|
||||||
if(source == 0 || buffer == 0) return;
|
|
||||||
alSourceStop(source);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void pauseSound(){
|
stb_vorbis_seek_start(decoder);
|
||||||
if(source == 0 || buffer == 0) return;
|
int lengthSamples = stb_vorbis_stream_length_in_samples(decoder);
|
||||||
alSourcePause(source);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void rewindSound(){
|
|
||||||
if(source == 0 || buffer == 0) return;
|
|
||||||
alSourceRewind(source);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setGain(float gain){
|
|
||||||
if(source == 0 || buffer == 0) return;
|
|
||||||
if(gain > 1.0f)gain = 1.0f;
|
|
||||||
if(gain < 0.0f)gain = 0.0f;
|
|
||||||
alSourcef(source, AL_GAIN, gain);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPitch(float pitch){
|
|
||||||
if(source == 0 || buffer == 0) return;
|
|
||||||
if(pitch < 0.0f)pitch = 0.0f;
|
|
||||||
alSourcef(source, AL_PITCH, pitch);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public float getGain(){
|
|
||||||
if(source == 0 || buffer == 0) return 0;
|
|
||||||
return alGetSourcef(source, AL_GAIN);
|
|
||||||
}
|
|
||||||
|
|
||||||
public float getPitch(){
|
|
||||||
if(source == 0 || buffer == 0) return 0;
|
|
||||||
return alGetSourcef(source, AL_PITCH);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setLooping(boolean looping){
|
|
||||||
if(source == 0 || buffer == 0) return;
|
|
||||||
if(looping){
|
|
||||||
alSourcef(source, AL_LOOPING, AL_TRUE);
|
|
||||||
}else{
|
|
||||||
alSourcef(source, AL_LOOPING, AL_FALSE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void destroySound(){
|
|
||||||
alDeleteSources(source);
|
|
||||||
alDeleteBuffers(buffer);
|
|
||||||
source = 0;
|
|
||||||
buffer = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getFileName() {
|
|
||||||
return fileName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setFileName(String fileName) throws Exception {
|
ShortBuffer pcm = BufferUtils.createShortBuffer(lengthSamples * channels);
|
||||||
this.fileName = fileName;
|
|
||||||
destroySound();
|
|
||||||
setSound();
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getBuffer() {
|
stb_vorbis_get_samples_short_interleaved(decoder, channels, pcm);
|
||||||
return buffer;
|
stb_vorbis_close(decoder);
|
||||||
}
|
|
||||||
|
|
||||||
public void setBuffer(int buffer) {
|
buffer = alGenBuffers();
|
||||||
this.buffer = buffer;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getSource() {
|
source = alGenSources();
|
||||||
return source;
|
|
||||||
}
|
if(channels == 1)alBufferData(buffer, AL_FORMAT_MONO16, pcm, info.sample_rate());
|
||||||
|
else alBufferData(buffer, AL_FORMAT_STEREO16, pcm, info.sample_rate());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void playSound(){
|
||||||
|
if(source == 0 || buffer == 0) return;
|
||||||
|
alSourcePlay(source);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getPosition(){
|
||||||
|
return alGetSourcei(source, AL_POSITION);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getDurationInSeconds(){
|
||||||
|
if(source == 0 || buffer == 0) return 0;
|
||||||
|
int size = alGetBufferi(buffer,AL_SIZE);
|
||||||
|
int bits = alGetBufferi(buffer, AL_BITS);
|
||||||
|
int channels = alGetBufferi(buffer, AL_CHANNELS);
|
||||||
|
int freq = alGetBufferi(buffer, AL_FREQUENCY);
|
||||||
|
return size/channels/(bits/8)/freq;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getStateSound(){
|
||||||
|
if(source == 0 || buffer == 0) return 0;
|
||||||
|
return alGetSourcei(source, AL_SOURCE_STATE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isStopped(){
|
||||||
|
if(source == 0 || buffer == 0) return false;
|
||||||
|
if(alGetSourcei(source, AL_SOURCE_STATE) == STOPPED_STATE)return true;
|
||||||
|
else return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isPaused(){
|
||||||
|
if(source == 0 || buffer == 0) return false;
|
||||||
|
if(alGetSourcei(source, AL_SOURCE_STATE) == PAUSED_STATE)return true;
|
||||||
|
else return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isPlaying(){
|
||||||
|
if(source == 0 || buffer == 0) return false;
|
||||||
|
if(alGetSourcei(source, AL_SOURCE_STATE) == PLAYING_STATE)return true;
|
||||||
|
else return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isInitial(){
|
||||||
|
if(source == 0 || buffer == 0) return false;
|
||||||
|
if(alGetSourcei(source, AL_SOURCE_STATE) == INITIAL_STATE)return true;
|
||||||
|
else return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void stopSound(){
|
||||||
|
if(source == 0 || buffer == 0) return;
|
||||||
|
alSourceStop(source);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void pauseSound(){
|
||||||
|
if(source == 0 || buffer == 0) return;
|
||||||
|
alSourcePause(source);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void rewindSound(){
|
||||||
|
if(source == 0 || buffer == 0) return;
|
||||||
|
alSourceRewind(source);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setGain(float gain){
|
||||||
|
if(source == 0 || buffer == 0) return;
|
||||||
|
if(gain > 1.0f)gain = 1.0f;
|
||||||
|
if(gain < 0.0f)gain = 0.0f;
|
||||||
|
alSourcef(source, AL_GAIN, gain);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPitch(float pitch){
|
||||||
|
if(source == 0 || buffer == 0) return;
|
||||||
|
if(pitch < 0.0f)pitch = 0.0f;
|
||||||
|
alSourcef(source, AL_PITCH, pitch);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public float getGain(){
|
||||||
|
if(source == 0 || buffer == 0) return 0;
|
||||||
|
return alGetSourcef(source, AL_GAIN);
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getPitch(){
|
||||||
|
if(source == 0 || buffer == 0) return 0;
|
||||||
|
return alGetSourcef(source, AL_PITCH);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLooping(boolean looping){
|
||||||
|
if(source == 0 || buffer == 0) return;
|
||||||
|
if(looping){
|
||||||
|
alSourcef(source, AL_LOOPING, AL_TRUE);
|
||||||
|
}else{
|
||||||
|
alSourcef(source, AL_LOOPING, AL_FALSE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void destroySound(){
|
||||||
|
alDeleteSources(source);
|
||||||
|
alDeleteBuffers(buffer);
|
||||||
|
source = 0;
|
||||||
|
buffer = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getFileName() {
|
||||||
|
return fileName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFileName(String fileName) throws Exception {
|
||||||
|
this.fileName = fileName;
|
||||||
|
destroySound();
|
||||||
|
setSound();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getBuffer() {
|
||||||
|
return buffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBuffer(int buffer) {
|
||||||
|
this.buffer = buffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getSource() {
|
||||||
|
return source;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSource(int source) {
|
||||||
|
this.source = source;
|
||||||
|
}
|
||||||
|
//------------------------------------------------------
|
||||||
|
|
||||||
public void setSource(int source) {
|
|
||||||
this.source = source;
|
|
||||||
}
|
|
||||||
//------------------------------------------------------
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,22 +12,22 @@ 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) {
|
||||||
|
@ -47,7 +47,7 @@ public class Input{
|
||||||
}
|
}
|
||||||
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();
|
||||||
|
@ -91,63 +91,63 @@ public class Input{
|
||||||
previousDMouse = dMouse;
|
previousDMouse = dMouse;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void destroy(){
|
public static void destroy(){
|
||||||
mousePos.release();
|
mousePos.free();
|
||||||
scroll.release();
|
scroll.free();
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
@ -239,7 +239,7 @@ public class Input{
|
||||||
public static int getMouseWheelOffset() {
|
public static int getMouseWheelOffset() {
|
||||||
return MOUSE_WHEEL_OFFSET;
|
return MOUSE_WHEEL_OFFSET;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,10 +18,10 @@ public class Camera {
|
||||||
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;
|
||||||
|
@ -51,11 +51,11 @@ public class Camera {
|
||||||
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, 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));
|
||||||
|
@ -63,5 +63,5 @@ public class Camera {
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue