add-new-NPCs

master
王宇洋 3 years ago
parent 2999206eb1
commit e445522266

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

@ -0,0 +1,14 @@
#version 110
uniform sampler2D DiffuseSampler;
varying vec2 texCoord;
uniform float InverseAmount;
void main(){
vec4 diffuseColor = texture2D(DiffuseSampler, texCoord);
vec4 invertColor = 1.0 - diffuseColor;
vec4 outColor = mix(diffuseColor, invertColor, InverseAmount);
gl_FragColor = vec4(outColor.rgb, 1.0);
}

@ -0,0 +1,20 @@
#version 110
attribute vec4 Position;
uniform mat4 ProjMat;
uniform vec2 InSize;
uniform vec2 OutSize;
varying vec2 texCoord;
void main(){
vec4 outPos = ProjMat * vec4(Position.xy, 0.0, 1.0);
gl_Position = vec4(outPos.xy, 0.2, 1.0);
vec2 sizeRatio = OutSize / InSize;
texCoord = Position.xy / OutSize;
texCoord.x = texCoord.x * sizeRatio.x;
texCoord.y = texCoord.y * sizeRatio.y;
texCoord.y = sizeRatio.y - texCoord.y;
}

@ -4,14 +4,15 @@ import Scene.base.SceneObject;
import base.GraphicsObjects.Point4f;
import base.GraphicsObjects.Vector4f;
import base.objects3D.DisplayListTexCube;
import main.Engine;
import org.lwjgl.opengl.GL11;
import org.newdawn.slick.Color;
import org.newdawn.slick.opengl.Texture;
import java.util.HashMap;
import static org.lwjgl.opengl.GL11.GL_NEAREST;
import static org.lwjgl.opengl.GL11.GL_TEXTURE_MIN_FILTER;
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.opengl.GL11.GL_TEXTURE_2D;
/**
* @Author: WangYuyang
@ -46,11 +47,13 @@ public class Copyleft extends SceneObject {
Color.white.bind();
//bind texture
getTextures().get("copyleft").bind();
// glBindTexture(GL_TEXTURE_2D, Engine.shadowTexture);
;
// GL11.glDisable(GL11.GL_LIGHTING); // switch lighting off
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL_NEAREST);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
cube.DrawTexCube();
// glBindTexture(GL_TEXTURE_2D, 0);
// GL11.glEnable(GL11.GL_LIGHTING); // switch lighting off
;

@ -0,0 +1,705 @@
package Scene.Objects;
import Scene.base.SceneObject;
import base.GraphicsObjects.Point4f;
import base.GraphicsObjects.Utils;
import base.GraphicsObjects.Vector4f;
import base.objects3D.DisplayListCylinder;
import base.objects3D.DisplayListOval;
import base.objects3D.DisplayListTexSphere;
import main.Engine;
import org.lwjgl.opengl.GL11;
import org.newdawn.slick.Color;
import org.newdawn.slick.opengl.Texture;
import java.util.HashMap;
import java.util.Random;
import static org.lwjgl.opengl.GL11.GL_NEAREST;
import static org.lwjgl.opengl.GL11.GL_TEXTURE_MIN_FILTER;
/**
* @Author: WangYuyang
* @Date: 2021/11/6-19:33
* @Project: Assignment3
* @Package: Scene.Objects
* @Description:
**/
public class NPC2 extends SceneObject {
public static int angle_target = 0;
public static int angle = 0;
// basic colours
static float black[] = {0.0f, 0.0f, 0.0f, 1.0f};
static float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
static float grey[] = {0.5f, 0.5f, 0.5f, 1.0f};
static float spot[] = {0.1f, 0.1f, 0.1f, 0.5f};
// primary colours
static float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
static float green[] = {0.0f, 1.0f, 0.0f, 1.0f};
static float blue[] = {0.0f, 0.0f, 1.0f, 1.0f};
// secondary colours
static float yellow[] = {1.0f, 1.0f, 0.0f, 1.0f};
static float magenta[] = {1.0f, 0.0f, 1.0f, 1.0f};
static float cyan[] = {0.0f, 1.0f, 1.0f, 1.0f};
// other colours
static float orange[] = {1.0f, 0.5f, 0.0f, 1.0f, 1.0f};
static float brown[] = {0.5f, 0.25f, 0.0f, 1.0f, 1.0f};
static float dkgreen[] = {0.0f, 0.5f, 0.0f, 1.0f, 1.0f};
static float pink[] = {1.0f, 0.6f, 0.6f, 1.0f, 1.0f};
DisplayListTexSphere s1 = new DisplayListTexSphere(0.5f, 32, 32, getTextures().get("warped_door_bottom"));
DisplayListTexSphere s2 = new DisplayListTexSphere(0.5f, 32, 32, getTextures().get("warped_door_bottom"));
DisplayListTexSphere s3 = new DisplayListTexSphere(0.25f, 32, 32, getTextures().get("default_stone"));
DisplayListTexSphere s4 = new DisplayListTexSphere(0.2f, 32, 32, getTextures().get("default_stone"));
DisplayListTexSphere s5 = new DisplayListTexSphere(0.2f, 32, 32, getTextures().get("default_stone"));
DisplayListTexSphere s6 = new DisplayListTexSphere(0.25f, 32, 32, getTextures().get("default_stone"));
DisplayListTexSphere s7 = new DisplayListTexSphere(0.2f, 32, 32, getTextures().get("default_stone"));
DisplayListTexSphere s8 = new DisplayListTexSphere(0.2f, 32, 32, getTextures().get("default_stone"));
DisplayListTexSphere s9 = new DisplayListTexSphere(0.25f, 32, 32, getTextures().get("default_cobble"));
DisplayListTexSphere s10 = new DisplayListTexSphere(0.25f, 32, 32, getTextures().get("default_cobble"));
DisplayListTexSphere s11 = new DisplayListTexSphere(0.3f, 32, 32, getTextures().get("default_cobble"));
DisplayListTexSphere s12 = new DisplayListTexSphere(0.25f, 32, 32, getTextures().get("default_cobble"));
DisplayListTexSphere s13 = new DisplayListTexSphere(0.25f, 32, 32, getTextures().get("default_cobble"));
DisplayListTexSphere s14 = new DisplayListTexSphere(0.3f, 32, 32, getTextures().get("default_cobble"));
DisplayListTexSphere s15 = new DisplayListTexSphere(0.5f, 32, 32, getTextures().get("awesomeface"));
DisplayListCylinder c1 = new DisplayListCylinder(0.15f, 0.7f, 32);
DisplayListCylinder c2 = new DisplayListCylinder(0.15f, 0.7f, 32);
DisplayListCylinder c3 = new DisplayListCylinder(0.1f, 0.7f, 32);
DisplayListCylinder c4 = new DisplayListCylinder(0.15f, 0.7f, 32);
DisplayListCylinder c5 = new DisplayListCylinder(0.1f, 0.7f, 32);
DisplayListCylinder c6 = new DisplayListCylinder(0.15f, 0.7f, 32);
DisplayListCylinder c7 = new DisplayListCylinder(0.15f, 0.7f, 32);
DisplayListCylinder c8 = new DisplayListCylinder(0.15f, 0.7f, 32);
DisplayListCylinder c9 = new DisplayListCylinder(0.15f, 0.7f, 32);
DisplayListOval shadow = new DisplayListOval(3f, 32);
Random random = new Random();
private float delta;
private Boolean isWalking = false;
private long walkStartTime;
private int stopCount = 0;
private Boolean isJumping = false;
private float jump_height = 0f;
private float timePassed = Engine.getTimePassed();
public NPC2(Point4f origin, Point4f position, Vector4f scale) {
super(origin, position, scale);
}
public NPC2(Point4f origin, Point4f position, Vector4f scale, HashMap<String, Texture> textures) {
super(origin, position, scale, textures);
}
public void walk() {
stopCount = 0;
if (isWalking == false) {
isWalking = true;
walkStartTime = Engine.getTimePassed();
// System.out.println(walkStartTime);
}
if (isWalking) {
this.delta = (Engine.getTimePassed() - walkStartTime) / 10000f;
}
}
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;
setShadowOffset(new Vector4f(
-jump_height * 90,
0,
-jump_height * 90,
0
));
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) {
isWalking = false;
this.delta = 0;
stopCount = 0;
}
stopCount++;
}
public void setAngle(float angle) {
this.angle_target = (int) angle;
}
@Override
public void draw(Integer frame_delta) {
timePassed = Engine.getTimePassed() / 10000.0f;
float speed = frame_delta / 160f;
// System.out.println(speed);
// walk();
// if((int) (timePassed % 4) == 0){
// move(new Vector4f(speed,0,0,0));
// angle_target = 90;
//
// }
// if((int) (timePassed % 4) == 1){
// move(new Vector4f(0,0,-speed,0));
// angle_target = 90 + 90;
// }
// if((int) (timePassed % 4) == 2){
// move(new Vector4f(-speed,0,0,0));
// angle_target = 90 + 90 + 90;
// }
// if((int) (timePassed % 4) == 3){
// move(new Vector4f(0,0,speed,0));
// angle_target = 90 + 90 + 90 + 90;
// }
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);
// System.out.println(angle);
//
GL11.glRotatef(angle + 180, 0, 1, 0);
float theta = (float) (delta * 2 * Math.PI) * 8;
//a variable for anim sync
float LimbRotation;
LimbRotation = (float) Math.sin(theta) * 60;
float Rotation = (float) Math.toDegrees(Math.sin(Engine.getTimePassed() / 200f) * Math.PI);
if (random.nextDouble() > 0.8) {
jump((int) (random.nextDouble() * 800));
}
// //a sphere for drawing
// Sphere sphere = new Sphere();
// //a sphere with texture
// TexSphere texSphere = new TexSphere();
// //a cylinder for drawing
// Cylinder cylinder = new Cylinder();
//Start to draw
GL11.glPushMatrix();
{
// move to pelvis
GL11.glTranslatef(0.0f, 0.5f, 0.0f);
//set up TEXTURE
GL11.glTexParameteri(
GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T,
GL11.GL_REPEAT);
//bind a color texture
Color.white.bind();
getTextures().get("warped_door_bottom").bind();
//Enable TEXTURE
//set texture Parameters
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL_NEAREST);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
s1.DrawTexSphere();
//Draw finish Disable TEXTURE
// sphere.DrawSphere(0.5f, 32, 32); // pelvis sphere
// chest
GL11.glColor3f(green[0], green[1], green[2]);
GL11.glMaterial(GL11.GL_FRONT, GL11.GL_AMBIENT_AND_DIFFUSE, Utils.ConvertForGL(green));
GL11.glPushMatrix();
{
GL11.glTranslatef(0.0f, 0.5f, 0.0f); // move to chest
GL11.glTexParameteri(
GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T,
GL11.GL_REPEAT);
Color.white.bind(); //bind color
//bind texture
getTextures().get("warped_door_bottom").bind(); //set texture
//Enable TEXTURE
;
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL_NEAREST);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
s2.DrawTexSphere();
; //disable texture
// sphere.DrawSphere(0.5f, 32, 32);// chest sphere
// GL11.glRotatef((float) (Rotation * 0.1), 0.0f, 0.0f, 1.0f);
// System.out.println((Rotation));
// GL11.glRotatef((float) (LimbRotation * 3), 1f, 1f, 0f);
// neck
GL11.glColor3f(orange[0], orange[1], orange[2]); //set color
GL11.glMaterial(GL11.GL_FRONT, GL11.GL_AMBIENT_AND_DIFFUSE, Utils.ConvertForGL(orange)); //set material render mode
GL11.glPushMatrix();
{
GL11.glTranslatef(0.0f, 0.0f, 0.0f);
GL11.glRotatef(-90.0f, 1.0f, 0.0f, 0.0f);
// GL11.glRotatef(45.0f,0.0f,1.0f,0.0f);
c1.DrawCylinder();
// head
GL11.glColor3f(red[0], red[1], red[2]);
GL11.glMaterial(GL11.GL_FRONT, GL11.GL_AMBIENT_AND_DIFFUSE, Utils.ConvertForGL(red));
GL11.glPushMatrix();
{
GL11.glTranslatef(0.0f, 0.0f, 1.0f);
GL11.glTexParameteri(
GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T,
GL11.GL_REPEAT);
Color.white.bind();
getTextures().get("awesomeface").bind(); //set texture
;
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
GL11.glRotatef((float) (Rotation * 0.1), 0.0f, 0.0f, 0.0f);
s15.DrawTexSphere();
;
// sphere.DrawSphere(0.5f, 32, 32);
GL11.glPopMatrix();
}
GL11.glPopMatrix();
// left shoulder
GL11.glColor3f(blue[0], blue[1], blue[2]);
GL11.glMaterial(GL11.GL_FRONT, GL11.GL_AMBIENT_AND_DIFFUSE, Utils.ConvertForGL(blue));
GL11.glPushMatrix();
{
GL11.glRotatef((float) (LimbRotation * 0.5), 0f, 1f, 0f);
GL11.glTranslatef(0.5f, 0.4f, 0.0f);
//set texture Parameter
GL11.glTexParameteri(
GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T,
GL11.GL_REPEAT);
Color.white.bind();
getTextures().get("default_stone").bind(); //set texture
;
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
s3.DrawTexSphere();
// sphere.DrawSphere(0.25f, 32, 32);
// left arm
GL11.glColor3f(orange[0], orange[1], orange[2]);
GL11.glMaterial(GL11.GL_FRONT, GL11.GL_AMBIENT_AND_DIFFUSE, Utils.ConvertForGL(orange));
GL11.glPushMatrix();
{
GL11.glTranslatef(0.0f, 0.0f, 0.0f);
GL11.glRotatef(20, 0f, 0f, 1f);
GL11.glRotatef(90.0f, 1.0f, 0.0f, 0.0f);
GL11.glRotatef((float) (-Rotation * 0.2), 1.0f, 0.0f, 0.0f);
// GL11.glRotatef(27.5f,0.0f,1.0f,0.0f);
c2.DrawCylinder();
// left elbow
GL11.glColor3f(blue[0], blue[1], blue[2]);
GL11.glMaterial(GL11.GL_FRONT, GL11.GL_AMBIENT_AND_DIFFUSE, Utils.ConvertForGL(blue));
GL11.glPushMatrix();
{
GL11.glRotatef((float) (LimbRotation * -0.5), 0f, 0f, 1f);
GL11.glTranslatef(0.0f, 0.0f, 0.75f);
GL11.glTexParameteri(
GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T,
GL11.GL_REPEAT);
Color.white.bind();
getTextures().get("default_stone").bind();
;
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
s4.DrawTexSphere();
;
// sphere.DrawSphere(0.2f, 32, 32);
//left forearm
GL11.glColor3f(orange[0], orange[1], orange[2]);
GL11.glMaterial(GL11.GL_FRONT, GL11.GL_AMBIENT_AND_DIFFUSE, Utils.ConvertForGL(orange));
GL11.glPushMatrix();
{
GL11.glTranslatef(0.0f, 0.0f, 0.0f);
GL11.glRotatef(90.0f, 1.0f, 0.0f, 0.0f);
// GL11.glRotatef(90.0f,0.0f,1.0f,0.0f);
GL11.glRotatef((float) (Rotation * 0.2), 0.0f, 1.0f, 0.0f);
c3.DrawCylinder();
// left hand
GL11.glColor3f(blue[0], blue[1], blue[2]);
GL11.glMaterial(GL11.GL_FRONT, GL11.GL_AMBIENT_AND_DIFFUSE, Utils.ConvertForGL(blue));
GL11.glPushMatrix();
{
GL11.glTranslatef(0.0f, 0.0f, 0.75f);
GL11.glTexParameteri(
GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T,
GL11.GL_REPEAT);
Color.white.bind();
getTextures().get("default_stone").bind();
;
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
s5.DrawTexSphere();
;
// sphere.DrawSphere(0.2f, 32, 32);
}
GL11.glPopMatrix();
}
GL11.glPopMatrix();
}
GL11.glPopMatrix();
}
GL11.glPopMatrix();
}
GL11.glPopMatrix();
// to chest
GL11.glColor3f(blue[0], blue[1], blue[2]);
GL11.glMaterial(GL11.GL_FRONT, GL11.GL_AMBIENT_AND_DIFFUSE, Utils.ConvertForGL(blue));
GL11.glPushMatrix();
{
GL11.glRotatef((float) (LimbRotation * 0.5), 0f, 1f, 0f);
GL11.glTranslatef(-0.5f, 0.4f, 0.0f); // move to right arm
GL11.glTexParameteri(
GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T,
GL11.GL_REPEAT);
Color.white.bind();
getTextures().get("default_stone").bind();
;
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
s6.DrawTexSphere();
;
// sphere.DrawSphere(0.25f, 32, 32);
// right arm
GL11.glColor3f(orange[0], orange[1], orange[2]);
GL11.glMaterial(GL11.GL_FRONT, GL11.GL_AMBIENT_AND_DIFFUSE, Utils.ConvertForGL(orange));
GL11.glPushMatrix();
{
GL11.glRotatef(-20, 0f, 0f, 1f);
GL11.glTranslatef(0.0f, 0.0f, 0.0f);
GL11.glRotatef(90.0f, 1.0f, 0.0f, 0.0f);
GL11.glRotatef(-LimbRotation, 1.0f, 0.0f, 0.0f);
// GL11.glRotatef(27.5f,0.0f,1.0f,0.0f);
c4.DrawCylinder();
// right elbow
GL11.glColor3f(blue[0], blue[1], blue[2]);
GL11.glMaterial(GL11.GL_FRONT, GL11.GL_AMBIENT_AND_DIFFUSE, Utils.ConvertForGL(blue));
GL11.glPushMatrix();
{
GL11.glRotatef((float) (LimbRotation * -0.5), 0f, 0f, 1f);
GL11.glTranslatef(0.0f, 0.0f, 0.75f);
GL11.glRotatef((float) (-Rotation * 0.2), 1.0f, 0.0f, 0.0f);
GL11.glTexParameteri(
GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T,
GL11.GL_REPEAT);
Color.white.bind();
getTextures().get("default_stone").bind();
;
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
s7.DrawTexSphere();
;
// sphere.DrawSphere(0.2f, 32, 32);
//right forearm
GL11.glColor3f(orange[0], orange[1], orange[2]);
GL11.glMaterial(GL11.GL_FRONT, GL11.GL_AMBIENT_AND_DIFFUSE, Utils.ConvertForGL(orange));
GL11.glPushMatrix();
{
GL11.glTranslatef(0.0f, 0.0f, 0.0f);
GL11.glRotatef(90.0f, 1.0f, 0.0f, 0.0f);
// GL11.glRotatef(90.0f,0.0f,1.0f,0.0f);
GL11.glRotatef((float) (-Rotation * 0.2), 0.0f, 1.0f, 0.0f);
c5.DrawCylinder();
// right hand
GL11.glColor3f(blue[0], blue[1], blue[2]);
GL11.glMaterial(GL11.GL_FRONT, GL11.GL_AMBIENT_AND_DIFFUSE, Utils.ConvertForGL(blue));
GL11.glPushMatrix();
{
GL11.glTranslatef(0.0f, 0.0f, 0.75f);
GL11.glTexParameteri(
GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T,
GL11.GL_REPEAT);
Color.white.bind();
getTextures().get("default_stone").bind();
;
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
s8.DrawTexSphere();
;
// sphere.DrawSphere(0.2f, 32, 32);
}
GL11.glPopMatrix();
}
GL11.glPopMatrix();
}
GL11.glPopMatrix();
}
GL11.glPopMatrix();
}
GL11.glPopMatrix();
//now chest
}
GL11.glPopMatrix();
// GL11.glRotatef(LimbRotation * 3, 0.0f, 1.0f, 0.0f);
// GL11.glRotatef((float) (LimbRotation * -0.2), 0.0f, 1.0f, 0.0f);
// GL11.glPushMatrix();
// GL11.glTranslatef(0,-1.8f,0);
// glDisable(GL_LIGHTING);
// glDisable(GL_TEXTURE_2D);
// Color.black.bind();
// shadow.DrawOval();
// Color.white.bind();
// glEnable(GL_TEXTURE_2D);
// glEnable(GL_LIGHTING);
// GL11.glPopMatrix();
// pelvis
// left hip
GL11.glColor3f(blue[0], blue[1], blue[2]);
GL11.glMaterial(GL11.GL_FRONT, GL11.GL_AMBIENT_AND_DIFFUSE, Utils.ConvertForGL(blue));
GL11.glPushMatrix();
{
GL11.glTranslatef(0.5f, -0.2f, 0.0f);
GL11.glTexParameteri(
GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T,
GL11.GL_REPEAT);
Color.white.bind();
getTextures().get("default_cobble").bind();
;
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
s9.DrawTexSphere();
;
// sphere.DrawSphere(0.25f, 32, 32);
// left high leg
GL11.glColor3f(orange[0], orange[1], orange[2]);
GL11.glMaterial(GL11.GL_FRONT, GL11.GL_AMBIENT_AND_DIFFUSE, Utils.ConvertForGL(orange));
GL11.glPushMatrix();
{
GL11.glTranslatef(0.0f, 0.0f, 0.0f);
GL11.glRotatef(0.0f, 0.0f, 0.0f, 0.0f);
GL11.glRotatef((-LimbRotation / 2) + 90, 1.0f, 0.0f, 0.0f);
// GL11.glRotatef(90.0f,1.0f,0.0f,0.0f);
c6.DrawCylinder();
// left knee
GL11.glColor3f(blue[0], blue[1], blue[2]);
GL11.glMaterial(GL11.GL_FRONT, GL11.GL_AMBIENT_AND_DIFFUSE, Utils.ConvertForGL(blue));
GL11.glPushMatrix();
{
GL11.glTranslatef(0.0f, 0.0f, 0.75f);
GL11.glRotatef(0.0f, 0.0f, 0.0f, 0.0f);
GL11.glTexParameteri(
GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T,
GL11.GL_REPEAT);
Color.white.bind();
getTextures().get("default_cobble").bind();
;
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
s10.DrawTexSphere();
;
// sphere.DrawSphere(0.25f, 32, 32);
//left low leg
GL11.glColor3f(orange[0], orange[1], orange[2]);
GL11.glMaterial(GL11.GL_FRONT, GL11.GL_AMBIENT_AND_DIFFUSE, Utils.ConvertForGL(orange));
GL11.glPushMatrix();
{
GL11.glTranslatef(0.0f, 0.0f, 0.0f);
// GL11.glRotatef(120.0f,1.0f,0.0f,0.0f);
// GL11.glRotatef(0.0f,0.0f,0.0f,0.0f);
c7.DrawCylinder();
// left foot
GL11.glColor3f(blue[0], blue[1], blue[2]);
GL11.glMaterial(GL11.GL_FRONT, GL11.GL_AMBIENT_AND_DIFFUSE, Utils.ConvertForGL(blue));
GL11.glPushMatrix();
{
GL11.glTranslatef(0.0f, 0.0f, 0.75f);
GL11.glTexParameteri(
GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T,
GL11.GL_REPEAT);
Color.white.bind();
getTextures().get("default_cobble").bind();
;
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
s11.DrawTexSphere();
;
// sphere.DrawSphere(0.3f, 32, 32);
}
GL11.glPopMatrix();
}
GL11.glPopMatrix();
}
GL11.glPopMatrix();
}
GL11.glPopMatrix();
}
GL11.glPopMatrix();
// pelvis
// right hip
GL11.glColor3f(blue[0], blue[1], blue[2]);
GL11.glMaterial(GL11.GL_FRONT, GL11.GL_AMBIENT_AND_DIFFUSE, Utils.ConvertForGL(blue));
GL11.glPushMatrix();
{
GL11.glTranslatef(-0.5f, -0.2f, 0.0f);
GL11.glTexParameteri(
GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T,
GL11.GL_REPEAT);
Color.white.bind();
getTextures().get("default_cobble").bind();
;
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
s12.DrawTexSphere();
;
// sphere.DrawSphere(0.25f, 32, 32);
// right high leg
GL11.glColor3f(orange[0], orange[1], orange[2]);
GL11.glMaterial(GL11.GL_FRONT, GL11.GL_AMBIENT_AND_DIFFUSE, Utils.ConvertForGL(orange));
GL11.glPushMatrix();
{
GL11.glTranslatef(0.0f, 0.0f, 0.0f);
GL11.glRotatef(0.0f, 0.0f, 0.0f, 0.0f);
GL11.glRotatef((LimbRotation / 2) + 90, 1.0f, 0.0f, 0.0f);
// GL11.glRotatef(90.0f,1.0f,0.0f,0.0f);
c8.DrawCylinder();
// right knee
GL11.glColor3f(blue[0], blue[1], blue[2]);
GL11.glMaterial(GL11.GL_FRONT, GL11.GL_AMBIENT_AND_DIFFUSE, Utils.ConvertForGL(blue));
GL11.glPushMatrix();
{
GL11.glTranslatef(0.0f, 0.0f, 0.75f);
GL11.glRotatef(0.0f, 0.0f, 0.0f, 0.0f);
GL11.glTexParameteri(
GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T,
GL11.GL_REPEAT);
Color.white.bind();
getTextures().get("default_cobble").bind();
;
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
s13.DrawTexSphere();
;
// sphere.DrawSphere(0.25f, 32, 32);
//right low leg
GL11.glColor3f(orange[0], orange[1], orange[2]);
GL11.glMaterial(GL11.GL_FRONT, GL11.GL_AMBIENT_AND_DIFFUSE, Utils.ConvertForGL(orange));
GL11.glPushMatrix();
{
GL11.glTranslatef(0.0f, 0.0f, 0.0f);
// GL11.glRotatef(120.0f,1.0f,0.0f,0.0f);
// GL11.glRotatef(0.0f,0.0f,0.0f,0.0f);
c9.DrawCylinder();
// left foot
GL11.glColor3f(blue[0], blue[1], blue[2]);
GL11.glMaterial(GL11.GL_FRONT, GL11.GL_AMBIENT_AND_DIFFUSE, Utils.ConvertForGL(blue));
GL11.glPushMatrix();
{
GL11.glTranslatef(0.0f, 0.0f, 0.75f);
GL11.glTexParameteri(
GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T,
GL11.GL_REPEAT);
Color.white.bind();
getTextures().get("default_cobble").bind();
;
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
s14.DrawTexSphere();
;
// sphere.DrawSphere(0.3f, 32, 32);
}
GL11.glPopMatrix();
}
GL11.glPopMatrix();
}
GL11.glPopMatrix();
}
GL11.glPopMatrix();
}
GL11.glPopMatrix();
}
GL11.glPopMatrix();
}
}
}

