Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
## Eclipse
#################

target/

*.pydevproject
.project
.metadata
Expand Down
23 changes: 23 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.base</groupId>
<artifactId>3DGameEngine</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>3DGameEngine</name>
<url>http://maven.apache.org</url>

<dependencies>
<dependency>
<groupId>org.lwjgl.lwjgl</groupId>
<artifactId>lwjgl</artifactId>
<version>2.9.1</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
71 changes: 71 additions & 0 deletions src/main/java/com/base/engine/components/BaseLight.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* Copyright (C) 2014 Benny Bobaganoosh
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.base.engine.components;

import com.base.engine.core.CoreEngine;
import com.base.engine.rendering.RenderingEngine;
import com.base.engine.core.Vector3f;
import com.base.engine.rendering.Shader;

public class BaseLight extends GameComponent
{
private Vector3f color;
private float intensity;
private Shader shader;

public BaseLight(Vector3f color, float intensity)
{
this.color = color;
this.intensity = intensity;
}

@Override
public void addToEngine(CoreEngine engine)
{
engine.getRenderingEngine().addLight(this);
}

public void setShader(Shader shader)
{
this.shader = shader;
}

public Shader getShader()
{
return shader;
}

public Vector3f getColor()
{
return color;
}

public void setColor(Vector3f color)
{
this.color = color;
}

public float getIntensity()
{
return intensity;
}

public void setIntensity(float intensity)
{
this.intensity = intensity;
}
}
47 changes: 47 additions & 0 deletions src/main/java/com/base/engine/components/Camera.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright (C) 2014 Benny Bobaganoosh
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.base.engine.components;

import com.base.engine.core.*;
import com.base.engine.rendering.RenderingEngine;
import com.base.engine.rendering.Window;

public class Camera extends GameComponent
{
private Matrix4f projection;

public Camera(float fov, float aspect, float zNear, float zFar)
{
this.projection = new Matrix4f().initPerspective(fov, aspect, zNear, zFar);
}

public Matrix4f getViewProjection()
{
Matrix4f cameraRotation = getTransform().getTransformedRot().conjugate().toRotationMatrix();
Vector3f cameraPos = getTransform().getTransformedPos().mul(-1);

Matrix4f cameraTranslation = new Matrix4f().initTranslation(cameraPos.getX(), cameraPos.getY(), cameraPos.getZ());

return projection.mul(cameraRotation.mul(cameraTranslation));
}

@Override
public void addToEngine(CoreEngine engine)
{
engine.getRenderingEngine().addCamera(this);
}
}
35 changes: 35 additions & 0 deletions src/main/java/com/base/engine/components/DirectionalLight.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright (C) 2014 Benny Bobaganoosh
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.base.engine.components;

import com.base.engine.core.Vector3f;
import com.base.engine.rendering.Shader;

public class DirectionalLight extends BaseLight
{
public DirectionalLight(Vector3f color, float intensity)
{
super(color, intensity);

setShader(new Shader("forward-directional"));
}

public Vector3f getDirection()
{
return getTransform().getTransformedRot().getForward();
}
}
76 changes: 76 additions & 0 deletions src/main/java/com/base/engine/components/FreeLook.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* Copyright (C) 2014 Benny Bobaganoosh
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.base.engine.components;

import com.base.engine.core.Input;
import com.base.engine.core.Vector2f;
import com.base.engine.core.Vector3f;
import com.base.engine.rendering.Window;

public class FreeLook extends GameComponent
{
private static final Vector3f yAxis = new Vector3f(0,1,0);

private boolean mouseLocked = false;
private float sensitivity;
private int unlockMouseKey;

public FreeLook(float sensitivity)
{
this(sensitivity, Input.KEY_ESCAPE);
}

public FreeLook(float sensitivity, int unlockMouseKey)
{
this.sensitivity = sensitivity;
this.unlockMouseKey = unlockMouseKey;
}

@Override
public void input(float delta)
{
Vector2f centerPosition = new Vector2f(Window.getWidth()/2, Window.getHeight()/2);

if(Input.getKey(unlockMouseKey))
{
Input.setCursor(true);
mouseLocked = false;
}
if(Input.getMouseDown(0))
{
Input.setMousePosition(centerPosition);
Input.setCursor(false);
mouseLocked = true;
}

if(mouseLocked)
{
Vector2f deltaPos = Input.getMousePosition().sub(centerPosition);

boolean rotY = deltaPos.getX() != 0;
boolean rotX = deltaPos.getY() != 0;

if(rotY)
getTransform().rotate(yAxis, (float) Math.toRadians(deltaPos.getX() * sensitivity));
if(rotX)
getTransform().rotate(getTransform().getRot().getRight(), (float) Math.toRadians(-deltaPos.getY() * sensitivity));

if(rotY || rotX)
Input.setMousePosition(centerPosition);
}
}
}
63 changes: 63 additions & 0 deletions src/main/java/com/base/engine/components/FreeMove.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* Copyright (C) 2014 Benny Bobaganoosh
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.base.engine.components;

import com.base.engine.core.Input;
import com.base.engine.core.Vector3f;

public class FreeMove extends GameComponent
{
private float speed;
private int forwardKey;
private int backKey;
private int leftKey;
private int rightKey;

public FreeMove(float speed)
{
this(speed, Input.KEY_W, Input.KEY_S, Input.KEY_A, Input.KEY_D);
}

public FreeMove(float speed, int forwardKey, int backKey, int leftKey, int rightKey)
{
this.speed = speed;
this.forwardKey = forwardKey;
this.backKey = backKey;
this.leftKey = leftKey;
this.rightKey = rightKey;
}

@Override
public void input(float delta)
{
float movAmt = speed * delta;

if(Input.getKey(forwardKey))
move(getTransform().getRot().getForward(), movAmt);
if(Input.getKey(backKey))
move(getTransform().getRot().getForward(), -movAmt);
if(Input.getKey(leftKey))
move(getTransform().getRot().getLeft(), movAmt);
if(Input.getKey(rightKey))
move(getTransform().getRot().getRight(), movAmt);
}

private void move(Vector3f dir, float amt)
{
getTransform().setPos(getTransform().getPos().add(dir.mul(amt)));
}
}
45 changes: 45 additions & 0 deletions src/main/java/com/base/engine/components/GameComponent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright (C) 2014 Benny Bobaganoosh
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.base.engine.components;

import com.base.engine.core.CoreEngine;
import com.base.engine.core.GameObject;
import com.base.engine.rendering.RenderingEngine;
import com.base.engine.core.Transform;
import com.base.engine.rendering.Shader;

public abstract class GameComponent
{
private GameObject parent;

public void input(float delta) {}
public void update(float delta) {}
public void render(Shader shader, RenderingEngine renderingEngine) {}

public void setParent(GameObject parent)
{
this.parent = parent;
}

public Transform getTransform()
{
return parent.getTransform();
}

public void addToEngine(CoreEngine engine) {}
}

Loading