human-rotate

master
王宇洋 3 years ago
parent eae7bd1b84
commit 9d92217b55

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

@ -44,9 +44,11 @@ public class Human extends SceneObject {
private Boolean isWalking = false;
private long walkStartTime;
private int stopCount = 0;
private float angle;
private float angle = 0;
private float angle_target = 0;
private Boolean isJumping = false;
private float jump_height = 0f;
public Human(Point4f origin, Point4f position, Vector4f scale) {
super(origin, position, scale);
@ -54,6 +56,23 @@ public class Human extends SceneObject {
public Human(Point4f origin, Point4f position, Vector4f scale, HashMap<String, Texture> textures) {
super(origin, position, scale, textures);
new Thread(new Runnable() {
@Override
public void run() {
while (true) {
if (angle > angle_target) {
angle -= 1f;
} else if (angle < angle_target) {
angle += 1f;
}
try {
Thread.sleep(1);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}).start();
}
@ -73,16 +92,48 @@ public class Human extends SceneObject {
// System.out.println(walkStartTime);
}
if (isWalking) {
this.delta = (Engine.getTimePassed() - walkStartTime)/10000f;
this.delta = (Engine.getTimePassed() - walkStartTime) / 10000f;
}
}
public void jump(){
public void jump(int speed) {
float g = 9.8f;
if (!isJumping) {
isJumping = true;
long start_time = System.currentTimeMillis();
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
double h = 0;
long t = 0;
while (h >= 0) {
long start = System.currentTimeMillis();
long current_time = System.currentTimeMillis();
t = (current_time - start_time) / 10;
h = (speed * t - 0.5 * g * t * t) / 10000;
jump_height = (float) h;
long end = System.currentTimeMillis();
while (end - start < 16) {
try {
Thread.sleep(1);
} catch (InterruptedException e) {
e.printStackTrace();
}
end = System.currentTimeMillis();
}
}
jump_height = 0;
isJumping = false;
}
});
thread.start();
}
}
public void stop() {
if(stopCount > 5) {
if (stopCount > 5) {
isWalking = false;
this.delta = 0;
stopCount = 0;
@ -91,13 +142,13 @@ public class Human extends SceneObject {
}
public void setAngle(float angle) {
this.angle = angle;
this.angle_target = angle;
}
@Override
public void draw() {
GL11.glTranslatef(0, jump_height, 0);
Boolean GoodAnimation = true;
float theta_face = (float) (delta * 2 * Math.PI);
// float angle = -(float) (180 * (theta_face) / Math.PI);

@ -133,7 +133,7 @@ public class Scene {
tmp.z = -new_z;
// System.out.println(tmp);
move = tmp.PlusVector(move);
human.setAngle(-angle);
human.setAngle(-angle - 180);
}
if (KEY_A) {
Vector4f tmp = new Vector4f();
@ -147,9 +147,12 @@ public class Scene {
move = tmp.PlusVector(move);
human.setAngle(angle);
}
if (Keyboard.isKeyDown(Keyboard.KEY_SPACE)) {
if (Keyboard.isKeyDown(Keyboard.KEY_RETURN)) {
move = move.PlusVector(new Vector4f(0, speedY, 0, 0));
}
if (Keyboard.isKeyDown(Keyboard.KEY_SPACE)) {
human.jump(500);
}
if (Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)) {
move = move.PlusVector(new Vector4f(0, -speedY, 0, 0));
}

@ -107,7 +107,7 @@ public class Camera {
}
if (Keyboard.isKeyDown(Keyboard.KEY_SPACE)) {
if (Keyboard.isKeyDown(Keyboard.KEY_RETURN)) {
position.y -= 10f;
}
if (Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)) {

Loading…
Cancel
Save