Matrix4f scale = Matrix4f.scale(1);
Matrix4f translation = Matrix4f.translation(0,0,0);
Matrix4f rotation = Matrix4f.identity;
//Matrix4f model = translation.multiply(scale);
Quaternion zrotation = new Quaternion(-Math.PI/360, new Vector3f(0,1,2));
Quaternion rotQ = zrotation;
float ztrans = 0;
float xtrans = 0;
Vector3f camForw = Vector3f.zUnit;
Vector3f camSide = Vector3f.xUnit.scale(-1);
double value = 0;
time = System.currentTimeMillis();
int fpsMod = 0;
Light light = Light.builder()
.intensity(255/1, 255/2, 255/3)
.pos(1, 1, 1).build();
shader.setUniform("lightPos", light.pos.xyz());
shader.setUniform("lightIntensity", light.intensity);
Matrix4f view = Matrix4f.view(
new Vector3f(0, 0, -5),
camForw,
Vector3f.cross(camSide, camForw));
float camX = 0;
float camZ = 0;
Vector3f trans = new Vector3f(1, 0.5, -4);
while(true){
try{
if(Display.isCloseRequested()){
Display.destroy();
Keyboard.destroy();
//cleanup
break;
}
else{
Keyboard.poll();
//Mouse.poll();
//System.out.println("Mouse: " +Mouse.getDX());
//view = Matrix4f.product(Matrix4f.rotation(Mouse.getDX()/(1000*Math.PI), Vector3f.yUnit), view);
//view = Matrix4f.product(Matrix4f.rotation(-Mouse.getDY()/(1000*Math.PI), Vector3f.xUnit), view);
while(Keyboard.next()){
int keyNo = Keyboard.getEventKey();
char character = Keyboard.getEventCharacter();
boolean down = Keyboard.getEventKeyState();
//System.out.print("Key " + keyNo + "(" + character +") ");
float moveSpeed = 0.1f;
if(keyNo == 17 && down){
xtrans += moveSpeed;
}
if(keyNo == 30 && down){
ztrans -= moveSpeed;
}
if(keyNo == 31 && down){
xtrans -= moveSpeed;
}
if(keyNo == 32 && down){
ztrans += moveSpeed;
}
if(keyNo == 17 && !down){
xtrans -= moveSpeed;
}
if(keyNo == 30 && !down){
ztrans += moveSpeed;
}
if(keyNo == 31 && !down){
xtrans += moveSpeed;
}
if(keyNo == 32 && !down){
ztrans -= moveSpeed;
}
}
trans = Vector3f.sum(
trans,
camForw.xz().unit().scale(xtrans),
camSide.xz().unit().scale(ztrans));
// Matrix4f camRot = Quaternion.product(
// new Quaternion(Mouse.getDY()/(600*Math.PI), camSide),
// new Quaternion(-Mouse.getDX()/(600*Math.PI), Vector3f.yUnit)).normalize().rotationMatrix();
Matrix4f camRot = Quaternion.product(
new Quaternion(-Mouse.getDX()/(600*Math.PI), Vector3f.yUnit),
new Quaternion(Mouse.getDY()/(600*Math.PI), camSide)).normalize().rotationMatrix();
view = Matrix4f.product();
camForw = camRot.multiply(camForw, 1).xyz();
camSide = camRot.multiply(camSide, 1).xyz();
view = Matrix4f.view(
trans,
camForw,
Vector3f.cross(camSide, camForw));
value = value+0.01;
Renderer.clear();
// light.pos = new Vector4f(
// 1+3*(float)Math.sin(-2*value),
// 1+1*(float)Math.cos(-2*value),
// 1f,//,
// 1.0f);
light.pos = new Vector4f(trans, 1.0f);
shader.use();
shader.setUniform("lightPos", light.pos.xyz());
shader.setUniform("lightInt", light.intensity);
shader.setUniform("flip", 0);
//rotQ = rotQ.multiply(zrotation);//.normalize();
rotation = rotQ.rotationMatrix();
translation = Matrix4f.translation(0, 0, 0);
Matrix4f m = Matrix4f.product(translation, rotation, scale, dragon.normalization);
Matrix4f vp = Matrix4f.product(projection, view);
shader.setUniform("M", m);