@ -145,6 +145,12 @@ public class Player extends SceneObject {
t = (current_time - start_time) / 10;
h = (speed * t - 0.5 * g * t * t) / 10000;
jump_height = (float) h;
setShadowOffset(new Vector4f(
-jump_height * 90,
0,
-jump_height * 90,
0
));
long end = System.currentTimeMillis();
while (end - start < 16) {
try {

@ -329,6 +329,55 @@ public class Scene {
textures
));
sceneManager.addSceneObject(new BookTable(
new Point4f(1000, 90f, -500, 0),
new Point4f(0, 0, 0, 0),
new Vector4f(90f, 90f, 90f, 0),
new Vector4f(0,0,0, 0),
textures
));
sceneManager.addSceneObject(new Book(
new Point4f(1000, 250f, -500, 0),
new Point4f(0, 0, 0, 0),
new Vector4f(90f, 90f, 90f, 0),
new Vector4f(0,1,0, 90),
textures
));
sceneManager.addSceneObject(new BookShelf(
new Point4f(1000, 90f, -500, 0),
new Point4f(0, 0, 0, 0),
new Vector4f(90f, 90f, 90f, 0),
new Vector4f(0,1,0, 90),
textures
));
sceneManager.addSceneObject(new BookTable(
new Point4f(-1000, 90f, -500, 0),
new Point4f(0, 0, 0, 0),
new Vector4f(90f, 90f, 90f, 0),
new Vector4f(0,0,0, 0),
textures
));
sceneManager.addSceneObject(new Book(
new Point4f(-1000, 250f, -500, 0),
new Point4f(0, 0, 0, 0),
new Vector4f(90f, 90f, 90f, 0),
new Vector4f(0,1,0, -90),
textures
));
sceneManager.addSceneObject(new BookShelf(
new Point4f(-1000, 90f, -500, 0),
new Point4f(0, 0, 0, 0),
new Vector4f(90f, 90f, 90f, 0),
new Vector4f(0,1,0, -90),
textures
));
for (int i = -9; i < 10; i++) {
sceneManager.addSceneObject(new BookTable(
new Point4f(500 * i, 90f, 4500, 0),
@ -421,6 +470,51 @@ public class Scene {
textures
));
// sceneManager.addSceneObject(new NPC(
// new Point4f(-2700, 130, 2500, 0),
// new Point4f(0, 0, 0, 0),
// new Vector4f(90, 90, 90, 0),
// textures
// ));
sceneManager.addSceneObject(new NPC2(
new Point4f(400, 130, -2000, 0),
new Point4f(0, 0, 0, 0),
new Vector4f(90, 90, 90, 0),
textures
));
sceneManager.addSceneObject(new NPC2(
new Point4f(800, 130, -2000, 0),
new Point4f(0, 0, 0, 0),
new Vector4f(90, 90, 90, 0),
textures
));
sceneManager.addSceneObject(new NPC2(
new Point4f(1200, 130, -2000, 0),
new Point4f(0, 0, 0, 0),
new Vector4f(90, 90, 90, 0),
textures
));
sceneManager.addSceneObject(new NPC2(
new Point4f(-400, 130, -2000, 0),
new Point4f(0, 0, 0, 0),
new Vector4f(90, 90, 90, 0),
textures
));
sceneManager.addSceneObject(new NPC2(
new Point4f(-800, 130, -2000, 0),
new Point4f(0, 0, 0, 0),
new Vector4f(90, 90, 90, 0),
textures
));
sceneManager.addSceneObject(new NPC2(
new Point4f(-1200, 130, -2000, 0),
new Point4f(0, 0, 0, 0),
new Vector4f(90, 90, 90, 0),
textures
));
new Thread(new Runnable() {
@Override
public void run() {

@ -28,6 +28,7 @@ public abstract class SceneObject implements IDrawable, IMovable, IScalable, IHi
private Vector4f rotation = new Vector4f();
private HashMap<String, Texture> textures = new LinkedHashMap<>();
private DisplayListOval shadow;
private Vector4f shadowOffset = new Vector4f();
public SceneObject(Point4f origin, Point4f position, Vector4f scale) {
this.origin = new Point4f(origin.x, origin.y, origin.z, 0);
@ -130,7 +131,7 @@ public abstract class SceneObject implements IDrawable, IMovable, IScalable, IHi
GL11.glTranslatef(position.x, position.y, position.z);
GL11.glScalef(1 / scale.x, 1 / scale.y, 1 / scale.z);
GL11.glTranslatef(0, -origin.y, 0);
GL11.glTranslatef(-140f, 2f, -140f);
GL11.glTranslatef(-140f + shadowOffset.x, 2f + shadowOffset.y, -140f + shadowOffset.z);
GL11.glRotatef(-45, 0,1,0);
GL11.glScalef(2f, 0f, 1f);
@ -203,4 +204,12 @@ public abstract class SceneObject implements IDrawable, IMovable, IScalable, IHi
public Vector4f getRotation() {
return rotation;
}
public Vector4f getShadowOffset() {
return shadowOffset;
}
public void setShadowOffset(Vector4f shadowOffset) {
this.shadowOffset = shadowOffset;
}
}

@ -42,15 +42,6 @@ import static org.lwjgl.opengl.GL15.*;
public class OBJLoader {
private static FloatBuffer reserveData(int size) {
return BufferUtils.createFloatBuffer(size);
}
private static float[] asFloats(Vector3f v) {
return new float[]{v.x, v.y, v.z};
}
private static Vector3f parseVertex(String line) {
String[] xyz = line.split(" ");
float x = Float.valueOf(xyz[1]);

@ -12,6 +12,7 @@ import org.lwjgl.LWJGLException;
import org.lwjgl.Sys;
import org.lwjgl.opengl.*;
import org.lwjgl.util.vector.Matrix4f;
import org.lwjgl.util.vector.Vector3f;
import org.newdawn.slick.Color;
import org.newdawn.slick.opengl.Texture;
@ -22,11 +23,14 @@ import java.util.LinkedHashMap;
import static main.Main.camera;
import static main.ShaderLoader.loadShaders;
import static org.lwjgl.opengl.ARBFramebufferObject.*;
import static org.lwjgl.opengl.ARBFramebufferObject.GL_FRAMEBUFFER;
import static org.lwjgl.opengl.ARBShadowAmbient.GL_TEXTURE_COMPARE_FAIL_VALUE_ARB;
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.opengl.GL12.GL_CLAMP_TO_EDGE;
import static org.lwjgl.opengl.GL14.GL_DEPTH_TEXTURE_MODE;
import static org.lwjgl.util.glu.GLU.gluPerspective;
import static org.lwjgl.opengl.GL14.*;
import static org.lwjgl.opengl.GL14.GL_COMPARE_R_TO_TEXTURE;
import static org.lwjgl.util.glu.GLU.*;
/**
* @Author: WangYuyang
@ -150,7 +154,7 @@ public class Engine {
glEnable(GL13.GL_MULTISAMPLE);
// Display.setResizable(true);
glClear(GL_COLOR_BUFFER_BIT);
shadowTexture = glGenTextures();
GL11.glMatrixMode(GL_PROJECTION);
GL11.glLoadIdentity();
@ -246,6 +250,8 @@ public class Engine {
spec.rewind();
direction.put(new float[]{0f, 0f, -1f, 0});
direction.rewind();
// setUpFrameBufferObject();
}
public void enterModelView() {
@ -303,7 +309,219 @@ public class Engine {
Display.destroy();
System.exit(0);
}
// /**
// * Sets up the OpenGL states.
// */
// private static void setUpFrameBufferObject() {
// final int MAX_RENDERBUFFER_SIZE = glGetInteger(GL_MAX_RENDERBUFFER_SIZE);
// final int MAX_TEXTURE_SIZE = glGetInteger(GL_MAX_TEXTURE_SIZE);
// /**
// * Cap the maximum shadow map size at 1024x1024 pixels or at the maximum render buffer size. If you have a good
// * graphics card, feel free to increase this value. The program will lag
// * if I record and run the program at the same time with higher values.
// */
// if (MAX_TEXTURE_SIZE > 1024) {
// if (MAX_RENDERBUFFER_SIZE < MAX_TEXTURE_SIZE) {
// shadowMapWidth = shadowMapHeight = MAX_RENDERBUFFER_SIZE;
// } else {
// shadowMapWidth = shadowMapHeight = 1024;
// }
// } else {
// shadowMapWidth = shadowMapHeight = MAX_TEXTURE_SIZE;
// }
// // Generate and bind a frame buffer.
// frameBuffer = glGenFramebuffers();
// glBindFramebuffer(GL_FRAMEBUFFER, frameBuffer);
// // Generate and bind a render buffer.
// renderBuffer = glGenRenderbuffers();
// glBindRenderbuffer(GL_RENDERBUFFER, renderBuffer);
// // Set the internal storage format of the render buffer to a depth component of 32 bits (4 bytes).
// glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT32, shadowMapWidth, shadowMapHeight);
// // Attach the render buffer to the frame buffer as a depth attachment. This means that, if the frame buffer is
// // bound, any depth texture values will be copied to the render buffer object.
// glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, renderBuffer);
// // OpenGL shall make no amendment to the colour or multisample buffer.
// glDrawBuffer(GL_NONE);
// // Disable the colour buffer for pixel read operations (such as glReadPixels or glCopyTexImage2D).
// glReadBuffer(GL_NONE);
// // Check for frame buffer errors.
// int FBOStatus = glCheckFramebufferStatus(GL_FRAMEBUFFER);
// if (FBOStatus != GL_FRAMEBUFFER_COMPLETE) {
// System.err.println("Framebuffer error: " + gluErrorString(glGetError()));
// }
// // Bind the default frame buffer, which is used for ordinary drawing.
// glBindFramebuffer(GL_FRAMEBUFFER, 0);
// }
//
// private static void generateTextureCoordinates() {
// glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
// // Compare the texture coordinate 'r' (the distance from the light to the surface of the object) to the
// // value in the depth buffer.
// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE);
// // Enable 's' texture coordinate generation.
// glEnable(GL_TEXTURE_GEN_S);
//// // Enable 't' texture coordinate generation.
// glEnable(GL_TEXTURE_GEN_T);
//// // Enable 'r' texture coordinate generation.
// glEnable(GL_TEXTURE_GEN_R);
//// // Enable 'q' texture coordinate generation.
// glEnable(GL_TEXTURE_GEN_Q);
// textureBuffer.clear();
// textureBuffer.put(0, depthModelViewProjection.m00);
// textureBuffer.put(1, depthModelViewProjection.m01);
// textureBuffer.put(2, depthModelViewProjection.m02);
// textureBuffer.put(3, depthModelViewProjection.m03);
//
// glTexGen(GL_S, GL_EYE_PLANE, textureBuffer);
//
// textureBuffer.put(0, depthModelViewProjection.m10);
// textureBuffer.put(1, depthModelViewProjection.m11);
// textureBuffer.put(2, depthModelViewProjection.m12);
// textureBuffer.put(3, depthModelViewProjection.m13);
//
// glTexGen(GL_T, GL_EYE_PLANE, textureBuffer);
//
// textureBuffer.put(0, depthModelViewProjection.m20);
// textureBuffer.put(1, depthModelViewProjection.m21);
// textureBuffer.put(2, depthModelViewProjection.m22);
// textureBuffer.put(3, depthModelViewProjection.m23);
//
// glTexGen(GL_R, GL_EYE_PLANE, textureBuffer);
//
// textureBuffer.put(0, depthModelViewProjection.m30);
// textureBuffer.put(1, depthModelViewProjection.m31);
// textureBuffer.put(2, depthModelViewProjection.m32);
// textureBuffer.put(3, depthModelViewProjection.m33);
//
// glTexGen(GL_Q, GL_EYE_PLANE, textureBuffer);
// }
//
// /**
// * Generate the shadow map.
// *
// * @param renderProgram
// */
// private static void drawShadowMap(RenderProgramStatement renderProgram) {
// /**
// * The model-view matrix of the light.
// */
// FloatBuffer lightModelView = BufferUtils.createFloatBuffer(16);
// /**
// * The projection matrix of the light.
// */
// FloatBuffer lightProjection = BufferUtils.createFloatBuffer(16);
// Matrix4f lightProjectionTemp = new Matrix4f();
// Matrix4f lightModelViewTemp = new Matrix4f();
// /**
// * The radius that encompasses all the objects that cast shadows in the scene. There should
// * be no object farther away than 50 units from [0, 0, 0] in any direction.
// * If an object exceeds the radius, the object may cast shadows wrongly.
// */
// float sceneBoundingRadius = 1500;
// /**
// * The distance from the light to the scene, assuming that the scene is located
// * at [0, 0, 0]. Using the Pythagorean theorem, the distance is calculated by taking the square-root of the
// * sum of each of the components of the light position squared.
// */
// float lightToSceneDistance = (float) Math.sqrt(lightPosition.get(0) * lightPosition.get(0) +
// lightPosition.get(1) * lightPosition.get(1) +
// lightPosition.get(2) * lightPosition.get(2));
//
// /**
// * The distance to the object that is nearest to the camera. This excludes objects that do not cast shadows.
// * This will be used as the zNear parameter in gluPerspective.
// */
// float nearPlane = lightToSceneDistance - sceneBoundingRadius;
// if (nearPlane < 0) {
// System.err.println("Camera is too close to scene. A valid shadow map cannot be generated.");
// }
// /**
// * The field-of-view of the shadow frustum in degrees. Formula taken from the OpenGL SuperBible.
// */
// float fieldOfView = (float) Math.toDegrees(2.0F * Math.atan(sceneBoundingRadius / lightToSceneDistance));
// glMatrixMode(GL_PROJECTION);
// // Store the current projection matrix.
// glPushMatrix();
// glLoadIdentity();
// // Generate the 'shadow frustum', a perspective projection matrix that shows all the objects in the scene.
// gluPerspective(fieldOfView, 1, nearPlane, nearPlane + sceneBoundingRadius * 2);
// // Store the shadow frustum in 'lightProjection'.
// glGetFloat(GL_PROJECTION_MATRIX, lightProjection);
// glMatrixMode(GL_MODELVIEW);
// // Store the current model-view matrix.
// glPushMatrix();
// glLoadIdentity();
// // Have the 'shadow camera' look toward [0, 0, 0] and be location at the light's position.
// gluLookAt(lightPosition.get(0), lightPosition.get(1), lightPosition.get(2), 0, 0, 0, 0, 1, 0);
// glGetFloat(GL_MODELVIEW_MATRIX, lightModelView);
// // Set the view port to the shadow map dimensions so no part of the shadow is cut off.
// glViewport(0, 0, shadowMapWidth, shadowMapHeight);
// // Bind the extra frame buffer in which to store the shadow map in the form a depth texture.
// glBindFramebuffer(GL_FRAMEBUFFER, frameBuffer);
// // Clear only the depth buffer bit. Clearing the colour buffer is unnecessary, because it is disabled (we
// // only need depth components).
// glClear(GL_DEPTH_BUFFER_BIT);
// // Store the current attribute state.
// glPushAttrib(GL_ALL_ATTRIB_BITS);
// {
// // Disable smooth shading, because the shading in a shadow map is irrelevant. It only matters where the
// // shape
// // vertices are positioned, and not what colour they have.
// glShadeModel(GL_FLAT);
// // Enabling all these lighting states is unnecessary for reasons listed above.
// glDisable(GL_LIGHTING);
// glDisable(GL_COLOR_MATERIAL);
// glDisable(GL_NORMALIZE);
// // Disable the writing of the red, green, blue, and alpha colour components,
// // because we only need the depth component.
// glColorMask(false, false, false, false);
// // An offset is given to every depth value of every polygon fragment to prevent a visual quirk called
// // 'shadow
// // acne'.
// glEnable(GL_POLYGON_OFFSET_FILL);
// // Draw the objects that cast shadows.
// renderProgram.renderScene(16);
//
// /**
// * Copy the pixels of the shadow map to the frame buffer object depth attachment.
// * int target -> GL_TEXTURE_2D
// * int level -> 0, has to do with mip-mapping, which is not applicable to shadow maps
// * int internalformat -> GL_DEPTH_COMPONENT
// * int x, y -> 0, 0
// * int width, height -> shadowMapWidth, shadowMapHeight
// * int border -> 0
// */
//// shadowTexture = glGenTextures();
//// glBindTexture(GL_TEXTURE_2D, shadowTexture);
// glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, 0, 0, shadowMapWidth, shadowMapHeight, 0);
//// glBindTexture(GL_TEXTURE_2D, 0);
//
//
// // Restore the previous model-view matrix.
// glPopMatrix();
// glMatrixMode(GL_PROJECTION);
// // Restore the previous projection matrix.
// glPopMatrix();
// glMatrixMode(GL_MODELVIEW);
// glBindFramebuffer(GL_FRAMEBUFFER, 0);
// }// Restore the previous attribute state.
// glPopAttrib();
// // Restore the view port.
// glViewport(0, 0, Display.getWidth(), Display.getHeight());
// lightProjectionTemp.load(lightProjection);
// lightModelViewTemp.load(lightModelView);
// lightProjection.flip();
// lightModelView.flip();
// depthModelViewProjection.setIdentity();
// // [-1,1] -> [-0.5,0.5] -> [0,1]
// depthModelViewProjection.translate(new Vector3f(0.5F, 0.5F, 0.5F));
// depthModelViewProjection.scale(new Vector3f(0.5F, 0.5F, 0.5F));
// // Multiply the texture matrix by the projection and model-view matrices of the light.
// Matrix4f.mul(depthModelViewProjection, lightProjectionTemp, depthModelViewProjection);
// Matrix4f.mul(depthModelViewProjection, lightModelViewTemp, depthModelViewProjection);
// // Transpose the texture matrix.
// Matrix4f.transpose(depthModelViewProjection, depthModelViewProjection);
// }
public void render(RenderProgramStatement renderProgram) {
glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
GL11.glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
@ -320,7 +538,6 @@ public class Engine {
// glPushAttrib(GL_ALL_ATTRIB_BITS);
// {
// generateTextureCoordinates();
//
// drawShadowMap(renderProgram);
//
//
@ -357,9 +574,8 @@ public class Engine {
GL11.glLoadIdentity();
//Placing 0,0 at the center of the screen
// GL11.glOrtho(1200 / 2 - OrthoNumber, OrthoNumber / 2, (800 / 2 - (OrthoNumber * 0.66f)), (OrthoNumber / 2 * 0.66f), 100000, -100000);
// GL11.glOrtho(1200 - OrthoNumber, OrthoNumber, (800 - (OrthoNumber * 0.66f)), (OrthoNumber * 0.66f), 100000, -100000);F
// GL11.glOrtho(1200 - OrthoNumber, OrthoNumber, (800 - (OrthoNumber * 0.66f)), (OrthoNumber * 0.66f), 100000, -100000);
gluPerspective((float) 60, Display.getWidth() / Display.getHeight(), zNear, zFar);
// GL11.glOrtho(-600 - OrthoNumber, 600 + OrthoNumber, -100 - OrthoNumber * 0.66, 700 + OrthoNumber * 0.66, 100000, -100000);
enterModelView();
// }

@ -15,6 +15,7 @@ import java.util.ArrayList;
import static org.lwjgl.opengl.GL11.glLoadIdentity;
import static org.lwjgl.opengl.GL11.glPointSize;
import static org.lwjgl.opengl.GL20.glUseProgram;
/**
* @Author: WangYuyang
@ -91,18 +92,18 @@ public class Main {
key_positions.add(new Vector4f(-3000, 100, 5000, 2000));
key_rotations.add(new Vector4f(0, -180, 0, 2000));
key_positions.add(new Vector4f(0, 7000, 0, 2000));
key_rotations.add(new Vector4f(90, 0, 0, 2000));
key_positions.add(new Vector4f(0, 7000, 0, 2000));
key_rotations.add(new Vector4f(90, 180, 0, 2000));
key_positions.add(new Vector4f(0, 7000, 0, 1000));
key_rotations.add(new Vector4f(90, 180, 45, 1000));
key_positions.add(new Vector4f(0, 7000, 0, 1000));
key_rotations.add(new Vector4f(90, 180, -45, 1000));
//
// key_positions.add(new Vector4f(0, 7000, 0, 2000));
// key_rotations.add(new Vector4f(90, 0, 0, 2000));
//
// key_positions.add(new Vector4f(0, 7000, 0, 2000));
// key_rotations.add(new Vector4f(90, 180, 0, 2000));
//
// key_positions.add(new Vector4f(0, 7000, 0, 1000));
// key_rotations.add(new Vector4f(90, 180, 45, 1000));
//
// key_positions.add(new Vector4f(0, 7000, 0, 1000));
// key_rotations.add(new Vector4f(90, 180, -45, 1000));
key_positions.add(new Vector4f(0, 500, -1000, 4000));

@ -24,6 +24,7 @@ public class ShaderLoader {
public static void loadShaders() {
loadShader(0, "shader.vs", "shader.fs");
// loadShader(1, "invert.vsh", "invert.fsh");
System.out.println("Shaders load ok.");

Loading…
Cancel
Save