[DEV] so many things
This commit is contained in:
parent
b84960ae9c
commit
2aee7077a9
BIN
res/dirt.png
BIN
res/dirt.png
Binary file not shown.
Before Width: | Height: | Size: 164 KiB After Width: | Height: | Size: 122 KiB |
@ -1,5 +1,6 @@
|
||||
package entities;
|
||||
|
||||
import org.atriaSoft.etk.math.Matrix4f;
|
||||
import org.atriaSoft.etk.math.Vector3f;
|
||||
|
||||
import renderEngine.DisplayManager;
|
||||
@ -39,6 +40,7 @@ public class Camera {
|
||||
|
||||
}
|
||||
|
||||
|
||||
private float calculateHorizontalDistance() {
|
||||
return (float) (distanceFromPlayer * Math.cos(pitch));
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ public class OBJFileLoader {
|
||||
|
||||
public static ModelData loadOBJ(String objFileName) {
|
||||
FileReader isr = null;
|
||||
File objFile = new File(RES_LOC + objFileName + ".obj");
|
||||
File objFile = new File(objFileName);
|
||||
try {
|
||||
isr = new FileReader(objFile);
|
||||
} catch (FileNotFoundException e) {
|
||||
|
@ -3,7 +3,7 @@ package org.atriaSoft.etk.math;
|
||||
import java.nio.FloatBuffer;
|
||||
|
||||
public class Matrix4f {
|
||||
private float[] mat = new float[4*4]; //!< matrix data
|
||||
public float[] mat = new float[4*4]; //!< matrix data
|
||||
/**
|
||||
* @brief configure identity of the matrix
|
||||
*/
|
||||
|
@ -2,11 +2,27 @@ package org.atriaSoft.etk.math;
|
||||
|
||||
public class Transform3D {
|
||||
protected Vector3f position; //! Position
|
||||
public Vector3f getPosition() {
|
||||
return position;
|
||||
}
|
||||
public void setPosition(Vector3f position) {
|
||||
this.position = position;
|
||||
}
|
||||
public Quaternion getOrientation() {
|
||||
return orientation;
|
||||
}
|
||||
public void setOrientation(Quaternion orientation) {
|
||||
this.orientation = orientation;
|
||||
}
|
||||
protected Quaternion orientation; //!< Orientation
|
||||
public Transform3D() {
|
||||
this.position = Vector3f.zero();
|
||||
this.orientation = Quaternion.identity();
|
||||
}
|
||||
public Transform3D(Vector3f position) {
|
||||
this.position = position.clone();
|
||||
this.orientation = Quaternion.identity();
|
||||
}
|
||||
public Transform3D(Vector3f position, Matrix3f orientation) {
|
||||
this.position = position.clone();
|
||||
this.orientation = new Quaternion(orientation);
|
||||
@ -39,24 +55,43 @@ public class Transform3D {
|
||||
this.position.setValue(matrix[12], matrix[13], matrix[14]);
|
||||
}
|
||||
/// Get the OpenGL matrix of the transform
|
||||
public void getOpenGLMatrix(float[] matrix) {
|
||||
public Matrix4f getOpenGLMatrix() {
|
||||
Matrix4f out = new Matrix4f();
|
||||
Matrix3f tmpMatrix = this.orientation.getMatrix();
|
||||
matrix[0] = tmpMatrix.mat[0];
|
||||
matrix[1] = tmpMatrix.mat[3];
|
||||
matrix[2] = tmpMatrix.mat[6];
|
||||
matrix[3] = 0.0f;
|
||||
matrix[4] = tmpMatrix.mat[1];
|
||||
matrix[5] = tmpMatrix.mat[4];
|
||||
matrix[6] = tmpMatrix.mat[7];
|
||||
matrix[7] = 0.0f;
|
||||
matrix[8] = tmpMatrix.mat[2];
|
||||
matrix[9] = tmpMatrix.mat[5];
|
||||
matrix[10] = tmpMatrix.mat[8];
|
||||
matrix[11] = 0.0f;
|
||||
matrix[12] = this.position.x;
|
||||
matrix[13] = this.position.y;
|
||||
matrix[14] = this.position.z;
|
||||
matrix[15] = 1.0f;
|
||||
// version transposer...
|
||||
// out.mat[0] = tmpMatrix.mat[0];
|
||||
// out.mat[1] = tmpMatrix.mat[3];
|
||||
// out.mat[2] = tmpMatrix.mat[6];
|
||||
// out.mat[3] = 0.0f;
|
||||
// out.mat[4] = tmpMatrix.mat[1];
|
||||
// out.mat[5] = tmpMatrix.mat[4];
|
||||
// out.mat[6] = tmpMatrix.mat[7];
|
||||
// out.mat[7] = 0.0f;
|
||||
// out.mat[8] = tmpMatrix.mat[2];
|
||||
// out.mat[9] = tmpMatrix.mat[5];
|
||||
// out.mat[10] = tmpMatrix.mat[8];
|
||||
// out.mat[11] = 0.0f;
|
||||
// out.mat[12] = this.position.x;
|
||||
// out.mat[13] = this.position.y;
|
||||
// out.mat[14] = this.position.z;
|
||||
// out.mat[15] = 1.0f;
|
||||
out.mat[0] = tmpMatrix.mat[0];
|
||||
out.mat[1] = tmpMatrix.mat[1];
|
||||
out.mat[2] = tmpMatrix.mat[2];
|
||||
out.mat[3] = this.position.x;
|
||||
out.mat[4] = tmpMatrix.mat[3];
|
||||
out.mat[5] = tmpMatrix.mat[4];
|
||||
out.mat[6] = tmpMatrix.mat[5];
|
||||
out.mat[7] = this.position.y;
|
||||
out.mat[8] = tmpMatrix.mat[6];
|
||||
out.mat[9] = tmpMatrix.mat[7];
|
||||
out.mat[10] = tmpMatrix.mat[8];
|
||||
out.mat[11] = this.position.z;
|
||||
out.mat[12] = 0.0f;
|
||||
out.mat[13] = 0.0f;
|
||||
out.mat[14] = 0.0f;
|
||||
out.mat[15] = 1.0f;
|
||||
return out;
|
||||
}
|
||||
/// Return the inverse of the transform
|
||||
public Transform3D inverse_new() {
|
||||
@ -66,8 +101,8 @@ public class Transform3D {
|
||||
}
|
||||
/// Return an interpolated transform
|
||||
public Transform3D interpolateTransforms(Transform3D old,
|
||||
Transform3D newOne,
|
||||
float interpolationFactor) {
|
||||
Transform3D newOne,
|
||||
float interpolationFactor) {
|
||||
Vector3f interPosition = old.position.multiply_new(1.0f - interpolationFactor)
|
||||
.add(newOne.position.multiply_new(interpolationFactor));
|
||||
Quaternion interOrientation = Quaternion.slerp(old.orientation,
|
||||
@ -108,4 +143,7 @@ public class Transform3D {
|
||||
public String toString() {
|
||||
return "Transform3D(" + this.position + " & " + this.orientation + ")";
|
||||
}
|
||||
public void applyRotation(Quaternion rotation) {
|
||||
this.orientation = this.orientation.multiply(rotation);
|
||||
}
|
||||
}
|
||||
|
@ -5,10 +5,10 @@ import org.atriaSoft.etk.math.Vector2f;
|
||||
import org.atriaSoft.gale.context.ClipboardList;
|
||||
import org.atriaSoft.gale.context.Context;
|
||||
import org.atriaSoft.gale.context.Cursor;
|
||||
import org.atriaSoft.gale.key.Keyboard;
|
||||
import org.atriaSoft.gale.key.Special;
|
||||
import org.atriaSoft.gale.key.Status;
|
||||
import org.atriaSoft.gale.key.Type;
|
||||
import org.atriaSoft.gale.key.KeyKeyboard;
|
||||
import org.atriaSoft.gale.key.KeySpecial;
|
||||
import org.atriaSoft.gale.key.KeyStatus;
|
||||
import org.atriaSoft.gale.key.KeyType;
|
||||
|
||||
public class Application {
|
||||
public boolean canDraw = false;
|
||||
@ -113,10 +113,11 @@ public class Application {
|
||||
* @param[in] pos Position of the event (can be <0 if out of window).
|
||||
* @param[in] state Key state (up/down/move)
|
||||
*/
|
||||
public void onPointer(Type type,
|
||||
int pointerID,
|
||||
Vector2f pos,
|
||||
Status state) {
|
||||
public void onPointer(KeySpecial special,
|
||||
KeyType type,
|
||||
int pointerID,
|
||||
Vector2f pos,
|
||||
KeyStatus state) {
|
||||
|
||||
}
|
||||
/**
|
||||
@ -126,10 +127,10 @@ public class Application {
|
||||
* @param[in] value Unicode value of the char pushed (viable only if type==gale::key::keyboard::character).
|
||||
* @param[in] state State of the key (up/down/upRepeate/downRepeate)
|
||||
*/
|
||||
public void onKeyboard(Special special,
|
||||
Keyboard type,
|
||||
public void onKeyboard(KeySpecial special,
|
||||
KeyKeyboard type,
|
||||
Character value,
|
||||
Status state) {
|
||||
KeyStatus state) {
|
||||
|
||||
}
|
||||
/**
|
||||
|
@ -12,10 +12,10 @@ import org.atriaSoft.gale.Log;
|
||||
import org.atriaSoft.gale.Orientation;
|
||||
import org.atriaSoft.gale.backend3d.OpenGL;
|
||||
import org.atriaSoft.gale.resource.ResourceManager;
|
||||
import org.atriaSoft.gale.key.Keyboard;
|
||||
import org.atriaSoft.gale.key.Special;
|
||||
import org.atriaSoft.gale.key.Status;
|
||||
import org.atriaSoft.gale.key.Type;
|
||||
import org.atriaSoft.gale.key.KeyKeyboard;
|
||||
import org.atriaSoft.gale.key.KeySpecial;
|
||||
import org.atriaSoft.gale.key.KeyStatus;
|
||||
import org.atriaSoft.gale.key.KeyType;
|
||||
|
||||
interface ActionToDoInAsyncLoop {
|
||||
public void run(Context context);
|
||||
@ -250,45 +250,47 @@ public abstract class Context {
|
||||
// }
|
||||
// }
|
||||
|
||||
public void OS_SetInput( Type type,
|
||||
Status status,
|
||||
int pointerID,
|
||||
Vector2f pos){
|
||||
public void OS_SetInput(KeySpecial special,
|
||||
KeyType type,
|
||||
KeyStatus status,
|
||||
int pointerID,
|
||||
Vector2f pos){
|
||||
postAction((context)->{
|
||||
Application appl = context.getApplication();
|
||||
if (appl == null) {
|
||||
return;
|
||||
}
|
||||
appl.onPointer(type,
|
||||
pointerID,
|
||||
pos,
|
||||
status);
|
||||
appl.onPointer(special,
|
||||
type,
|
||||
pointerID,
|
||||
pos,
|
||||
status);
|
||||
});
|
||||
}
|
||||
public void OS_setKeyboard( Special special,
|
||||
Keyboard type,
|
||||
Status state,
|
||||
public void OS_setKeyboard( KeySpecial special,
|
||||
KeyKeyboard type,
|
||||
KeyStatus state,
|
||||
boolean isARepeateKey) {
|
||||
OS_setKeyboard(special, type, state, isARepeateKey, (char)0);
|
||||
}
|
||||
public void OS_setKeyboard( Special special,
|
||||
Keyboard type,
|
||||
Status state,
|
||||
public void OS_setKeyboard( KeySpecial special,
|
||||
KeyKeyboard type,
|
||||
KeyStatus state,
|
||||
boolean isARepeateKey,
|
||||
Character charValue) {
|
||||
Status tmpState = state;
|
||||
KeyStatus tmpState = state;
|
||||
if (isARepeateKey == true) {
|
||||
if (tmpState == Status.down) {
|
||||
tmpState = Status.downRepeate;
|
||||
if (tmpState == KeyStatus.down) {
|
||||
tmpState = KeyStatus.downRepeate;
|
||||
} else {
|
||||
tmpState = Status.upRepeate;
|
||||
tmpState = KeyStatus.upRepeate;
|
||||
}
|
||||
}
|
||||
OS_setKeyboard2(special, type, state, charValue);
|
||||
}
|
||||
public void OS_setKeyboard2( Special special,
|
||||
Keyboard type,
|
||||
Status state,
|
||||
public void OS_setKeyboard2( KeySpecial special,
|
||||
KeyKeyboard type,
|
||||
KeyStatus state,
|
||||
Character charValue){
|
||||
postAction((context)->{
|
||||
Application appl = context.getApplication();
|
||||
|
@ -17,10 +17,10 @@ import org.atriaSoft.etk.math.Vector2f;
|
||||
import org.atriaSoft.gale.Application;
|
||||
import org.atriaSoft.gale.Fps;
|
||||
import org.atriaSoft.gale.context.Context;
|
||||
import org.atriaSoft.gale.key.Keyboard;
|
||||
import org.atriaSoft.gale.key.Special;
|
||||
import org.atriaSoft.gale.key.Status;
|
||||
import org.atriaSoft.gale.key.Type;
|
||||
import org.atriaSoft.gale.key.KeyKeyboard;
|
||||
import org.atriaSoft.gale.key.KeySpecial;
|
||||
import org.atriaSoft.gale.key.KeyStatus;
|
||||
import org.atriaSoft.gale.key.KeyType;
|
||||
import org.atriaSoft.gameEngine.Log;
|
||||
import org.lwjgl.Version;
|
||||
import org.lwjgl.glfw.GLFWErrorCallback;
|
||||
@ -55,7 +55,7 @@ public class ContextLWJGL extends Context {
|
||||
|
||||
// The window handle
|
||||
private long window = 0;
|
||||
private Special guiKeyBoardMode = new Special();
|
||||
private KeySpecial guiKeyBoardMode = new KeySpecial();
|
||||
|
||||
public ContextLWJGL(Application application, String[] args) {
|
||||
super(application, args);
|
||||
@ -94,37 +94,6 @@ public class ContextLWJGL extends Context {
|
||||
glfwTerminate();
|
||||
glfwSetErrorCallback(null).free();
|
||||
}
|
||||
private static boolean valueS = false;
|
||||
private static boolean valueZ = false;
|
||||
private static boolean valueQ = false;
|
||||
private static boolean valueD = false;
|
||||
private static boolean valueA = false;
|
||||
private static boolean valueW = false;
|
||||
private static boolean valueSPACE = false;
|
||||
public static boolean isKeyDown(char value) {
|
||||
if (value == 's') {
|
||||
return valueS;
|
||||
}
|
||||
if (value == 'z') {
|
||||
return valueZ;
|
||||
}
|
||||
if (value == 'q') {
|
||||
return valueQ;
|
||||
}
|
||||
if (value == 'd') {
|
||||
return valueD;
|
||||
}
|
||||
if (value == 'w') {
|
||||
return valueW;
|
||||
}
|
||||
if (value == 'a') {
|
||||
return valueA;
|
||||
}
|
||||
if (value == ' ') {
|
||||
return valueSPACE;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void initWindows() {
|
||||
// Setup an error callback. The default implementation
|
||||
@ -212,30 +181,30 @@ public class ContextLWJGL extends Context {
|
||||
private void keyCallback(long window, int key, int scancode, int action, int mods) {
|
||||
boolean find = true;
|
||||
boolean thisIsAReapeateKey = false; // TODO detect this ...
|
||||
Keyboard keyInput = Keyboard.unknow;
|
||||
KeyKeyboard keyInput = KeyKeyboard.unknow;
|
||||
Log.error("keyboard input " + key + " " + scancode);
|
||||
switch (key) {
|
||||
//case 80: // keypad
|
||||
case GLFW_KEY_UP: keyInput = Keyboard.up; break;
|
||||
//case 83: // keypad
|
||||
case GLFW_KEY_LEFT: keyInput = Keyboard.left; break;
|
||||
//case 85: // keypad
|
||||
case GLFW_KEY_RIGHT: keyInput = Keyboard.right; break;
|
||||
//case 88: // keypad
|
||||
case GLFW_KEY_DOWN: keyInput = Keyboard.down; break;
|
||||
//case 81: // keypad
|
||||
case GLFW_KEY_PAGE_UP: keyInput = Keyboard.pageUp; break;
|
||||
//case 89: // keypad
|
||||
case GLFW_KEY_PAGE_DOWN: keyInput = Keyboard.pageDown; break;
|
||||
//case 79: // keypad
|
||||
case GLFW_KEY_HOME: keyInput = Keyboard.start; break;
|
||||
//case 87: // keypad
|
||||
case GLFW_KEY_END: keyInput = Keyboard.end; break;
|
||||
case GLFW_KEY_PRINT_SCREEN: keyInput = Keyboard.stopDefil; break;
|
||||
case GLFW_KEY_PAUSE: keyInput = Keyboard.wait; break;
|
||||
//case 90: // keypad
|
||||
//case 328: // keypad
|
||||
case GLFW_KEY_UP: keyInput = KeyKeyboard.up; break;
|
||||
//case 324: // keypad
|
||||
case GLFW_KEY_LEFT: keyInput = KeyKeyboard.left; break;
|
||||
//case 326: // keypad
|
||||
case GLFW_KEY_RIGHT: keyInput = KeyKeyboard.right; break;
|
||||
//case 323: // keypad
|
||||
case GLFW_KEY_DOWN: keyInput = KeyKeyboard.down; break;
|
||||
case 329: // keypad
|
||||
case GLFW_KEY_PAGE_UP: keyInput = KeyKeyboard.pageUp; break;
|
||||
case 323: // keypad
|
||||
case GLFW_KEY_PAGE_DOWN: keyInput = KeyKeyboard.pageDown; break;
|
||||
case 327: // keypad
|
||||
case GLFW_KEY_HOME: keyInput = KeyKeyboard.start; break;
|
||||
case 321: // keypad
|
||||
case GLFW_KEY_END: keyInput = KeyKeyboard.end; break;
|
||||
case GLFW_KEY_PRINT_SCREEN: keyInput = KeyKeyboard.stopDefil; break;
|
||||
case GLFW_KEY_PAUSE: keyInput = KeyKeyboard.wait; break;
|
||||
case 320: // keypad
|
||||
case GLFW_KEY_INSERT:
|
||||
keyInput = Keyboard.insert;
|
||||
keyInput = KeyKeyboard.insert;
|
||||
if(action == GLFW_RELEASE) {
|
||||
if (guiKeyBoardMode.getInsert() == true) {
|
||||
guiKeyBoardMode.setInsert(false);
|
||||
@ -245,54 +214,54 @@ public class ContextLWJGL extends Context {
|
||||
}
|
||||
break;
|
||||
//case 84: keyInput = KeyboardCenter; break; // Keypad
|
||||
case GLFW_KEY_F1: keyInput = Keyboard.f1; break;
|
||||
case GLFW_KEY_F2: keyInput = Keyboard.f2; break;
|
||||
case GLFW_KEY_F3: keyInput = Keyboard.f3; break;
|
||||
case GLFW_KEY_F4: keyInput = Keyboard.f4; break;
|
||||
case GLFW_KEY_F5: keyInput = Keyboard.f5; break;
|
||||
case GLFW_KEY_F6: keyInput = Keyboard.f6; break;
|
||||
case GLFW_KEY_F7: keyInput = Keyboard.f7; break;
|
||||
case GLFW_KEY_F8: keyInput = Keyboard.f8; break;
|
||||
case GLFW_KEY_F9: keyInput = Keyboard.f9; break;
|
||||
case GLFW_KEY_F10: keyInput = Keyboard.f10; break;
|
||||
case GLFW_KEY_F11: keyInput = Keyboard.f11; break;
|
||||
case GLFW_KEY_F12: keyInput = Keyboard.f12; break;
|
||||
case GLFW_KEY_CAPS_LOCK: keyInput = Keyboard.capLock; guiKeyBoardMode.setCapsLock (action == GLFW_PRESS); break;
|
||||
case GLFW_KEY_LEFT_SHIFT: keyInput = Keyboard.shiftLeft; guiKeyBoardMode.setShiftLeft (action == GLFW_PRESS); break;
|
||||
case GLFW_KEY_RIGHT_SHIFT: keyInput = Keyboard.shiftRight; guiKeyBoardMode.setShiftRight(action == GLFW_PRESS); break;
|
||||
case GLFW_KEY_LEFT_CONTROL: keyInput = Keyboard.ctrlLeft; guiKeyBoardMode.setCtrlLeft (action == GLFW_PRESS); break;
|
||||
case GLFW_KEY_RIGHT_CONTROL: keyInput = Keyboard.ctrlRight; guiKeyBoardMode.setCtrlRight (action == GLFW_PRESS); break;
|
||||
case GLFW_KEY_LEFT_SUPER: keyInput = Keyboard.metaLeft; guiKeyBoardMode.setMetaLeft (action == GLFW_PRESS); break;
|
||||
case GLFW_KEY_RIGHT_SUPER: keyInput = Keyboard.metaRight; guiKeyBoardMode.setMetaRight (action == GLFW_PRESS); break;
|
||||
case GLFW_KEY_LEFT_ALT: keyInput = Keyboard.altLeft; guiKeyBoardMode.setAltLeft (action == GLFW_PRESS); break;
|
||||
case GLFW_KEY_RIGHT_ALT: keyInput = Keyboard.altRight; guiKeyBoardMode.setAltRight (action == GLFW_PRESS); break;
|
||||
case GLFW_KEY_MENU: keyInput = Keyboard.contextMenu; break;
|
||||
case GLFW_KEY_NUM_LOCK: keyInput = Keyboard.numLock; guiKeyBoardMode.setNumLock (action == GLFW_PRESS); break;
|
||||
case GLFW_KEY_F1: keyInput = KeyKeyboard.f1; break;
|
||||
case GLFW_KEY_F2: keyInput = KeyKeyboard.f2; break;
|
||||
case GLFW_KEY_F3: keyInput = KeyKeyboard.f3; break;
|
||||
case GLFW_KEY_F4: keyInput = KeyKeyboard.f4; break;
|
||||
case GLFW_KEY_F5: keyInput = KeyKeyboard.f5; break;
|
||||
case GLFW_KEY_F6: keyInput = KeyKeyboard.f6; break;
|
||||
case GLFW_KEY_F7: keyInput = KeyKeyboard.f7; break;
|
||||
case GLFW_KEY_F8: keyInput = KeyKeyboard.f8; break;
|
||||
case GLFW_KEY_F9: keyInput = KeyKeyboard.f9; break;
|
||||
case GLFW_KEY_F10: keyInput = KeyKeyboard.f10; break;
|
||||
case GLFW_KEY_F11: keyInput = KeyKeyboard.f11; break;
|
||||
case GLFW_KEY_F12: keyInput = KeyKeyboard.f12; break;
|
||||
case GLFW_KEY_CAPS_LOCK: keyInput = KeyKeyboard.capLock; guiKeyBoardMode.setCapsLock (action == GLFW_PRESS); break;
|
||||
case GLFW_KEY_LEFT_SHIFT: keyInput = KeyKeyboard.shiftLeft; guiKeyBoardMode.setShiftLeft (action == GLFW_PRESS); break;
|
||||
case GLFW_KEY_RIGHT_SHIFT: keyInput = KeyKeyboard.shiftRight; guiKeyBoardMode.setShiftRight(action == GLFW_PRESS); break;
|
||||
case GLFW_KEY_LEFT_CONTROL: keyInput = KeyKeyboard.ctrlLeft; guiKeyBoardMode.setCtrlLeft (action == GLFW_PRESS); break;
|
||||
case GLFW_KEY_RIGHT_CONTROL: keyInput = KeyKeyboard.ctrlRight; guiKeyBoardMode.setCtrlRight (action == GLFW_PRESS); break;
|
||||
case GLFW_KEY_LEFT_SUPER: keyInput = KeyKeyboard.metaLeft; guiKeyBoardMode.setMetaLeft (action == GLFW_PRESS); break;
|
||||
case GLFW_KEY_RIGHT_SUPER: keyInput = KeyKeyboard.metaRight; guiKeyBoardMode.setMetaRight (action == GLFW_PRESS); break;
|
||||
case GLFW_KEY_LEFT_ALT: keyInput = KeyKeyboard.altLeft; guiKeyBoardMode.setAltLeft (action == GLFW_PRESS); break;
|
||||
case GLFW_KEY_RIGHT_ALT: keyInput = KeyKeyboard.altRight; guiKeyBoardMode.setAltRight (action == GLFW_PRESS); break;
|
||||
case GLFW_KEY_MENU: keyInput = KeyKeyboard.contextMenu; break;
|
||||
case GLFW_KEY_NUM_LOCK: keyInput = KeyKeyboard.numLock; guiKeyBoardMode.setNumLock (action == GLFW_PRESS); break;
|
||||
case GLFW_KEY_DELETE: // Suppr on keypad
|
||||
find = false;
|
||||
if(guiKeyBoardMode.getNumLock() == true){
|
||||
OS_setKeyboard(guiKeyBoardMode,
|
||||
Keyboard.character,
|
||||
(action == GLFW_PRESS?Status.down:Status.up),
|
||||
KeyKeyboard.character,
|
||||
(action == GLFW_PRESS?KeyStatus.down:KeyStatus.up),
|
||||
thisIsAReapeateKey,
|
||||
'.');
|
||||
if (thisIsAReapeateKey == true) {
|
||||
OS_setKeyboard(guiKeyBoardMode,
|
||||
Keyboard.character,
|
||||
(action != GLFW_PRESS?Status.down:Status.up),
|
||||
KeyKeyboard.character,
|
||||
(action != GLFW_PRESS?KeyStatus.down:KeyStatus.up),
|
||||
thisIsAReapeateKey,
|
||||
'.');
|
||||
}
|
||||
} else {
|
||||
OS_setKeyboard(guiKeyBoardMode,
|
||||
Keyboard.character,
|
||||
(action == GLFW_PRESS?Status.down:Status.up),
|
||||
KeyKeyboard.character,
|
||||
(action == GLFW_PRESS?KeyStatus.down:KeyStatus.up),
|
||||
thisIsAReapeateKey,
|
||||
(char)0x7F);
|
||||
if (thisIsAReapeateKey == true) {
|
||||
OS_setKeyboard(guiKeyBoardMode,
|
||||
Keyboard.character,
|
||||
(action != GLFW_PRESS?Status.down:Status.up),
|
||||
KeyKeyboard.character,
|
||||
(action != GLFW_PRESS?KeyStatus.down:KeyStatus.up),
|
||||
thisIsAReapeateKey,
|
||||
(char)0x7F);
|
||||
}
|
||||
@ -301,14 +270,14 @@ public class ContextLWJGL extends Context {
|
||||
case GLFW_KEY_TAB: // special case for TAB
|
||||
find = false;
|
||||
OS_setKeyboard(guiKeyBoardMode,
|
||||
Keyboard.character,
|
||||
(action == GLFW_PRESS?Status.down:Status.up),
|
||||
KeyKeyboard.character,
|
||||
(action == GLFW_PRESS?KeyStatus.down:KeyStatus.up),
|
||||
thisIsAReapeateKey,
|
||||
(char)0x09);
|
||||
if (thisIsAReapeateKey == true) {
|
||||
OS_setKeyboard(guiKeyBoardMode,
|
||||
Keyboard.character,
|
||||
(action!=GLFW_PRESS?Status.down:Status.up),
|
||||
KeyKeyboard.character,
|
||||
(action!=GLFW_PRESS?KeyStatus.down:KeyStatus.up),
|
||||
thisIsAReapeateKey,
|
||||
(char)0x09);
|
||||
}
|
||||
@ -346,14 +315,14 @@ public class ContextLWJGL extends Context {
|
||||
tmpKey += (int)'A' - (int)'a';
|
||||
}
|
||||
OS_setKeyboard(guiKeyBoardMode,
|
||||
Keyboard.character,
|
||||
(action==GLFW_PRESS?Status.down:Status.up),
|
||||
KeyKeyboard.character,
|
||||
(action==GLFW_PRESS?KeyStatus.down:KeyStatus.up),
|
||||
thisIsAReapeateKey,
|
||||
(char)tmpKey);
|
||||
if (thisIsAReapeateKey == true) {
|
||||
OS_setKeyboard(guiKeyBoardMode,
|
||||
Keyboard.character,
|
||||
(action!=GLFW_PRESS?Status.down:Status.up),
|
||||
KeyKeyboard.character,
|
||||
(action!=GLFW_PRESS?KeyStatus.down:KeyStatus.up),
|
||||
thisIsAReapeateKey,
|
||||
(char)tmpKey);
|
||||
}
|
||||
@ -376,14 +345,14 @@ public class ContextLWJGL extends Context {
|
||||
// tmpKey += (int)'A' - (int)'a';
|
||||
// }
|
||||
OS_setKeyboard(guiKeyBoardMode,
|
||||
Keyboard.character,
|
||||
(action==GLFW_PRESS?Status.down:Status.up),
|
||||
KeyKeyboard.character,
|
||||
(action==GLFW_PRESS?KeyStatus.down:KeyStatus.up),
|
||||
thisIsAReapeateKey,
|
||||
(char)tmpKey);
|
||||
if (thisIsAReapeateKey == true) {
|
||||
OS_setKeyboard(guiKeyBoardMode,
|
||||
Keyboard.character,
|
||||
(action!=GLFW_PRESS?Status.down:Status.up),
|
||||
KeyKeyboard.character,
|
||||
(action!=GLFW_PRESS?KeyStatus.down:KeyStatus.up),
|
||||
thisIsAReapeateKey,
|
||||
(char)tmpKey);
|
||||
}
|
||||
@ -438,12 +407,12 @@ public class ContextLWJGL extends Context {
|
||||
if (find == true) {
|
||||
OS_setKeyboard(guiKeyBoardMode,
|
||||
keyInput,
|
||||
(action == GLFW_PRESS?Status.down:Status.up),
|
||||
(action == GLFW_PRESS?KeyStatus.down:KeyStatus.up),
|
||||
thisIsAReapeateKey);
|
||||
if (thisIsAReapeateKey == true) {
|
||||
OS_setKeyboard(guiKeyBoardMode,
|
||||
keyInput,
|
||||
(action!=GLFW_PRESS?Status.down:Status.up),
|
||||
(action!=GLFW_PRESS?KeyStatus.down:KeyStatus.up),
|
||||
thisIsAReapeateKey);
|
||||
}
|
||||
}
|
||||
@ -459,8 +428,9 @@ public class ContextLWJGL extends Context {
|
||||
for (int iii=0; iii<MAX_MANAGE_INPUT; iii++) {
|
||||
if (inputIsPressed[iii] == true) {
|
||||
//Log.debug("X11 event: bt=" << iii << " " << event.type << " = \"MotionNotify\" (" << m_cursorEventX << "," << m_cursorEventY << ")");
|
||||
OS_SetInput(Type.mouse,
|
||||
Status.move,
|
||||
OS_SetInput(guiKeyBoardMode,
|
||||
KeyType.mouse,
|
||||
KeyStatus.move,
|
||||
iii,
|
||||
cursorPos);
|
||||
findOne = true;
|
||||
@ -468,8 +438,9 @@ public class ContextLWJGL extends Context {
|
||||
}
|
||||
if (findOne == false) {
|
||||
//X11_DEBUG("X11 event: bt=" << 0 << " " << event.type << " = \"MotionNotify\" (" << m_cursorEventX << "," << m_cursorEventY << ")");
|
||||
OS_SetInput(Type.mouse,
|
||||
Status.move,
|
||||
OS_SetInput(guiKeyBoardMode,
|
||||
KeyType.mouse,
|
||||
KeyStatus.move,
|
||||
0,
|
||||
cursorPos);
|
||||
}
|
||||
@ -482,46 +453,50 @@ public class ContextLWJGL extends Context {
|
||||
*/
|
||||
if (yoffset<0) {
|
||||
inputIsPressed[5] = true;
|
||||
OS_SetInput(Type.mouse,
|
||||
Status.down,
|
||||
OS_SetInput(guiKeyBoardMode,KeyType.mouse,
|
||||
KeyStatus.down,
|
||||
5,
|
||||
cursorPos);
|
||||
inputIsPressed[5] = false;
|
||||
OS_SetInput(Type.mouse,
|
||||
Status.up,
|
||||
OS_SetInput(guiKeyBoardMode,KeyType.mouse,
|
||||
KeyStatus.up,
|
||||
5,
|
||||
cursorPos);
|
||||
} else if (yoffset>0) {
|
||||
inputIsPressed[4] = true;
|
||||
OS_SetInput(Type.mouse,
|
||||
Status.down,
|
||||
OS_SetInput(guiKeyBoardMode,KeyType.mouse,
|
||||
KeyStatus.down,
|
||||
4,
|
||||
cursorPos);
|
||||
inputIsPressed[4] = false;
|
||||
OS_SetInput(Type.mouse,
|
||||
Status.up,
|
||||
OS_SetInput(guiKeyBoardMode,KeyType.mouse,
|
||||
KeyStatus.up,
|
||||
4,
|
||||
cursorPos);
|
||||
}
|
||||
}
|
||||
private void mouseCallback(long window, int button, int action, int mods) {
|
||||
if (action == GLFW_PRESS) {
|
||||
// Log.info("mouse value: GLFW_PRESS " + action + " bt=" + button);
|
||||
if (button < MAX_MANAGE_INPUT) {
|
||||
inputIsPressed[button] = true;
|
||||
}
|
||||
OS_SetInput(Type.mouse,
|
||||
Status.down,
|
||||
OS_SetInput(guiKeyBoardMode,KeyType.mouse,
|
||||
KeyStatus.down,
|
||||
button,
|
||||
cursorPos);
|
||||
} else if (action == GLFW_RELEASE) {
|
||||
// Log.info("mouse value: GLFW_RELEASE" + action + " bt=" + button);
|
||||
leftButtonStateDown = false;
|
||||
if (button < MAX_MANAGE_INPUT) {
|
||||
inputIsPressed[button] = false;
|
||||
}
|
||||
OS_SetInput(Type.mouse,
|
||||
Status.up,
|
||||
OS_SetInput(guiKeyBoardMode,KeyType.mouse,
|
||||
KeyStatus.up,
|
||||
button,
|
||||
cursorPos);
|
||||
// } else {
|
||||
// Log.info("mouse value: ???" + action + " bt=" + button);
|
||||
}
|
||||
}
|
||||
public static float getFrameTimeSecconds() {
|
||||
|
50
src/org/atriaSoft/gale/event/EventEntry.java
Normal file
50
src/org/atriaSoft/gale/event/EventEntry.java
Normal file
@ -0,0 +1,50 @@
|
||||
package org.atriaSoft.gale.event;
|
||||
|
||||
import org.atriaSoft.gale.key.KeyKeyboard;
|
||||
import org.atriaSoft.gale.key.KeyStatus;
|
||||
import org.atriaSoft.gale.key.KeySpecial;
|
||||
|
||||
public class EventEntry {
|
||||
private KeySpecial specialKey; //!< input key status (prevent change in time..)
|
||||
private KeyKeyboard type; //!< type of hardware event
|
||||
private KeyStatus status; //!< status of hardware event
|
||||
private Character unicodeData; //!< Unicode data (in some case)
|
||||
public EventEntry(KeySpecial specialKey,
|
||||
KeyKeyboard type,
|
||||
KeyStatus status,
|
||||
Character charValue) {
|
||||
this.type = type;
|
||||
this.status = status;
|
||||
this.specialKey = specialKey;
|
||||
this.unicodeData = charValue;
|
||||
}
|
||||
public void setType(KeyKeyboard type) {
|
||||
this.type = type;
|
||||
}
|
||||
public KeyKeyboard getType() {
|
||||
return this.type;
|
||||
}
|
||||
public void setStatus(KeyStatus status) {
|
||||
this.status = status;
|
||||
}
|
||||
public KeyStatus getStatus() {
|
||||
return this.status;
|
||||
};
|
||||
public void setSpecialKey(KeySpecial specialKey) {
|
||||
this.specialKey = specialKey;
|
||||
}
|
||||
public KeySpecial getSpecialKey() {
|
||||
return this.specialKey;
|
||||
}
|
||||
public void setChar(Character charValue) {
|
||||
this.unicodeData = charValue;
|
||||
}
|
||||
public Character getChar() {
|
||||
return this.unicodeData;
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
return "EventEntry [type=" + type + ", status=" + status + ", unicodeData="
|
||||
+ unicodeData + ", specialKey=" + specialKey + "]";
|
||||
}
|
||||
}
|
57
src/org/atriaSoft/gale/event/EventInput.java
Normal file
57
src/org/atriaSoft/gale/event/EventInput.java
Normal file
@ -0,0 +1,57 @@
|
||||
package org.atriaSoft.gale.event;
|
||||
|
||||
import org.atriaSoft.gale.key.KeyType;
|
||||
import org.atriaSoft.gale.key.KeyStatus;
|
||||
import org.atriaSoft.etk.math.Vector2f;
|
||||
import org.atriaSoft.gale.key.KeySpecial;
|
||||
|
||||
public class EventInput {
|
||||
private KeyType type;
|
||||
private KeyStatus status;
|
||||
private int inputId;
|
||||
private Vector2f position;
|
||||
private KeySpecial specialKey; //!< input key status (prevent change in time..)
|
||||
public EventInput(KeyType type, KeyStatus status, int inputId, Vector2f position, KeySpecial specialKey) {
|
||||
this.type = type;
|
||||
this.status = status;
|
||||
this.inputId = inputId;
|
||||
this.position = position;
|
||||
this.specialKey = specialKey;
|
||||
}
|
||||
public KeyType getType() {
|
||||
return type;
|
||||
}
|
||||
public void setType(KeyType type) {
|
||||
this.type = type;
|
||||
}
|
||||
public KeyStatus getStatus() {
|
||||
return status;
|
||||
}
|
||||
public void setStatus(KeyStatus status) {
|
||||
this.status = status;
|
||||
}
|
||||
public int getInputId() {
|
||||
return inputId;
|
||||
}
|
||||
public void setInputId(int inputId) {
|
||||
this.inputId = inputId;
|
||||
}
|
||||
public Vector2f getPosition() {
|
||||
return position;
|
||||
}
|
||||
public void setPosition(Vector2f position) {
|
||||
this.position = position;
|
||||
}
|
||||
public KeySpecial getSpecialKey() {
|
||||
return specialKey;
|
||||
}
|
||||
public void setSpecialKey(KeySpecial specialKey) {
|
||||
this.specialKey = specialKey;
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
return "EventInput [type=" + type + ", status=" + status + ", inputId=" + inputId + ", position=" + position
|
||||
+ ", specialKey=" + specialKey + "]";
|
||||
}
|
||||
|
||||
}
|
51
src/org/atriaSoft/gale/event/EventTime.java
Normal file
51
src/org/atriaSoft/gale/event/EventTime.java
Normal file
@ -0,0 +1,51 @@
|
||||
package org.atriaSoft.gale.event;
|
||||
|
||||
public class EventTime {
|
||||
private long timeSystem; //!< Current system time (micro-second)
|
||||
private long timeUpAppl; //!< Current application wake up-time (micro-second)
|
||||
private long timeDelta; //!< Time from the last cycle call of the system (main appl tick) (micro-second)
|
||||
private long timeDeltaCall; //!< Time from the last call (when we can manage periodic call with specifying periode) (micro-second)
|
||||
public EventTime(long timeSystem, long timeUpAppl, long timeDelta, long timeDeltaCall) {
|
||||
super();
|
||||
this.timeSystem = timeSystem;
|
||||
this.timeUpAppl = timeUpAppl;
|
||||
this.timeDelta = timeDelta;
|
||||
this.timeDeltaCall = timeDeltaCall;
|
||||
}
|
||||
public long getTimeSystem() {
|
||||
return timeSystem;
|
||||
}
|
||||
public void setTimeSystem(long timeSystem) {
|
||||
this.timeSystem = timeSystem;
|
||||
}
|
||||
public long getTimeUpAppl() {
|
||||
return timeUpAppl;
|
||||
}
|
||||
public void setTimeUpAppl(long timeUpAppl) {
|
||||
this.timeUpAppl = timeUpAppl;
|
||||
}
|
||||
public long getTimeDelta() {
|
||||
return timeDelta;
|
||||
}
|
||||
public float getTimeDeltaSecond() {
|
||||
return (float)timeDelta*0.0000001f;
|
||||
}
|
||||
public void setTimeDelta(long timeDelta) {
|
||||
this.timeDelta = timeDelta;
|
||||
}
|
||||
public long getTimeDeltaCall() {
|
||||
return timeDeltaCall;
|
||||
}
|
||||
public float getTimeDeltaCallSecond() {
|
||||
return (float)timeDeltaCall*0.0000001f;
|
||||
}
|
||||
public void setTimeDeltaCall(long timeDeltaCall) {
|
||||
this.timeDeltaCall = timeDeltaCall;
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
return "EventTime [timeSystem=" + timeSystem + "us, timeUpAppl=" + timeUpAppl + "us, timeDelta=" + timeDelta
|
||||
+ "us, timeDeltaCall=" + timeDeltaCall + "us]";
|
||||
}
|
||||
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
package org.atriaSoft.gale.key;
|
||||
|
||||
public enum Keyboard {
|
||||
public enum KeyKeyboard {
|
||||
unknow, //!< Unknown keyboard key
|
||||
character, //!< Char input is arrived ...
|
||||
left, //!< Left key <--
|
@ -1,6 +1,6 @@
|
||||
package org.atriaSoft.gale.key;
|
||||
|
||||
public class Special {
|
||||
public class KeySpecial {
|
||||
private boolean valueCapLock = false;
|
||||
private boolean valueShiftLeft = false;
|
||||
private boolean valueShiftRight = false;
|
||||
@ -15,7 +15,7 @@ public class Special {
|
||||
/**
|
||||
* @brief Main ructor
|
||||
*/
|
||||
public Special() {
|
||||
public KeySpecial() {
|
||||
|
||||
}
|
||||
/**
|
||||
@ -219,7 +219,7 @@ public class Special {
|
||||
* @param[in] move Moving key.
|
||||
* @param[in] isDown The key is pressed or not.
|
||||
*/
|
||||
public void update(Keyboard move, boolean isDown) {
|
||||
public void update(KeyKeyboard move, boolean isDown) {
|
||||
switch (move) {
|
||||
case insert:
|
||||
setInsert(isDown);
|
||||
@ -264,7 +264,7 @@ public class Special {
|
||||
* @return true The key is pressed.
|
||||
* @return false The key is released.
|
||||
*/
|
||||
public boolean get(Keyboard move) {
|
||||
public boolean get(KeyKeyboard move) {
|
||||
switch (move) {
|
||||
case insert:
|
||||
return getInsert();
|
@ -1,6 +1,6 @@
|
||||
package org.atriaSoft.gale.key;
|
||||
|
||||
public enum Status {
|
||||
public enum KeyStatus {
|
||||
unknow,
|
||||
down, // availlable on Keyboard too
|
||||
downRepeate, // availlable on Keyboard too: the down event us in repeate cycle
|
@ -1,6 +1,6 @@
|
||||
package org.atriaSoft.gale.key;
|
||||
|
||||
public enum Type {
|
||||
public enum KeyType {
|
||||
unknow, //!< Unknow input Type
|
||||
mouse, //!< Mouse type
|
||||
finger, //!< Finger type
|
@ -9,8 +9,8 @@ import org.atriaSoft.gale.context.Context;
|
||||
|
||||
public abstract class Resource {
|
||||
protected static int MAXRESOURCELEVEL = 5;
|
||||
private static int idGenerated = 0;
|
||||
protected long uid = 0; //!< unique ID definition
|
||||
private static int idGenerated = 10;
|
||||
protected long uid = -1; //!< unique ID definition
|
||||
protected int count = 1;
|
||||
protected int resourceLevel = MAXRESOURCELEVEL-1; //!< Level of the resource ==> for update priority [0..5] 0 must be update first.
|
||||
protected String name; //!< name of the resource ...
|
||||
|
@ -15,6 +15,7 @@ import org.atriaSoft.etk.math.Vector3i;
|
||||
import org.atriaSoft.gale.Log;
|
||||
import org.atriaSoft.gale.backend3d.OpenGL;
|
||||
import org.atriaSoft.gale.backend3d.OpenGL.Usage;
|
||||
import org.atriaSoft.gameEngine.Material;
|
||||
import org.lwjgl.BufferUtils;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.lwjgl.opengl.GL13;
|
||||
@ -356,7 +357,7 @@ public class ResourceProgram extends Resource {
|
||||
*/
|
||||
OpenGL.programLoadUniformMatrix(this.elementList.get(idElem).elementId, matrix, transpose);
|
||||
}
|
||||
|
||||
|
||||
public void uniformColor(int idElem, Color value) {
|
||||
if (this.exist == false) {
|
||||
return;
|
||||
@ -370,13 +371,65 @@ public class ResourceProgram extends Resource {
|
||||
}
|
||||
OpenGL.programLoadUniformColor(this.elementList.get(idElem).elementId, value);
|
||||
}
|
||||
public void uniformVector(int idElem, Vector2f value) {
|
||||
if (this.exist == false) {
|
||||
return;
|
||||
}
|
||||
if (idElem<0 || (long)idElem>this.elementList.size()) {
|
||||
Log.error("idElem = " + idElem + " not in [0.." + (this.elementList.size()-1) + "]");
|
||||
return;
|
||||
}
|
||||
if (false == this.elementList.get(idElem).isLinked) {
|
||||
return;
|
||||
}
|
||||
OpenGL.programLoadUniformVector(this.elementList.get(idElem).elementId, value);
|
||||
}
|
||||
public void uniformVector(int idElem, Vector2i value) {
|
||||
if (this.exist == false) {
|
||||
return;
|
||||
}
|
||||
if (idElem<0 || (long)idElem>this.elementList.size()) {
|
||||
Log.error("idElem = " + idElem + " not in [0.." + (this.elementList.size()-1) + "]");
|
||||
return;
|
||||
}
|
||||
if (false == this.elementList.get(idElem).isLinked) {
|
||||
return;
|
||||
}
|
||||
OpenGL.programLoadUniformVector(this.elementList.get(idElem).elementId, value);
|
||||
}
|
||||
public void uniformVector(int idElem, Vector3f value) {
|
||||
if (this.exist == false) {
|
||||
return;
|
||||
}
|
||||
if (idElem<0 || (long)idElem>this.elementList.size()) {
|
||||
Log.error("idElem = " + idElem + " not in [0.." + (this.elementList.size()-1) + "]");
|
||||
return;
|
||||
}
|
||||
if (false == this.elementList.get(idElem).isLinked) {
|
||||
return;
|
||||
}
|
||||
OpenGL.programLoadUniformVector(this.elementList.get(idElem).elementId, value);
|
||||
}
|
||||
public void uniformVector(int idElem, Vector3i value) {
|
||||
if (this.exist == false) {
|
||||
return;
|
||||
}
|
||||
if (idElem<0 || (long)idElem>this.elementList.size()) {
|
||||
Log.error("idElem = " + idElem + " not in [0.." + (this.elementList.size()-1) + "]");
|
||||
return;
|
||||
}
|
||||
if (false == this.elementList.get(idElem).isLinked) {
|
||||
return;
|
||||
}
|
||||
OpenGL.programLoadUniformVector(this.elementList.get(idElem).elementId, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Send 1 float uniform element to the spefified ID (not send if does not really exist in the openGL program)
|
||||
* @param[in] idElem Id of the uniform that might be sended.
|
||||
* @param[in] value1 Value to send at the Uniform
|
||||
*/
|
||||
public void uniform1f(int idElem, float value1){
|
||||
public void uniformFloat(int idElem, float value1){
|
||||
if (this.exist == false) {
|
||||
return;
|
||||
}
|
||||
@ -395,7 +448,7 @@ public class ResourceProgram extends Resource {
|
||||
* @param[in] value1 Value to send at the Uniform
|
||||
* @param[in] value2 Value to send at the Uniform
|
||||
*/
|
||||
public void uniform2f(int idElem, float value1, float value2) {
|
||||
public void uniformFloat(int idElem, float value1, float value2) {
|
||||
|
||||
if (this.exist == false) {
|
||||
return;
|
||||
@ -416,7 +469,7 @@ public class ResourceProgram extends Resource {
|
||||
* @param[in] value2 Value to send at the Uniform
|
||||
* @param[in] value3 Value to send at the Uniform
|
||||
*/
|
||||
public void uniform3f(int idElem, float value1, float value2, float value3){
|
||||
public void uniformFloat(int idElem, float value1, float value2, float value3){
|
||||
|
||||
if (this.exist == false) {
|
||||
return;
|
||||
@ -438,7 +491,7 @@ public class ResourceProgram extends Resource {
|
||||
* @param[in] value3 Value to send at the Uniform
|
||||
* @param[in] value4 Value to send at the Uniform
|
||||
*/
|
||||
public void uniform4f(int idElem, float value1, float value2, float value3, float value4) {
|
||||
public void uniformFloat(int idElem, float value1, float value2, float value3, float value4) {
|
||||
|
||||
if (this.exist == false) {
|
||||
return;
|
||||
@ -458,7 +511,7 @@ public class ResourceProgram extends Resource {
|
||||
* @param[in] idElem Id of the uniform that might be sended.
|
||||
* @param[in] value1 Value to send at the Uniform
|
||||
*/
|
||||
public void uniform1i(int idElem, int value1){
|
||||
public void uniformInt(int idElem, int value1){
|
||||
|
||||
if (this.exist == false) {
|
||||
return;
|
||||
@ -478,7 +531,7 @@ public class ResourceProgram extends Resource {
|
||||
* @param[in] value1 Value to send at the Uniform
|
||||
* @param[in] value2 Value to send at the Uniform
|
||||
*/
|
||||
public void uniform2i(int idElem, int value1, int value2) {
|
||||
public void uniformInt(int idElem, int value1, int value2) {
|
||||
|
||||
if (this.exist == false) {
|
||||
return;
|
||||
@ -499,7 +552,7 @@ public class ResourceProgram extends Resource {
|
||||
* @param[in] value2 Value to send at the Uniform
|
||||
* @param[in] value3 Value to send at the Uniform
|
||||
*/
|
||||
public void uniform3i(int idElem, int value1, int value2, int value3){
|
||||
public void uniformInt(int idElem, int value1, int value2, int value3){
|
||||
|
||||
if (this.exist == false) {
|
||||
return;
|
||||
@ -521,7 +574,7 @@ public class ResourceProgram extends Resource {
|
||||
* @param[in] value3 Value to send at the Uniform
|
||||
* @param[in] value4 Value to send at the Uniform
|
||||
*/
|
||||
public void uniform4i(int idElem, int value1, int value2, int value3, int value4){
|
||||
public void uniformInt(int idElem, int value1, int value2, int value3, int value4){
|
||||
|
||||
if (this.exist == false) {
|
||||
return;
|
||||
@ -536,302 +589,6 @@ public class ResourceProgram extends Resource {
|
||||
OpenGL.programLoadUniformInt(this.elementList.get(idElem).elementId, value1, value2, value3, value4);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Send "vec1" uniform element to the spefified ID (not send if does not really exist in the openGL program)
|
||||
* @param[in] idElem Id of the uniform that might be sended.
|
||||
* @param[in] nbElement Number of element sended
|
||||
* @param[in] value Pointer on the data
|
||||
*/
|
||||
// public void uniform1fv(int idElem, int nbElement, float *value){
|
||||
//
|
||||
// if (this.exist == false) {
|
||||
// return;
|
||||
// }
|
||||
// if ( idElem < 0
|
||||
// || (long)idElem > this.elementList.size()) {
|
||||
// Log.error("idElem = " + idElem + " not in [0.." + (this.elementList.size()-1) + "]");
|
||||
// return;
|
||||
// }
|
||||
// if (this.elementList.get(idElem).isLinked == false) {
|
||||
// return;
|
||||
// }
|
||||
// if (nbElement == 0) {
|
||||
// Log.error("No element to send at open GL ...");
|
||||
// return;
|
||||
// }
|
||||
// if (value == null) {
|
||||
// Log.error("null Input pointer to send at open GL ...");
|
||||
// return;
|
||||
// }
|
||||
// glUniform1fv(this.elementList.get(idElem).elementId, nbElement, value);
|
||||
// checkGlError("glUniform1fv", LINE, idElem);
|
||||
// }
|
||||
/**
|
||||
* @brief Send "Vector2f" uniform element to the spefified ID (not send if does not really exist in the openGL program)
|
||||
* @param[in] idElem Id of the uniform that might be sended.
|
||||
* @param[in] nbElement Number of element sended
|
||||
* @param[in] value Pointer on the data
|
||||
*/
|
||||
// public void uniform2fv(int idElem, int nbElement, float *value){
|
||||
//
|
||||
// if (this.exist == false) {
|
||||
// return;
|
||||
// }
|
||||
// if ( idElem < 0
|
||||
// || (long)idElem > this.elementList.size()) {
|
||||
// Log.error("idElem = " + idElem + " not in [0.." + (this.elementList.size()-1) + "]");
|
||||
// return;
|
||||
// }
|
||||
// if (this.elementList.get(idElem).isLinked == false) {
|
||||
// return;
|
||||
// }
|
||||
// if (nbElement == 0) {
|
||||
// Log.error("No element to send at open GL ...");
|
||||
// return;
|
||||
// }
|
||||
// if (value == null) {
|
||||
// Log.error("null Input pointer to send at open GL ...");
|
||||
// return;
|
||||
// }
|
||||
// glUniform2fv(this.elementList.get(idElem).elementId, nbElement, value);
|
||||
// checkGlError("glUniform2fv", LINE, idElem);
|
||||
// }
|
||||
/**
|
||||
* @brief Send "Vector3f" uniform element to the spefified ID (not send if does not really exist in the openGL program)
|
||||
* @param[in] idElem Id of the uniform that might be sended.
|
||||
* @param[in] nbElement Number of element sended
|
||||
* @param[in] value Pointer on the data
|
||||
*/
|
||||
// public void uniform3fv(int idElem, int nbElement, float *value){
|
||||
//
|
||||
// if (this.exist == false) {
|
||||
// return;
|
||||
// }
|
||||
// if ( idElem < 0
|
||||
// || (long)idElem > this.elementList.size()) {
|
||||
// Log.error("idElem = " + idElem + " not in [0.." + (this.elementList.size()-1) + "]");
|
||||
// return;
|
||||
// }
|
||||
// if (this.elementList.get(idElem).isLinked == false) {
|
||||
// return;
|
||||
// }
|
||||
// if (nbElement == 0) {
|
||||
// Log.error("No element to send at open GL ...");
|
||||
// return;
|
||||
// }
|
||||
// if (value == null) {
|
||||
// Log.error("null Input pointer to send at open GL ...");
|
||||
// return;
|
||||
// }
|
||||
// Log.verbose("[" + this.elementList.get(idElem).name + "] send " + nbElement + " Vector3f");
|
||||
// glUniform3fv(this.elementList.get(idElem).elementId, nbElement, value);
|
||||
// checkGlError("glUniform3fv", LINE, idElem);
|
||||
// }
|
||||
/**
|
||||
* @brief Send "Vector4f" uniform element to the spefified ID (not send if does not really exist in the openGL program)
|
||||
* @param[in] idElem Id of the uniform that might be sended.
|
||||
* @param[in] nbElement Number of element sended
|
||||
* @param[in] value Pointer on the data
|
||||
*/
|
||||
// public void uniform4fv(int idElem, int nbElement, float *value){
|
||||
//
|
||||
// if (this.exist == false) {
|
||||
// return;
|
||||
// }
|
||||
// if ( idElem < 0
|
||||
// || (long)idElem > this.elementList.size()) {
|
||||
// Log.error("idElem = " + idElem + " not in [0.." + (this.elementList.size()-1) + "]");
|
||||
// return;
|
||||
// }
|
||||
// if (this.elementList.get(idElem).isLinked == false) {
|
||||
// return;
|
||||
// }
|
||||
// if (nbElement == 0) {
|
||||
// Log.error("No element to send at open GL ...");
|
||||
// return;
|
||||
// }
|
||||
// if (value == null) {
|
||||
// Log.error("null Input pointer to send at open GL ...");
|
||||
// return;
|
||||
// }
|
||||
// Log.verbose("[" + this.elementList.get(idElem).name + "] send " + nbElement + " Vector4f");
|
||||
// glUniform4fv(this.elementList.get(idElem).elementId, nbElement, value);
|
||||
// checkGlError("glUniform4fv", LINE, idElem);
|
||||
// }
|
||||
|
||||
/**
|
||||
* @brief Send "ivec1" uniform element to the spefified ID (not send if does not really exist in the openGL program)
|
||||
* @param[in] idElem Id of the uniform that might be sended.
|
||||
* @param[in] nbElement Number of element sended
|
||||
* @param[in] value Pointer on the data
|
||||
*/
|
||||
// public void uniform1iv(int idElem, int nbElement, int *value){
|
||||
//
|
||||
// if (this.exist == false) {
|
||||
// return;
|
||||
// }
|
||||
// if ( idElem < 0
|
||||
// || (long)idElem > this.elementList.size()) {
|
||||
// Log.error("idElem = " + idElem + " not in [0.." + (this.elementList.size()-1) + "]");
|
||||
// return;
|
||||
// }
|
||||
// if (this.elementList.get(idElem).isLinked == false) {
|
||||
// return;
|
||||
// }
|
||||
// if (nbElement == 0) {
|
||||
// Log.error("No element to send at open GL ...");
|
||||
// return;
|
||||
// }
|
||||
// if (value == null) {
|
||||
// Log.error("null Input pointer to send at open GL ...");
|
||||
// return;
|
||||
// }
|
||||
// glUniform1iv(this.elementList.get(idElem).elementId, nbElement, value);
|
||||
// checkGlError("glUniform1iv", LINE, idElem);
|
||||
// }
|
||||
/**
|
||||
* @brief Send "Vector2i" uniform element to the spefified ID (not send if does not really exist in the openGL program)
|
||||
* @param[in] idElem Id of the Attribute that might be sended.
|
||||
* @param[in] nbElement Number of element sended
|
||||
* @param[in] value Pointer on the data
|
||||
*/
|
||||
// public void uniform2iv(int idElem, int nbElement, int *value){
|
||||
//
|
||||
// if (this.exist == false) {
|
||||
// return;
|
||||
// }
|
||||
// if ( idElem < 0
|
||||
// || (long)idElem > this.elementList.size()) {
|
||||
// Log.error("idElem = " + idElem + " not in [0.." + (this.elementList.size()-1) + "]");
|
||||
// return;
|
||||
// }
|
||||
// if (this.elementList.get(idElem).isLinked == false) {
|
||||
// return;
|
||||
// }
|
||||
// if (nbElement == 0) {
|
||||
// Log.error("No element to send at open GL ...");
|
||||
// return;
|
||||
// }
|
||||
// if (value == null) {
|
||||
// Log.error("null Input pointer to send at open GL ...");
|
||||
// return;
|
||||
// }
|
||||
// glUniform2iv(this.elementList.get(idElem).elementId, nbElement, value);
|
||||
// checkGlError("glUniform2iv", LINE, idElem);
|
||||
// }
|
||||
/**
|
||||
* @brief Send "Vector3i" uniform element to the spefified ID (not send if does not really exist in the openGL program)
|
||||
* @param[in] idElem Id of the uniform that might be sended.
|
||||
* @param[in] nbElement Number of element sended
|
||||
* @param[in] value Pointer on the data
|
||||
*/
|
||||
// public void uniform3iv(int idElem, int nbElement, int *value){
|
||||
//
|
||||
// if (this.exist == false) {
|
||||
// return;
|
||||
// }
|
||||
// if ( idElem < 0
|
||||
// || (long)idElem > this.elementList.size()) {
|
||||
// Log.error("idElem = " + idElem + " not in [0.." + (this.elementList.size()-1) + "]");
|
||||
// return;
|
||||
// }
|
||||
// if (this.elementList.get(idElem).isLinked == false) {
|
||||
// return;
|
||||
// }
|
||||
// if (nbElement == 0) {
|
||||
// Log.error("No element to send at open GL ...");
|
||||
// return;
|
||||
// }
|
||||
// if (value == null) {
|
||||
// Log.error("null Input pointer to send at open GL ...");
|
||||
// return;
|
||||
// }
|
||||
// glUniform3iv(this.elementList.get(idElem).elementId, nbElement, value);
|
||||
// checkGlError("glUniform3iv", LINE, idElem);
|
||||
// }
|
||||
/**
|
||||
* @brief Send "Vector4i" uniform element to the spefified ID (not send if does not really exist in the openGL program)
|
||||
* @param[in] idElem Id of the uniform that might be sended.
|
||||
* @param[in] nbElement Number of element sended
|
||||
* @param[in] value Pointer on the data
|
||||
*/
|
||||
// public void uniform4iv(int idElem, int nbElement, int *value){
|
||||
//
|
||||
// if (this.exist == false) {
|
||||
// return;
|
||||
// }
|
||||
// if ( idElem < 0
|
||||
// || (long)idElem > this.elementList.size()) {
|
||||
// Log.error("idElem = " + idElem + " not in [0.." + (this.elementList.size()-1) + "]");
|
||||
// return;
|
||||
// }
|
||||
// if (this.elementList.get(idElem).isLinked == false) {
|
||||
// return;
|
||||
// }
|
||||
// if (nbElement == 0) {
|
||||
// Log.error("No element to send at open GL ...");
|
||||
// return;
|
||||
// }
|
||||
// if (value == null) {
|
||||
// Log.error("null Input pointer to send at open GL ...");
|
||||
// return;
|
||||
// }
|
||||
// glUniform4iv(this.elementList.get(idElem).elementId, nbElement, value);
|
||||
// checkGlError("glUniform4iv", LINE, idElem);
|
||||
// }
|
||||
public void uniform2(int idElem, Vector2f value) {
|
||||
if (this.exist == false) {
|
||||
return;
|
||||
}
|
||||
if (idElem<0 || (long)idElem>this.elementList.size()) {
|
||||
Log.error("idElem = " + idElem + " not in [0.." + (this.elementList.size()-1) + "]");
|
||||
return;
|
||||
}
|
||||
if (false == this.elementList.get(idElem).isLinked) {
|
||||
return;
|
||||
}
|
||||
OpenGL.programLoadUniformVector(this.elementList.get(idElem).elementId, value);
|
||||
};
|
||||
public void uniform3(int idElem, Vector3f value) {
|
||||
if (this.exist == false) {
|
||||
return;
|
||||
}
|
||||
if (idElem<0 || (long)idElem>this.elementList.size()) {
|
||||
Log.error("idElem = " + idElem + " not in [0.." + (this.elementList.size()-1) + "]");
|
||||
return;
|
||||
}
|
||||
if (false == this.elementList.get(idElem).isLinked) {
|
||||
return;
|
||||
}
|
||||
OpenGL.programLoadUniformVector(this.elementList.get(idElem).elementId, value);
|
||||
};
|
||||
public void uniform2(int idElem, Vector2i value) {
|
||||
if (this.exist == false) {
|
||||
return;
|
||||
}
|
||||
if (idElem<0 || (long)idElem>this.elementList.size()) {
|
||||
Log.error("idElem = " + idElem + " not in [0.." + (this.elementList.size()-1) + "]");
|
||||
return;
|
||||
}
|
||||
if (false == this.elementList.get(idElem).isLinked) {
|
||||
return;
|
||||
}
|
||||
OpenGL.programLoadUniformVector(this.elementList.get(idElem).elementId, value);
|
||||
};
|
||||
public void uniform3(int idElem, Vector3i value) {
|
||||
if (this.exist == false) {
|
||||
return;
|
||||
}
|
||||
if (idElem<0 || (long)idElem>this.elementList.size()) {
|
||||
Log.error("idElem = " + idElem + " not in [0.." + (this.elementList.size()-1) + "]");
|
||||
return;
|
||||
}
|
||||
if (false == this.elementList.get(idElem).isLinked) {
|
||||
return;
|
||||
}
|
||||
OpenGL.programLoadUniformVector(this.elementList.get(idElem).elementId, value);
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Request the processing of this program
|
||||
*/
|
||||
@ -921,10 +678,10 @@ public class ResourceProgram extends Resource {
|
||||
OpenGL.programAttach(this.program, this.shaderFragment.getGLID());
|
||||
}
|
||||
|
||||
OpenGL.programBindAttribute(this.program, ResourceVirtualArrayObject.INDICE_VBO_POSITIONS, "position");
|
||||
OpenGL.programBindAttribute(this.program, ResourceVirtualArrayObject.INDICE_VBO_TEXTURE_COORDINATES, "textureCoords");
|
||||
OpenGL.programBindAttribute(this.program, ResourceVirtualArrayObject.INDICE_VBO_NORMALS, "normal");
|
||||
OpenGL.programBindAttribute(this.program, ResourceVirtualArrayObject.INDICE_VBO_COLORS, "colors");
|
||||
OpenGL.programBindAttribute(this.program, ResourceVirtualArrayObject.INDICE_VBO_POSITIONS, "in_position");
|
||||
OpenGL.programBindAttribute(this.program, ResourceVirtualArrayObject.INDICE_VBO_TEXTURE_COORDINATES, "tin_extureCoords");
|
||||
OpenGL.programBindAttribute(this.program, ResourceVirtualArrayObject.INDICE_VBO_NORMALS, "in_normal");
|
||||
OpenGL.programBindAttribute(this.program, ResourceVirtualArrayObject.INDICE_VBO_COLORS, "in_colors");
|
||||
|
||||
if (OpenGL.programCompile(this.program) == false) {
|
||||
Log.error("Could not compile'PROGRAM':'" + this.name + "'");
|
||||
@ -1048,4 +805,5 @@ public class ResourceProgram extends Resource {
|
||||
getManager().localAdd(resource);
|
||||
return resource;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -102,7 +102,7 @@ public class ResourceTexture extends Resource {
|
||||
@Override
|
||||
public boolean updateContext() {
|
||||
if (this.loaded == true) {
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
// Request a new texture at openGl :
|
||||
texId = GL11.glGenTextures();
|
||||
@ -222,7 +222,7 @@ public class ResourceTexture extends Resource {
|
||||
Log.critical("resource Is not correctly init : ResourceProgram" );
|
||||
return null;
|
||||
}
|
||||
getManager().localAdd(resource);
|
||||
resource.flush();
|
||||
return resource;
|
||||
}
|
||||
|
||||
|
@ -194,7 +194,7 @@ public class ResourceVirtualArrayObject extends Resource {
|
||||
* @brief This load/reload the data in the opengl context, needed when removed previously.
|
||||
*/
|
||||
public boolean updateContext() {
|
||||
//Log.verbose(" Start: [" + getId() + "] '" + getName() + "' (size=" + this.buffer.get(0).length + ")");
|
||||
//Log.verbose(" Start: [" + getId() + "] '" + getName() + "' (size=" + this.indices.length + ") ********************************");
|
||||
if (this.exist == false) {
|
||||
Log.debug(" ==> ALLOCATE new handle");
|
||||
// Allocate and assign a Vertex Array Object to our handle
|
||||
@ -233,6 +233,14 @@ public class ResourceVirtualArrayObject extends Resource {
|
||||
updateContext();
|
||||
}
|
||||
|
||||
public static ResourceVirtualArrayObject create(float[] positions, float[] colors, float[] textureCoordinates, float[] normals, int[] indices) {
|
||||
ResourceVirtualArrayObject resource = new ResourceVirtualArrayObject(positions, colors, textureCoordinates, normals, indices, indices.length);
|
||||
if (resource.resourceHasBeenCorectlyInit() == false) {
|
||||
Log.critical("resource Is not correctly init: ResourceVirtualBufferObject");
|
||||
}
|
||||
getManager().localAdd(resource);
|
||||
return resource;
|
||||
}
|
||||
public static ResourceVirtualArrayObject create(float[] positions, float[] colors, int[] indices) {
|
||||
ResourceVirtualArrayObject resource = new ResourceVirtualArrayObject(positions, colors, null, null, indices, indices.length);
|
||||
if (resource.resourceHasBeenCorectlyInit() == false) {
|
||||
|
@ -10,12 +10,12 @@ import org.atriaSoft.gale.backend3d.OpenGL;
|
||||
import org.atriaSoft.gale.context.Context;
|
||||
import org.atriaSoft.gale.resource.ResourceProgram;
|
||||
import org.atriaSoft.gale.resource.ResourceVirtualArrayObject;
|
||||
import org.atriaSoft.gale.key.Keyboard;
|
||||
import org.atriaSoft.gale.key.Special;
|
||||
import org.atriaSoft.gale.key.Status;
|
||||
import org.atriaSoft.gale.key.Type;
|
||||
import org.atriaSoft.gale.key.KeyKeyboard;
|
||||
import org.atriaSoft.gale.key.KeySpecial;
|
||||
import org.atriaSoft.gale.key.KeyStatus;
|
||||
import org.atriaSoft.gale.key.KeyType;
|
||||
|
||||
public class MainApplication extends Application {
|
||||
public class Sample1Application extends Application {
|
||||
private ResourceProgram GLprogram;
|
||||
private int GLMatrixTransformation;
|
||||
private int GLMatrixProjection;
|
||||
@ -78,7 +78,7 @@ public class MainApplication extends Application {
|
||||
// create a local matrix environnement.
|
||||
OpenGL.push();
|
||||
|
||||
Matrix4f tmpProjection = Matrix4f.createMatrixOrtho(-1, 1, -1, 1, -2, 2);
|
||||
Matrix4f tmpProjection = Matrix4f.createMatrixOrtho(-getAspectRatio(), getAspectRatio(), -1, 1, -50, 50);
|
||||
// set internal matrix system:
|
||||
OpenGL.setMatrix(tmpProjection);
|
||||
if (this.GLprogram == null) {
|
||||
@ -110,20 +110,21 @@ public class MainApplication extends Application {
|
||||
this.markDrawingIsNeeded();
|
||||
}
|
||||
@Override
|
||||
public void onPointer(Type type,
|
||||
public void onPointer(KeySpecial special,
|
||||
KeyType type,
|
||||
int pointerID,
|
||||
Vector2f pos,
|
||||
Status state) {
|
||||
KeyStatus state) {
|
||||
// Log.info("input event: type=" + type);
|
||||
// Log.info(" id=" + pointerID);
|
||||
// Log.info(" pos=" + pos);
|
||||
// Log.info(" state=" + state);
|
||||
}
|
||||
@Override
|
||||
public void onKeyboard( Special special,
|
||||
Keyboard type,
|
||||
public void onKeyboard( KeySpecial special,
|
||||
KeyKeyboard type,
|
||||
Character value,
|
||||
Status state) {
|
||||
KeyStatus state) {
|
||||
Log.info("Keyboard event: special=" + special);
|
||||
Log.info(" type=" + type);
|
||||
Log.info(" value='" + value + "'");
|
@ -5,9 +5,12 @@ precision mediump float;
|
||||
precision mediump int;
|
||||
#endif
|
||||
|
||||
// input:
|
||||
in vec4 io_color;
|
||||
|
||||
// output:
|
||||
varying vec4 f_color;
|
||||
out vec4 out_Color;
|
||||
|
||||
void main(void) {
|
||||
gl_FragColor = f_color;
|
||||
out_Color = io_color;
|
||||
}
|
||||
|
@ -6,16 +6,16 @@ precision mediump int;
|
||||
#endif
|
||||
|
||||
// Input:
|
||||
attribute vec3 position;
|
||||
attribute vec4 colors;
|
||||
uniform mat4 matrixTransformation;
|
||||
uniform mat4 matrixProjection;
|
||||
uniform mat4 matrixView;
|
||||
in vec3 in_position;
|
||||
in vec4 in_colors;
|
||||
uniform mat4 in_matrixTransformation;
|
||||
uniform mat4 in_matrixProjection;
|
||||
uniform mat4 in_matrixView;
|
||||
|
||||
// output:
|
||||
varying vec4 f_color;
|
||||
out vec4 io_color;
|
||||
|
||||
void main(void) {
|
||||
gl_Position = matrixProjection * matrixView * matrixTransformation * vec4(position, 1.0);
|
||||
f_color = colors;
|
||||
gl_Position = in_matrixProjection * in_matrixView * in_matrixTransformation * vec4(in_position, 1.0);
|
||||
f_color = in_colors;
|
||||
}
|
||||
|
@ -6,6 +6,6 @@ import org.atriaSoft.gale.Gale;
|
||||
public class sample_1 {
|
||||
public static void main(String[] args) {
|
||||
Uri.setGroup("DATA", "src/org/atriaSoft/gale/test/sample1/");
|
||||
Gale.run(new MainApplication(), args);
|
||||
Gale.run(new Sample1Application(), args);
|
||||
}
|
||||
}
|
||||
|
@ -13,12 +13,12 @@ import org.atriaSoft.gale.resource.ResourceTexture;
|
||||
import org.atriaSoft.gale.resource.ResourceVirtualArrayObject;
|
||||
import org.atriaSoft.gale.tools.ImageLoader;
|
||||
import org.atriaSoft.gale.tools.ImageRawData;
|
||||
import org.atriaSoft.gale.key.Keyboard;
|
||||
import org.atriaSoft.gale.key.Special;
|
||||
import org.atriaSoft.gale.key.Status;
|
||||
import org.atriaSoft.gale.key.Type;
|
||||
import org.atriaSoft.gale.key.KeyKeyboard;
|
||||
import org.atriaSoft.gale.key.KeySpecial;
|
||||
import org.atriaSoft.gale.key.KeyStatus;
|
||||
import org.atriaSoft.gale.key.KeyType;
|
||||
|
||||
public class MainApplication extends Application {
|
||||
public class Sample2Application extends Application {
|
||||
private ResourceProgram GLprogram;
|
||||
private int GLMatrixTransformation;
|
||||
private int GLMatrixProjection;
|
||||
@ -171,20 +171,21 @@ public class MainApplication extends Application {
|
||||
this.markDrawingIsNeeded();
|
||||
}
|
||||
@Override
|
||||
public void onPointer(Type type,
|
||||
public void onPointer(KeySpecial special,
|
||||
KeyType type,
|
||||
int pointerID,
|
||||
Vector2f pos,
|
||||
Status state) {
|
||||
KeyStatus state) {
|
||||
// Log.info("input event: type=" + type);
|
||||
// Log.info(" id=" + pointerID);
|
||||
// Log.info(" pos=" + pos);
|
||||
// Log.info(" state=" + state);
|
||||
}
|
||||
@Override
|
||||
public void onKeyboard( Special special,
|
||||
Keyboard type,
|
||||
public void onKeyboard( KeySpecial special,
|
||||
KeyKeyboard type,
|
||||
Character value,
|
||||
Status state) {
|
||||
KeyStatus state) {
|
||||
Log.info("Keyboard event: special=" + special);
|
||||
Log.info(" type=" + type);
|
||||
Log.info(" value='" + value + "'");
|
@ -5,13 +5,13 @@ precision mediump float;
|
||||
precision mediump int;
|
||||
#endif
|
||||
|
||||
in vec2 out_textureCoords;
|
||||
in vec2 io_textureCoords;
|
||||
|
||||
uniform sampler2D textureBase;
|
||||
uniform sampler2D in_textureBase;
|
||||
|
||||
// output:
|
||||
out vec4 out_Color;
|
||||
|
||||
void main(void) {
|
||||
out_Color = texture(textureBase, out_textureCoords);
|
||||
out_Color = texture(in_textureBase, io_textureCoords);
|
||||
}
|
||||
|
@ -6,16 +6,16 @@ precision mediump int;
|
||||
#endif
|
||||
|
||||
// Input:
|
||||
in vec3 position;
|
||||
in vec2 textureCoords;
|
||||
uniform mat4 matrixTransformation;
|
||||
uniform mat4 matrixProjection;
|
||||
uniform mat4 matrixView;
|
||||
in vec3 in_position;
|
||||
in vec2 in_textureCoords;
|
||||
uniform mat4 in_matrixTransformation;
|
||||
uniform mat4 in_matrixProjection;
|
||||
uniform mat4 in_matrixView;
|
||||
|
||||
// output:
|
||||
out vec2 out_textureCoords;
|
||||
out vec2 io_textureCoords;
|
||||
|
||||
void main(void) {
|
||||
gl_Position = matrixProjection * matrixView * matrixTransformation * vec4(position, 1.0);
|
||||
out_textureCoords = textureCoords;
|
||||
gl_Position = in_matrixProjection * in_matrixView * in_matrixTransformation * vec4(in_position, 1.0);
|
||||
io_textureCoords = in_textureCoords;
|
||||
}
|
||||
|
@ -6,6 +6,6 @@ import org.atriaSoft.gale.Gale;
|
||||
public class sample_2 {
|
||||
public static void main(String[] args) {
|
||||
Uri.setGroup("DATA", "src/org/atriaSoft/gale/test/sample2/");
|
||||
Gale.run(new MainApplication(), args);
|
||||
Gale.run(new Sample2Application(), args);
|
||||
}
|
||||
}
|
||||
|
125
src/org/atriaSoft/gameEngine/ControlCameraSimple.java
Normal file
125
src/org/atriaSoft/gameEngine/ControlCameraSimple.java
Normal file
@ -0,0 +1,125 @@
|
||||
package org.atriaSoft.gameEngine;
|
||||
|
||||
import org.atriaSoft.etk.math.Vector2f;
|
||||
import org.atriaSoft.gale.event.EventEntry;
|
||||
import org.atriaSoft.gale.event.EventInput;
|
||||
import org.atriaSoft.gale.event.EventTime;
|
||||
import org.atriaSoft.gale.key.KeyKeyboard;
|
||||
import org.atriaSoft.gale.key.KeyStatus;
|
||||
import org.atriaSoft.gameEngine.camera.Camera;
|
||||
|
||||
|
||||
public class ControlCameraSimple implements ControlInterface {
|
||||
private Camera camera;
|
||||
private float distanceFromCenter = 20;
|
||||
private float angleZ = 0;
|
||||
private float pitch = 0;
|
||||
private Vector2f lastMousePosition = null;
|
||||
private boolean moveUp = false;
|
||||
private boolean moveLeft = false;
|
||||
private boolean moveRight = false;
|
||||
private boolean moveDown = false;
|
||||
private boolean ctrlIsSet = false;
|
||||
|
||||
public ControlCameraSimple(Camera camera) {
|
||||
this.camera = camera;
|
||||
}
|
||||
private boolean getState(KeyStatus state, boolean previousState) {
|
||||
if (state == KeyStatus.down) {
|
||||
return true;
|
||||
}
|
||||
if (state == KeyStatus.up) {
|
||||
return false;
|
||||
}
|
||||
return previousState;
|
||||
}
|
||||
@Override
|
||||
public boolean onEventEntry(EventEntry event) {
|
||||
if(event.getType() == KeyKeyboard.up) {
|
||||
moveUp = getState(event.getStatus(), moveUp);
|
||||
}
|
||||
if(event.getType() == KeyKeyboard.left) {
|
||||
moveLeft = getState(event.getStatus(), moveLeft);
|
||||
}
|
||||
if(event.getSpecialKey().getCtrl() == false
|
||||
&& event.getType() == KeyKeyboard.right) {
|
||||
moveRight = getState(event.getStatus(), moveRight);
|
||||
}
|
||||
if(event.getSpecialKey().getCtrl() == false
|
||||
&& event.getType() == KeyKeyboard.down) {
|
||||
moveDown = getState(event.getStatus(), moveDown);
|
||||
}
|
||||
ctrlIsSet = event.getSpecialKey().getCtrl();
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onEventInput(EventInput event, Vector2f relativePosition) {
|
||||
Log.info("" + event);
|
||||
// TODO Auto-generated method stub
|
||||
if (event.getInputId() == 4) {
|
||||
if (event.getStatus() == KeyStatus.down) {
|
||||
distanceFromCenter -= 1;
|
||||
}
|
||||
} else if (event.getInputId() == 5) {
|
||||
if (event.getStatus() == KeyStatus.down) {
|
||||
distanceFromCenter += 1;
|
||||
}
|
||||
} else if (event.getInputId() == 2) {
|
||||
if (event.getStatus() == KeyStatus.down) {
|
||||
lastMousePosition = event.getPosition();
|
||||
} else if (event.getStatus() == KeyStatus.move) {
|
||||
Vector2f delta = event.getPosition().clone();
|
||||
delta.less(lastMousePosition);
|
||||
lastMousePosition = event.getPosition().clone();
|
||||
//angleZ += delta.x;
|
||||
//this.camera.setYaw(this.camera.getYaw() + (float)Math.toRadians(delta.x));
|
||||
this.camera.setPitch(this.camera.getPitch() - (float)Math.toRadians(delta.y));
|
||||
if (this.camera.getPitch()>0) {
|
||||
this.camera.setPitch(0);
|
||||
}
|
||||
if (this.camera.getPitch()<-Math.PI) {
|
||||
this.camera.setPitch((float)-Math.PI);
|
||||
}
|
||||
this.camera.setRoll(this.camera.getRoll() + (float)Math.toRadians(delta.x));
|
||||
Log.info("Change camera: " + this.camera.getYaw() + " " + this.camera.getPitch());
|
||||
if (this.camera.getRoll()>Math.PI) {
|
||||
this.camera.setRoll(this.camera.getRoll()-(float)Math.PI*2.0f);
|
||||
}
|
||||
if (this.camera.getRoll()<-Math.PI) {
|
||||
this.camera.setRoll(this.camera.getRoll()+(float)Math.PI*2.0f);
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void periodicCall(EventTime event) {
|
||||
if (moveLeft != moveRight) {
|
||||
if (moveRight) {
|
||||
camera.getPosition().x += 0.1;
|
||||
} else {
|
||||
camera.getPosition().x -= 0.1;
|
||||
}
|
||||
}
|
||||
if (ctrlIsSet == false) {
|
||||
if (moveUp != moveDown) {
|
||||
if (moveUp) {
|
||||
camera.getPosition().y += 0.1;
|
||||
} else {
|
||||
camera.getPosition().y -= 0.1;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (moveUp != moveDown) {
|
||||
if (moveUp) {
|
||||
camera.getPosition().z += 0.1;
|
||||
} else {
|
||||
camera.getPosition().z -= 0.1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
16
src/org/atriaSoft/gameEngine/ControlInterface.java
Normal file
16
src/org/atriaSoft/gameEngine/ControlInterface.java
Normal file
@ -0,0 +1,16 @@
|
||||
package org.atriaSoft.gameEngine;
|
||||
|
||||
import org.atriaSoft.etk.math.Vector2f;
|
||||
import org.atriaSoft.gale.event.EventEntry;
|
||||
import org.atriaSoft.gale.event.EventInput;
|
||||
import org.atriaSoft.gale.event.EventTime;
|
||||
|
||||
public interface ControlInterface {
|
||||
public boolean onEventEntry(EventEntry event);
|
||||
public boolean onEventInput(EventInput event, Vector2f relativePosition);
|
||||
/**
|
||||
* @brief Periodic call to update grapgic display
|
||||
* @param[in] event Time generic event
|
||||
*/
|
||||
public void periodicCall(EventTime event);
|
||||
}
|
@ -4,14 +4,13 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.atriaSoft.etk.math.Vector3f;
|
||||
import org.atriaSoft.gameEngine.camera.Camera;
|
||||
|
||||
public abstract class Entity {
|
||||
protected Environement env;
|
||||
public class Entity {
|
||||
protected Environement env = null;
|
||||
protected List<Component> component = new ArrayList<Component>();
|
||||
/**
|
||||
* @brief Constructor (when ructer is called just add Entity that did not change.
|
||||
* The objest will be stored in a pool of Entity and keep a second time if needed == > redure memory allocation,
|
||||
* The objest will be stored in a pool of Entity and keep a second time if needed == > reduce memory allocation,
|
||||
* when needed, the system will call the init and un-init function...
|
||||
*/
|
||||
public Entity(Environement env) {
|
||||
@ -29,6 +28,7 @@ public abstract class Entity {
|
||||
component.add(ref);
|
||||
env.engineComponentAdd(ref);
|
||||
for (Component it : component) {
|
||||
ref.addFriendComponent(it);
|
||||
it.addFriendComponent(ref);
|
||||
}
|
||||
Log.print("Entity: Add New component ... [END]");
|
||||
@ -81,11 +81,6 @@ public abstract class Entity {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief get the Entity Type description string.
|
||||
* @return A reference on the descriptive string.
|
||||
*/
|
||||
abstract public String getType();
|
||||
/**
|
||||
* @brief init the Entity with the defined properties
|
||||
* @param[in] property Type of the next Entity
|
||||
@ -151,7 +146,7 @@ public abstract class Entity {
|
||||
life += power;
|
||||
life = Math.min(Math.max(0.0f, life), lifeMax);
|
||||
if (life <= 0) {
|
||||
Log.debug("[" + getUID() + "] Entity is killed ..." + getType());
|
||||
Log.debug("[" + getUID() + "] Entity is killed ...");
|
||||
}
|
||||
if (life != previousLife) {
|
||||
onLifeChange();
|
||||
|
@ -5,12 +5,22 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.atriaSoft.etk.math.Vector2f;
|
||||
import org.atriaSoft.gale.backend3d.OpenGL;
|
||||
import org.atriaSoft.gale.event.EventEntry;
|
||||
import org.atriaSoft.gale.event.EventInput;
|
||||
import org.atriaSoft.gale.event.EventTime;
|
||||
import org.atriaSoft.gale.key.KeyKeyboard;
|
||||
import org.atriaSoft.gale.key.KeySpecial;
|
||||
import org.atriaSoft.gale.key.KeyStatus;
|
||||
import org.atriaSoft.gale.key.KeyType;
|
||||
import org.atriaSoft.gameEngine.camera.Camera;
|
||||
import org.atriaSoft.gameEngine.engines.EngineRender;
|
||||
import org.atriaSoft.gameEngine.engines.EngineAI;
|
||||
import org.atriaSoft.gameEngine.engines.EngineLight;
|
||||
import org.atriaSoft.gameEngine.engines.EngineParticle;
|
||||
import org.atriaSoft.gameEngine.engines.EnginePhysics;
|
||||
import org.atriaSoft.gameEngine.resource.Mesh;
|
||||
//import org.atriaSoft.gameEngine.resource.Mesh;
|
||||
|
||||
public class Environement {
|
||||
public Signal<Float> signalPlayTimeChange = new Signal<Float>();
|
||||
@ -19,11 +29,14 @@ public class Environement {
|
||||
protected List<Engine> engine = new ArrayList<Engine>(); // !< EGE sub engine interface (like physique, rendering,
|
||||
// audio, ...).
|
||||
private List<Entity> listEntity = new ArrayList<Entity>(); // !< List of all entity added in the Game
|
||||
|
||||
List<ControlInterface> controls = new ArrayList<ControlInterface>();
|
||||
long lastCallTime = 0;
|
||||
|
||||
// ! list of all camera in the world
|
||||
protected Map<String, Camera> listCamera = new HashMap<String, Camera>();
|
||||
protected long gameTime = 0; // !< time of the game running
|
||||
protected List<Mesh> listMeshToDrawFirst = new ArrayList<Mesh>();
|
||||
private long startTime;
|
||||
//protected List<Mesh> listMeshToDrawFirst = new ArrayList<Mesh>();
|
||||
|
||||
public Environement() {
|
||||
// we add the 4 classical engines (the order is used to the global rendering cycle ...
|
||||
@ -31,8 +44,37 @@ public class Environement {
|
||||
addEngine(new EngineAI(this));
|
||||
addEngine(new EngineRender(this));
|
||||
addEngine(new EngineParticle(this));
|
||||
addEngine(new EngineLight(this));
|
||||
}
|
||||
|
||||
public void addControlInterface(ControlInterface ref) {
|
||||
controls.add(ref);
|
||||
}
|
||||
public void removeControlInterface(ControlInterface ref) {
|
||||
controls.remove(ref);
|
||||
}
|
||||
|
||||
public void onPointer(KeySpecial special,
|
||||
KeyType type,
|
||||
int pointerID,
|
||||
Vector2f pos,
|
||||
KeyStatus state) {
|
||||
EventInput event = new EventInput(type, state, pointerID, pos, special);
|
||||
for (ControlInterface elem : controls) {
|
||||
elem.onEventInput(event, pos);
|
||||
}
|
||||
}
|
||||
public void onKeyboard( KeySpecial special,
|
||||
KeyKeyboard type,
|
||||
Character value,
|
||||
KeyStatus state) {
|
||||
EventEntry event = new EventEntry(special, type, state, value);
|
||||
for (ControlInterface elem : controls) {
|
||||
elem.onEventEntry(event);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void addEngine(Engine ref) {
|
||||
if (ref == null) {
|
||||
Log.error("try to add an empty Engine");
|
||||
@ -97,17 +139,18 @@ public class Environement {
|
||||
Log.error("Render: Can not get camera named: '" + cameraName + "'");
|
||||
return;
|
||||
}
|
||||
OpenGL.setCameraMatrix(camera.getConvertionMatrix());
|
||||
for (Engine it: engine) {
|
||||
Log.verbose(" render: " + it.getType());
|
||||
//Log.verbose(" render: " + it.getType());
|
||||
it.render(deltaMilli, camera);
|
||||
}
|
||||
for (Engine it: engine) {
|
||||
if(it == null) {
|
||||
continue;
|
||||
}
|
||||
Log.verbose(" render: " + it.getType());
|
||||
it.renderDebug(deltaMilli, camera);
|
||||
}
|
||||
// for (Engine it: engine) {
|
||||
// if(it == null) {
|
||||
// continue;
|
||||
// }
|
||||
// Log.verbose(" render: " + it.getType());
|
||||
// it.renderDebug(deltaMilli, camera);
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
@ -331,13 +374,13 @@ public class Environement {
|
||||
// */
|
||||
// }
|
||||
|
||||
public void addStaticMeshToDraw(Mesh mesh) {
|
||||
listMeshToDrawFirst.add(mesh);
|
||||
}
|
||||
|
||||
public List<Mesh> getStaticMeshToDraw() {
|
||||
return listMeshToDrawFirst;
|
||||
}
|
||||
// public void addStaticMeshToDraw(Mesh mesh) {
|
||||
// listMeshToDrawFirst.add(mesh);
|
||||
// }
|
||||
//
|
||||
// public List<Mesh> getStaticMeshToDraw() {
|
||||
// return listMeshToDrawFirst;
|
||||
// }
|
||||
|
||||
public GameStatus getPropertyStatus() {
|
||||
return propertyStatus;
|
||||
@ -354,6 +397,19 @@ public class Environement {
|
||||
// mperiodicCallConnection.disconnect();
|
||||
// }
|
||||
}
|
||||
|
||||
public void periodicCall() {
|
||||
if (lastCallTime == 0 ) {
|
||||
startTime = System.nanoTime()/1000;
|
||||
lastCallTime = startTime;
|
||||
}
|
||||
long lastUpdate = lastCallTime;
|
||||
lastCallTime = System.nanoTime()/1000;
|
||||
EventTime event = new EventTime(lastCallTime, lastCallTime-startTime, lastCallTime-lastUpdate, lastCallTime-lastUpdate);
|
||||
for (ControlInterface elem : controls) {
|
||||
elem.periodicCall(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
38
src/org/atriaSoft/gameEngine/Light.java
Normal file
38
src/org/atriaSoft/gameEngine/Light.java
Normal file
@ -0,0 +1,38 @@
|
||||
package org.atriaSoft.gameEngine;
|
||||
|
||||
import org.atriaSoft.etk.math.Vector3f;
|
||||
|
||||
public class Light {
|
||||
private Vector3f color;
|
||||
// A light is linked with an entity, then the entity position the object and the light have a relative position with the entity
|
||||
private Vector3f positionDelta;
|
||||
private Vector3f attenuation;
|
||||
public Light(Vector3f color, Vector3f positionDelta, Vector3f attenuation) {
|
||||
this.color = color;
|
||||
this.positionDelta = positionDelta;
|
||||
this.attenuation = attenuation;
|
||||
}
|
||||
public Light() {
|
||||
this.color = new Vector3f(1.0f,1.0f,1.0f);
|
||||
this.positionDelta = new Vector3f(0.0f,0.0f,0.0f);
|
||||
this.attenuation = new Vector3f(0.0f,0.0f,0.0f);;
|
||||
}
|
||||
public Vector3f getColor() {
|
||||
return color;
|
||||
}
|
||||
public void setColor(Vector3f color) {
|
||||
this.color = color;
|
||||
}
|
||||
public Vector3f getPositionDelta() {
|
||||
return positionDelta;
|
||||
}
|
||||
public void setPositionDelta(Vector3f positionDelta) {
|
||||
this.positionDelta = positionDelta;
|
||||
}
|
||||
public Vector3f getAttenuation() {
|
||||
return attenuation;
|
||||
}
|
||||
public void setAttenuation(Vector3f attenuation) {
|
||||
this.attenuation = attenuation;
|
||||
}
|
||||
}
|
51
src/org/atriaSoft/gameEngine/Material.java
Normal file
51
src/org/atriaSoft/gameEngine/Material.java
Normal file
@ -0,0 +1,51 @@
|
||||
package org.atriaSoft.gameEngine;
|
||||
|
||||
import org.atriaSoft.etk.math.Vector3f;
|
||||
|
||||
public class Material {
|
||||
// Minimum of the ambient value of the material (default minimum color of the element)
|
||||
private Vector3f ambientFactor;
|
||||
// Material diffuse his own color (for lights...)
|
||||
private Vector3f diffuseFactor;
|
||||
// Reflection of the lights
|
||||
private Vector3f specularFactor;
|
||||
// Distance of witch the camera must to be to receive the the reflection
|
||||
private float shininess;
|
||||
public Material(Vector3f ambientFactor, Vector3f diffuseFactor, Vector3f specularFactor, float shininess) {
|
||||
this.ambientFactor = ambientFactor;
|
||||
this.diffuseFactor = diffuseFactor;
|
||||
this.specularFactor = specularFactor;
|
||||
this.shininess = shininess;
|
||||
}
|
||||
public Material() {
|
||||
this.ambientFactor = new Vector3f(1,1,1);
|
||||
this.diffuseFactor = new Vector3f(0,0,0);
|
||||
this.specularFactor = new Vector3f(0,0,0);
|
||||
this.shininess = 1.0f;
|
||||
}
|
||||
public Vector3f getAmbientFactor() {
|
||||
return ambientFactor;
|
||||
}
|
||||
public void setAmbientFactor(Vector3f ambientFactor) {
|
||||
this.ambientFactor = ambientFactor;
|
||||
}
|
||||
public Vector3f getDiffuseFactor() {
|
||||
return diffuseFactor;
|
||||
}
|
||||
public void setDiffuseFactor(Vector3f diffuseFactor) {
|
||||
this.diffuseFactor = diffuseFactor;
|
||||
}
|
||||
public Vector3f getSpecularFactor() {
|
||||
return specularFactor;
|
||||
}
|
||||
public void setSpecularFactor(Vector3f specularFactor) {
|
||||
this.specularFactor = specularFactor;
|
||||
}
|
||||
public float getShininess() {
|
||||
return shininess;
|
||||
}
|
||||
public void setShininess(float shininess) {
|
||||
this.shininess = shininess;
|
||||
}
|
||||
|
||||
}
|
@ -1,5 +1,57 @@
|
||||
package org.atriaSoft.gameEngine.camera;
|
||||
|
||||
public class Camera {
|
||||
import org.atriaSoft.etk.math.Matrix4f;
|
||||
import org.atriaSoft.etk.math.Vector3f;
|
||||
|
||||
//import entities.Player;
|
||||
//import renderEngine.DisplayManager;
|
||||
|
||||
public class Camera {
|
||||
private Vector3f position = new Vector3f(0,0,2);
|
||||
private float pitch = 0;
|
||||
private float yaw = 0;
|
||||
private float roll = 0;
|
||||
|
||||
public Camera() {
|
||||
|
||||
}
|
||||
|
||||
public Matrix4f getConvertionMatrix() {
|
||||
Matrix4f matrix = new Matrix4f();
|
||||
matrix.setIdentity();
|
||||
matrix.rotate(new Vector3f(1,0,0), getPitch());
|
||||
matrix.rotate(new Vector3f(0,1,0), getYaw());
|
||||
matrix.rotate(new Vector3f(0,0,1), getRoll());
|
||||
matrix.translate(new Vector3f(-position.x,-position.y,-position.z));
|
||||
return matrix;
|
||||
}
|
||||
public Vector3f getPosition() {
|
||||
return position;
|
||||
}
|
||||
public void setPosition(Vector3f position) {
|
||||
this.position = position;
|
||||
}
|
||||
|
||||
public float getPitch() {
|
||||
return pitch;
|
||||
}
|
||||
|
||||
public void setPitch(float pitch) {
|
||||
this.pitch = pitch;
|
||||
}
|
||||
|
||||
public float getYaw() {
|
||||
return yaw;
|
||||
}
|
||||
public void setYaw(float yaw) {
|
||||
this.yaw = yaw;
|
||||
}
|
||||
|
||||
public float getRoll() {
|
||||
return roll;
|
||||
}
|
||||
public void setRoll(float roll) {
|
||||
this.roll = roll;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,12 +1,15 @@
|
||||
package org.atriaSoft.gameEngine.components;
|
||||
|
||||
import org.atriaSoft.gameEngine.Component;
|
||||
import org.atriaSoft.gameEngine.engines.EngineAI;
|
||||
|
||||
public class ComponentAI extends Component {
|
||||
public abstract class ComponentAI extends Component {
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
return EngineAI.ENGINE_NAME;
|
||||
}
|
||||
|
||||
public abstract void update(float timeStep);
|
||||
}
|
||||
|
41
src/org/atriaSoft/gameEngine/components/ComponentLight.java
Normal file
41
src/org/atriaSoft/gameEngine/components/ComponentLight.java
Normal file
@ -0,0 +1,41 @@
|
||||
package org.atriaSoft.gameEngine.components;
|
||||
|
||||
import org.atriaSoft.etk.math.Vector3f;
|
||||
import org.atriaSoft.gameEngine.Component;
|
||||
import org.atriaSoft.gameEngine.Light;
|
||||
|
||||
public class ComponentLight extends Component {
|
||||
// the material is not a resource, it can change in time... with AI or selection...
|
||||
private Light light;
|
||||
private ComponentPosition position;
|
||||
|
||||
public ComponentLight(Light light) {
|
||||
super();
|
||||
this.light = light;
|
||||
}
|
||||
public void addFriendComponent(Component component) {
|
||||
if (component.getType().contentEquals("position")) {
|
||||
this.position = (ComponentPosition)component;
|
||||
}
|
||||
}
|
||||
|
||||
public ComponentLight() {
|
||||
super();
|
||||
this.light = new Light();
|
||||
}
|
||||
@Override
|
||||
public String getType() {
|
||||
return "light";
|
||||
}
|
||||
public Light getLight() {
|
||||
return light;
|
||||
}
|
||||
public void setLight(Light light) {
|
||||
this.light = light;
|
||||
}
|
||||
|
||||
public Vector3f getPosition() {
|
||||
return position.getTransform().getPosition().clone().add(light.getPositionDelta());
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
package org.atriaSoft.gameEngine.components;
|
||||
|
||||
import org.atriaSoft.gameEngine.Light;
|
||||
|
||||
public class ComponentLightSun extends ComponentLight{
|
||||
|
||||
public ComponentLightSun() {
|
||||
super();
|
||||
}
|
||||
|
||||
public ComponentLightSun(Light light) {
|
||||
super(light);
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public String getType() {
|
||||
// return "sun";
|
||||
// }
|
||||
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
package org.atriaSoft.gameEngine.components;
|
||||
|
||||
import org.atriaSoft.gameEngine.Component;
|
||||
import org.atriaSoft.gameEngine.Material;
|
||||
|
||||
public class ComponentMaterial extends Component {
|
||||
// the material is not a resource, it can change in time... with AI or selection...
|
||||
private Material material;
|
||||
|
||||
public ComponentMaterial(Material material) {
|
||||
super();
|
||||
this.material = material;
|
||||
}
|
||||
|
||||
public ComponentMaterial() {
|
||||
super();
|
||||
this.material = new Material();
|
||||
}
|
||||
@Override
|
||||
public String getType() {
|
||||
return "material";
|
||||
}
|
||||
public Material getMaterial() {
|
||||
return material;
|
||||
}
|
||||
public void setMaterial(Material material) {
|
||||
this.material = material;
|
||||
}
|
||||
|
||||
}
|
@ -1,12 +1,13 @@
|
||||
package org.atriaSoft.gameEngine.components;
|
||||
|
||||
import org.atriaSoft.gameEngine.Component;
|
||||
import org.atriaSoft.gameEngine.engines.EngineParticle;
|
||||
|
||||
public class ComponentParticle extends Component {
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
return EngineParticle.ENGINE_NAME;
|
||||
}
|
||||
}
|
||||
|
@ -1,13 +1,21 @@
|
||||
package org.atriaSoft.gameEngine.components;
|
||||
|
||||
import org.atriaSoft.gameEngine.Component;
|
||||
import org.atriaSoft.gameEngine.engines.EngineRender;
|
||||
|
||||
public class ComponentRender extends Component {
|
||||
public abstract class ComponentRender extends Component {
|
||||
private boolean propertyDebugNormal = false;
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
return EngineRender.ENGINE_NAME;
|
||||
}
|
||||
|
||||
public void setPropertyDebugNormal(boolean value) {
|
||||
this.propertyDebugNormal = value;
|
||||
}
|
||||
public boolean getPropertyDebugNormal() {
|
||||
return this.propertyDebugNormal;
|
||||
}
|
||||
public abstract void render();
|
||||
}
|
||||
|
@ -0,0 +1,63 @@
|
||||
|
||||
|
||||
package org.atriaSoft.gameEngine.components;
|
||||
|
||||
import org.atriaSoft.etk.Uri;
|
||||
import org.atriaSoft.etk.math.Matrix4f;
|
||||
import org.atriaSoft.gale.backend3d.OpenGL;
|
||||
import org.atriaSoft.gale.resource.ResourceProgram;
|
||||
import org.atriaSoft.gameEngine.Component;
|
||||
|
||||
public class ComponentRenderColoredStaticMesh extends ComponentRender {
|
||||
ComponentStaticMesh mesh = null;
|
||||
ComponentPosition position = null;
|
||||
ResourceProgram program = null;
|
||||
private int GLMatrixTransformation;
|
||||
private int GLMatrixProjection;
|
||||
private int GLMatrixView;
|
||||
|
||||
public ComponentRenderColoredStaticMesh(Uri vertexShader, Uri fragmentShader) {
|
||||
this.program = ResourceProgram.create(vertexShader, fragmentShader);
|
||||
if (this.program != null) {
|
||||
this.GLMatrixTransformation = this.program.getUniform("in_matrixTransformation");
|
||||
this.GLMatrixProjection = this.program.getUniform("in_matrixProjection");
|
||||
this.GLMatrixView = this.program.getUniform("in_matrixView");
|
||||
}
|
||||
|
||||
}
|
||||
@Override
|
||||
public void addFriendComponent(Component component) {
|
||||
if (component.getType().contentEquals("static-mesh")) {
|
||||
mesh = (ComponentStaticMesh)component;
|
||||
}
|
||||
if (component.getType().contentEquals("position")) {
|
||||
position = (ComponentPosition)component;
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void removeFriendComponent(Component component) {
|
||||
// nothing to do.
|
||||
}
|
||||
@Override
|
||||
public void render() {
|
||||
this.program.use();
|
||||
|
||||
Matrix4f projectionMatrix = OpenGL.getMatrix();
|
||||
Matrix4f viewMatrix = OpenGL.getCameraMatrix();
|
||||
Matrix4f transformationMatrix = position.getTransform().getOpenGLMatrix();
|
||||
this.mesh.bindForRendering();
|
||||
|
||||
this.program.uniformMatrix(this.GLMatrixView, viewMatrix);
|
||||
this.program.uniformMatrix(this.GLMatrixProjection, projectionMatrix);
|
||||
// Change the position for each element with the same pipeline you need to render ...
|
||||
this.program.uniformMatrix(this.GLMatrixTransformation, transformationMatrix);
|
||||
// update of flags is done asyncronously ==> need update befor drawing...
|
||||
OpenGL.updateAllFlags();
|
||||
// Request the draw od the elements:
|
||||
this.mesh.render();
|
||||
|
||||
this.mesh.unBindForRendering();
|
||||
|
||||
this.program.unUse();
|
||||
}
|
||||
}
|
@ -0,0 +1,118 @@
|
||||
package org.atriaSoft.gameEngine.components;
|
||||
|
||||
import org.atriaSoft.etk.Uri;
|
||||
import org.atriaSoft.etk.math.Matrix4f;
|
||||
import org.atriaSoft.etk.math.Vector3f;
|
||||
import org.atriaSoft.gale.backend3d.OpenGL;
|
||||
import org.atriaSoft.gale.resource.ResourceProgram;
|
||||
import org.atriaSoft.gameEngine.Component;
|
||||
import org.atriaSoft.gameEngine.Light;
|
||||
import org.atriaSoft.gameEngine.Material;
|
||||
import org.atriaSoft.gameEngine.engines.EngineLight;
|
||||
class GlLightIndex {
|
||||
int GLcolor;
|
||||
int GLposition;
|
||||
int GLattenuation;
|
||||
public GlLightIndex(int gLcolor, int gLposition, int gLattenuation) {
|
||||
GLcolor = gLcolor;
|
||||
GLposition = gLposition;
|
||||
GLattenuation = gLattenuation;
|
||||
}
|
||||
}
|
||||
public class ComponentRenderTexturedMaterialsStaticMesh extends ComponentRender {
|
||||
private static final int numberOfLight = 8;
|
||||
ComponentStaticMesh mesh = null;
|
||||
ComponentTexture texture = null;
|
||||
ComponentMaterial material = null;
|
||||
ComponentPosition position = null;
|
||||
ResourceProgram program = null;
|
||||
EngineLight lightEngine;
|
||||
private int GLMatrixTransformation;
|
||||
private int GLMatrixProjection;
|
||||
private int GLMatrixView;
|
||||
private int GLambientFactor;
|
||||
private int GLdiffuseFactor;
|
||||
private int GLspecularFactor;
|
||||
private int GLshininess;
|
||||
private GlLightIndex[] GLlights;
|
||||
|
||||
public ComponentRenderTexturedMaterialsStaticMesh(Uri vertexShader, Uri fragmentShader, EngineLight lightEngine) {
|
||||
this.lightEngine = lightEngine;
|
||||
this.program = ResourceProgram.create(vertexShader, fragmentShader);
|
||||
if (this.program != null) {
|
||||
this.GLMatrixTransformation = this.program.getUniform("in_matrixTransformation");
|
||||
this.GLMatrixProjection = this.program.getUniform("in_matrixProjection");
|
||||
this.GLMatrixView = this.program.getUniform("in_matrixView");
|
||||
this.GLambientFactor = this.program.getUniform("in_material.ambientFactor");
|
||||
this.GLdiffuseFactor = this.program.getUniform("in_material.diffuseFactor");
|
||||
this.GLspecularFactor = this.program.getUniform("in_material.specularFactor");
|
||||
this.GLshininess = this.program.getUniform("in_material.shininess");
|
||||
this.GLlights = new GlLightIndex[numberOfLight];
|
||||
for (int iii=0; iii<numberOfLight; iii++) {
|
||||
int color = this.program.getUniform("in_lights[" + iii + "].color");
|
||||
int position = this.program.getUniform("in_lights[" + iii + "].position");
|
||||
int attenuation = this.program.getUniform("in_lights[" + iii + "].attenuation");
|
||||
this.GLlights[iii] = new GlLightIndex(color, position, attenuation);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@Override
|
||||
public void addFriendComponent(Component component) {
|
||||
if (component.getType().contentEquals("static-mesh")) {
|
||||
mesh = (ComponentStaticMesh)component;
|
||||
}
|
||||
if (component.getType().contentEquals("texture")) {
|
||||
texture = (ComponentTexture)component;
|
||||
}
|
||||
if (component.getType().contentEquals("material")) {
|
||||
material = (ComponentMaterial)component;
|
||||
}
|
||||
if (component.getType().contentEquals("position")) {
|
||||
position = (ComponentPosition)component;
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void removeFriendComponent(Component component) {
|
||||
// nothing to do.
|
||||
}
|
||||
@Override
|
||||
public void render() {
|
||||
this.program.use();
|
||||
Light[] lights = this.lightEngine.getNearest(position.getTransform().getPosition());
|
||||
Matrix4f projectionMatrix = OpenGL.getMatrix();
|
||||
Matrix4f viewMatrix = OpenGL.getCameraMatrix();
|
||||
Matrix4f transformationMatrix = position.getTransform().getOpenGLMatrix();
|
||||
this.mesh.bindForRendering();
|
||||
this.texture.bindForRendering();
|
||||
|
||||
Material mat = this.material.getMaterial();
|
||||
this.program.uniformVector(GLambientFactor, mat.getAmbientFactor());
|
||||
this.program.uniformVector(GLdiffuseFactor, mat.getDiffuseFactor());
|
||||
this.program.uniformVector(GLspecularFactor, mat.getSpecularFactor());
|
||||
this.program.uniformFloat(GLshininess, mat.getShininess());
|
||||
for (int iii=0; iii<numberOfLight; iii++) {
|
||||
if (lights[iii] != null) {
|
||||
this.program.uniformVector(this.GLlights[iii].GLposition, lights[iii].getPositionDelta());
|
||||
this.program.uniformVector(this.GLlights[iii].GLcolor, lights[iii].getColor());
|
||||
this.program.uniformVector(this.GLlights[iii].GLattenuation, lights[iii].getAttenuation());
|
||||
} else {
|
||||
this.program.uniformVector(this.GLlights[iii].GLposition, new Vector3f(0,0,0));
|
||||
this.program.uniformVector(this.GLlights[iii].GLcolor, new Vector3f(0,0,0));
|
||||
this.program.uniformVector(this.GLlights[iii].GLattenuation, new Vector3f(1,0,0));
|
||||
}
|
||||
}
|
||||
this.program.uniformMatrix(this.GLMatrixView, viewMatrix);
|
||||
this.program.uniformMatrix(this.GLMatrixProjection, projectionMatrix);
|
||||
// Change the position for each element with the same pipeline you need to render ...
|
||||
this.program.uniformMatrix(this.GLMatrixTransformation, transformationMatrix);
|
||||
// update of flags is done asynchronously ==> need update before drawing...
|
||||
OpenGL.updateAllFlags();
|
||||
// Request the draw all the elements:
|
||||
this.mesh.render();
|
||||
this.texture.unBindForRendering();
|
||||
this.mesh.unBindForRendering();
|
||||
this.program.unUse();
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,64 @@
|
||||
package org.atriaSoft.gameEngine.components;
|
||||
|
||||
import org.atriaSoft.etk.Uri;
|
||||
import org.atriaSoft.etk.math.Matrix4f;
|
||||
import org.atriaSoft.gale.backend3d.OpenGL;
|
||||
import org.atriaSoft.gale.resource.ResourceProgram;
|
||||
import org.atriaSoft.gameEngine.Component;
|
||||
|
||||
public class ComponentRenderTexturedStaticMesh extends ComponentRender {
|
||||
ComponentStaticMesh mesh = null;
|
||||
ComponentTexture texture = null;
|
||||
ComponentPosition position = null;
|
||||
ResourceProgram program = null;
|
||||
private int GLMatrixTransformation;
|
||||
private int GLMatrixProjection;
|
||||
private int GLMatrixView;
|
||||
|
||||
public ComponentRenderTexturedStaticMesh(Uri vertexShader, Uri fragmentShader) {
|
||||
this.program = ResourceProgram.create(vertexShader, fragmentShader);
|
||||
if (this.program != null) {
|
||||
this.GLMatrixTransformation = this.program.getUniform("in_matrixTransformation");
|
||||
this.GLMatrixProjection = this.program.getUniform("in_matrixProjection");
|
||||
this.GLMatrixView = this.program.getUniform("in_matrixView");
|
||||
}
|
||||
|
||||
}
|
||||
@Override
|
||||
public void addFriendComponent(Component component) {
|
||||
if (component.getType().contentEquals("static-mesh")) {
|
||||
mesh = (ComponentStaticMesh)component;
|
||||
}
|
||||
if (component.getType().contentEquals("texture")) {
|
||||
texture = (ComponentTexture)component;
|
||||
}
|
||||
if (component.getType().contentEquals("position")) {
|
||||
position = (ComponentPosition)component;
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void removeFriendComponent(Component component) {
|
||||
// nothing to do.
|
||||
}
|
||||
@Override
|
||||
public void render() {
|
||||
this.program.use();
|
||||
Matrix4f projectionMatrix = OpenGL.getMatrix();
|
||||
Matrix4f viewMatrix = OpenGL.getCameraMatrix();
|
||||
Matrix4f transformationMatrix = position.getTransform().getOpenGLMatrix();
|
||||
this.mesh.bindForRendering();
|
||||
this.texture.bindForRendering();
|
||||
this.program.uniformMatrix(this.GLMatrixView, viewMatrix);
|
||||
this.program.uniformMatrix(this.GLMatrixProjection, projectionMatrix);
|
||||
// Change the position for each element with the same pipeline you need to render ...
|
||||
this.program.uniformMatrix(this.GLMatrixTransformation, transformationMatrix);
|
||||
// update of flags is done asynchronously ==> need update before drawing...
|
||||
OpenGL.updateAllFlags();
|
||||
// Request the draw all the elements:
|
||||
this.mesh.render();
|
||||
this.texture.unBindForRendering();
|
||||
this.mesh.unBindForRendering();
|
||||
this.program.unUse();
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,49 @@
|
||||
package org.atriaSoft.gameEngine.components;
|
||||
|
||||
import org.atriaSoft.etk.Uri;
|
||||
import org.atriaSoft.gameEngine.Component;
|
||||
import org.atriaSoft.gameEngine.resource.ResourceStaticMesh;
|
||||
import org.atriaSoft.gameEngine.resource.ResourceStaticMeshObj;
|
||||
|
||||
public class ComponentStaticMesh extends Component {
|
||||
private ResourceStaticMesh mesh = null;
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
// TODO Auto-generated method stub
|
||||
return "static-mesh";
|
||||
}
|
||||
|
||||
public ComponentStaticMesh(Uri objectFileName) {
|
||||
// TODO: check if it is OBJ ...
|
||||
mesh = ResourceStaticMeshObj.create(objectFileName);
|
||||
}
|
||||
public ComponentStaticMesh(ResourceStaticMesh mesh) {
|
||||
this.mesh = mesh;
|
||||
}
|
||||
|
||||
public ResourceStaticMesh getMesh() {
|
||||
return mesh;
|
||||
}
|
||||
|
||||
public void bindForRendering() {
|
||||
if (mesh == null) {
|
||||
return;
|
||||
}
|
||||
mesh.bindForRendering();
|
||||
}
|
||||
|
||||
public void unBindForRendering() {
|
||||
if (mesh == null) {
|
||||
return;
|
||||
}
|
||||
mesh.unBindForRendering();
|
||||
}
|
||||
|
||||
public void render() {
|
||||
if (mesh == null) {
|
||||
return;
|
||||
}
|
||||
mesh.render();
|
||||
}
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
package org.atriaSoft.gameEngine.components;
|
||||
|
||||
import org.atriaSoft.etk.Uri;
|
||||
import org.atriaSoft.gale.resource.ResourceTexture;
|
||||
import org.atriaSoft.gale.test.sample2.Log;
|
||||
import org.atriaSoft.gameEngine.Component;
|
||||
|
||||
public class ComponentTexture extends Component {
|
||||
|
||||
private ResourceTexture texture;
|
||||
@Override
|
||||
public String getType() {
|
||||
// TODO Auto-generated method stub
|
||||
return "texture";
|
||||
}
|
||||
public ComponentTexture(Uri textureName) {
|
||||
this.texture = ResourceTexture.createFromPng(textureName);
|
||||
if (this.texture == null) {
|
||||
Log.error("can not instanciate Texture ...");
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
public void bindForRendering() {
|
||||
this.texture.bindForRendering(0);
|
||||
|
||||
}
|
||||
public void unBindForRendering() {
|
||||
this.texture.unBindForRendering();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package org.atriaSoft.gameEngine.components;
|
||||
|
||||
import org.atriaSoft.gameEngine.Component;
|
||||
|
||||
public class ComponentTexturePack extends Component {
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
// TODO Auto-generated method stub
|
||||
return "texture-pack";
|
||||
}
|
||||
|
||||
}
|
@ -7,6 +7,6 @@ public class CoponentPhysics extends Component {
|
||||
@Override
|
||||
public String getType() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
return "physics";
|
||||
}
|
||||
}
|
||||
|
16
src/org/atriaSoft/gameEngine/data/wireColor.frag
Normal file
16
src/org/atriaSoft/gameEngine/data/wireColor.frag
Normal file
@ -0,0 +1,16 @@
|
||||
#version 400 core
|
||||
|
||||
#ifdef GL_ES
|
||||
precision mediump float;
|
||||
precision mediump int;
|
||||
#endif
|
||||
|
||||
in vec4 io_color;
|
||||
|
||||
// output:
|
||||
out vec4 out_Color;
|
||||
|
||||
void main(void) {
|
||||
out_Color = vec4(1.0,0.0,0.0,1.0);
|
||||
// io_color;
|
||||
}
|
21
src/org/atriaSoft/gameEngine/data/wireColor.vert
Normal file
21
src/org/atriaSoft/gameEngine/data/wireColor.vert
Normal file
@ -0,0 +1,21 @@
|
||||
#version 400 core
|
||||
|
||||
#ifdef GL_ES
|
||||
precision mediump float;
|
||||
precision mediump int;
|
||||
#endif
|
||||
|
||||
// Input:
|
||||
in vec3 in_position;
|
||||
in vec4 in_colors;
|
||||
uniform mat4 in_matrixTransformation;
|
||||
uniform mat4 in_matrixProjection;
|
||||
uniform mat4 in_matrixView;
|
||||
|
||||
// output:
|
||||
out vec4 io_color;
|
||||
|
||||
void main(void) {
|
||||
gl_Position = in_matrixProjection * in_matrixView * in_matrixTransformation * vec4(in_position, 1.0);
|
||||
io_color = in_colors;
|
||||
}
|
@ -1,12 +1,19 @@
|
||||
package org.atriaSoft.gameEngine.engines;
|
||||
|
||||
import java.util.Vector;
|
||||
|
||||
import org.atriaSoft.gameEngine.Component;
|
||||
import org.atriaSoft.gameEngine.Engine;
|
||||
import org.atriaSoft.gameEngine.Environement;
|
||||
import org.atriaSoft.gameEngine.Log;
|
||||
import org.atriaSoft.gameEngine.camera.Camera;
|
||||
import org.atriaSoft.gameEngine.components.ComponentAI;
|
||||
|
||||
public class EngineAI extends Engine {
|
||||
|
||||
public static final String ENGINE_NAME = "ia";
|
||||
private float accumulator = 0;
|
||||
private static float TIME_STEP = 5.0f;
|
||||
private Vector<ComponentAI> components;
|
||||
public EngineAI(Environement env) {
|
||||
super(env);
|
||||
// TODO Auto-generated constructor stub
|
||||
@ -14,38 +21,48 @@ public class EngineAI extends Engine {
|
||||
|
||||
@Override
|
||||
public void componentRemove(Component ref) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
components.remove(ref);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void componentAdd(Component ref) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
if (ref instanceof ComponentAI == false) {
|
||||
return;
|
||||
}
|
||||
components.add((ComponentAI)ref);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(long deltaMili) {
|
||||
// TODO Auto-generated method stub
|
||||
// Add the time difference in the accumulator
|
||||
accumulator += (float)deltaMili*0.0001f;
|
||||
// While there is enough accumulated time to take one or several physics steps
|
||||
while (accumulator >= TIME_STEP) {
|
||||
Log.warning("Generate for " + accumulator + " / " + TIME_STEP + " for:" + components.size());
|
||||
// call every object to usdate their constant forces applyed
|
||||
for (ComponentAI it: components) {
|
||||
it.update(TIME_STEP);
|
||||
}
|
||||
// Decrease the accumulated time
|
||||
accumulator -= TIME_STEP;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(long deltaMili, Camera camera) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
// nothing to do ...
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderDebug(long deltaMili, Camera camera) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
// nothing to do ...
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
return ENGINE_NAME;
|
||||
}
|
||||
|
||||
}
|
||||
|
82
src/org/atriaSoft/gameEngine/engines/EngineLight.java
Normal file
82
src/org/atriaSoft/gameEngine/engines/EngineLight.java
Normal file
@ -0,0 +1,82 @@
|
||||
package org.atriaSoft.gameEngine.engines;
|
||||
|
||||
import java.util.Vector;
|
||||
|
||||
import org.atriaSoft.etk.math.Vector3f;
|
||||
import org.atriaSoft.gameEngine.Component;
|
||||
import org.atriaSoft.gameEngine.Engine;
|
||||
import org.atriaSoft.gameEngine.Environement;
|
||||
import org.atriaSoft.gameEngine.Light;
|
||||
import org.atriaSoft.gameEngine.Log;
|
||||
import org.atriaSoft.gameEngine.camera.Camera;
|
||||
import org.atriaSoft.gameEngine.components.ComponentAI;
|
||||
import org.atriaSoft.gameEngine.components.ComponentLight;
|
||||
import org.atriaSoft.gameEngine.components.ComponentLightSun;
|
||||
|
||||
public class EngineLight extends Engine {
|
||||
public static final String ENGINE_NAME = "light";
|
||||
private Vector<ComponentLight> componentLights = new Vector<ComponentLight>();
|
||||
private Vector<ComponentLightSun> componentSuns = new Vector<ComponentLightSun>();
|
||||
public EngineLight(Environement env) {
|
||||
super(env);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
@Override
|
||||
public void componentRemove(Component ref) {
|
||||
componentLights.remove(ref);
|
||||
componentSuns.remove(ref);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void componentAdd(Component ref) {
|
||||
if (ref instanceof ComponentLightSun == true) {
|
||||
componentSuns.add((ComponentLightSun)ref);
|
||||
return;
|
||||
}
|
||||
if (ref instanceof ComponentLight == true) {
|
||||
componentLights.add((ComponentLight)ref);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(long deltaMili) {
|
||||
// nothing to do ...
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(long deltaMili, Camera camera) {
|
||||
// nothing to do ...
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderDebug(long deltaMili, Camera camera) {
|
||||
// nothing to do ...
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
// TODO Auto-generated method stub
|
||||
return ENGINE_NAME;
|
||||
}
|
||||
|
||||
public Light[] getNearest(Vector3f position) {
|
||||
Light[] out = new Light[8];
|
||||
int count = 0;
|
||||
for (ComponentLightSun elem: componentSuns) {
|
||||
out[count] = new Light(elem.getLight().getColor(), elem.getPosition(), elem.getLight().getAttenuation());
|
||||
count++;
|
||||
}
|
||||
float maxDistance = 50*50;
|
||||
for (ComponentLight elem: componentLights) {
|
||||
Vector3f pos = elem.getPosition();
|
||||
if (pos.distance2(position) < maxDistance) {
|
||||
out[count] = new Light(elem.getLight().getColor(), pos, elem.getLight().getAttenuation());
|
||||
count++;
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
}
|
@ -6,6 +6,7 @@ import org.atriaSoft.gameEngine.Environement;
|
||||
import org.atriaSoft.gameEngine.camera.Camera;
|
||||
|
||||
public class EngineParticle extends Engine {
|
||||
public static final String ENGINE_NAME = "particle";
|
||||
|
||||
public EngineParticle(Environement env) {
|
||||
super(env);
|
||||
@ -45,7 +46,7 @@ public class EngineParticle extends Engine {
|
||||
@Override
|
||||
public String getType() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
return ENGINE_NAME;
|
||||
}
|
||||
|
||||
|
||||
|
@ -6,6 +6,7 @@ import org.atriaSoft.gameEngine.Environement;
|
||||
import org.atriaSoft.gameEngine.camera.Camera;
|
||||
|
||||
public class EnginePhysics extends Engine {
|
||||
public static final String ENGINE_NAME = "physics";
|
||||
|
||||
public EnginePhysics(Environement env) {
|
||||
super(env);
|
||||
@ -45,7 +46,7 @@ public class EnginePhysics extends Engine {
|
||||
@Override
|
||||
public String getType() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
return ENGINE_NAME;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,12 +1,24 @@
|
||||
package org.atriaSoft.gameEngine.engines;
|
||||
|
||||
import java.util.Vector;
|
||||
|
||||
import org.atriaSoft.gale.test.sample2.Log;
|
||||
import org.atriaSoft.gameEngine.Component;
|
||||
import org.atriaSoft.gameEngine.Engine;
|
||||
import org.atriaSoft.gameEngine.Environement;
|
||||
import org.atriaSoft.gameEngine.camera.Camera;
|
||||
import org.atriaSoft.gameEngine.components.ComponentRender;
|
||||
|
||||
class ResultNearestElement {
|
||||
public ComponentRender element;
|
||||
public float dist;
|
||||
};
|
||||
|
||||
public class EngineRender extends Engine {
|
||||
|
||||
public static final String ENGINE_NAME = "render";
|
||||
private Vector<ComponentRender> components = new Vector<ComponentRender>();
|
||||
private Vector<ResultNearestElement> displayElementOrdered = new Vector<ResultNearestElement>();
|
||||
//private ResourceColored3DObject debugDrawProperty;
|
||||
public EngineRender(Environement env) {
|
||||
super(env);
|
||||
// TODO Auto-generated constructor stub
|
||||
@ -14,14 +26,15 @@ public class EngineRender extends Engine {
|
||||
|
||||
@Override
|
||||
public void componentRemove(Component ref) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
components.remove(ref);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void componentAdd(Component ref) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
if (ref instanceof ComponentRender == false) {
|
||||
return;
|
||||
}
|
||||
components.add((ComponentRender)ref);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -32,8 +45,73 @@ public class EngineRender extends Engine {
|
||||
|
||||
@Override
|
||||
public void render(long deltaMili, Camera camera) {
|
||||
// TODO Auto-generated method stub
|
||||
//Matrix4f tmpMatrix;
|
||||
for (ComponentRender it: this.components) {
|
||||
//Log.info("Render " + it);
|
||||
it.render();
|
||||
}
|
||||
/*
|
||||
getOrderedElementForDisplay(this.displayElementOrdered, camera->getEye(), camera->getViewVector());
|
||||
Log.verbose("DRAW : " + this.displayElementOrdered.size() + "/" + this.component.size() + " elements");
|
||||
|
||||
// note : the first pass is done at the reverse way to prevent multiple display od the same point in the screen
|
||||
// (and we remember that the first pass is to display all the non transparent elements)
|
||||
for (int32t iii=this.displayElementOrdered.size()-1; iii >= 0; iii--) {
|
||||
this.displayElementOrdered[iii].element->draw(0);
|
||||
}
|
||||
// for the other pass the user can draw transparent elements ...
|
||||
for (int32t pass=1; pass <= NUMBEROFSUBPASS+1; pass++) {
|
||||
for (auto &it: this.displayElementOrdered) {
|
||||
it.element->draw(pass);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public void renderDebug(long deltaMili, Camera camera) {
|
||||
// //Log.debug("Draw (start)");
|
||||
// Matrix4f tmpMatrix;
|
||||
// getOrderedElementForDisplay(this.displayElementOrdered, camera->getEye(), camera->getViewVector());
|
||||
// Log.verbose("DRAW : " + this.displayElementOrdered.size() + "/" + this.component.size() + " elements");
|
||||
//// if (propertyDebugPhysic.get() == true) {
|
||||
//// // Draw debug ... (Object)
|
||||
//// for (int32t iii=this.displayElementOrdered.size()-1; iii >= 0; iii--) {
|
||||
//// this.displayElementOrdered[iii].element->drawDebug(this.debugDrawProperty, camera);
|
||||
//// }
|
||||
//// // Draw debug ... (Camera)
|
||||
//// /*
|
||||
//// etk::Map<etk::String, ege::Camera>> listCamera = this.env->getCameraList();
|
||||
//// for (auto &itCam : listCamera) {
|
||||
//// if (itCam.second != null) {
|
||||
//// itCam.second->drawDebug(this.debugDrawProperty, camera);
|
||||
//// }
|
||||
//// }
|
||||
//// */
|
||||
//// }
|
||||
// if (propertyDebugNormal.get() == true) {
|
||||
// // Draw debug ... (Object)
|
||||
// for (int32t iii=this.displayElementOrdered.size()-1; iii >= 0; iii--) {
|
||||
// this.displayElementOrdered[iii].element.drawNormalDebug(this.debugDrawProperty);
|
||||
// }
|
||||
// }
|
||||
//// if (propertyDebugApplication.get() == true) {
|
||||
//// // Draw debug ... (User)
|
||||
//// signalDisplayDebug.emit(this.debugDrawProperty);
|
||||
//// }
|
||||
//// /* TODO: set it back ...
|
||||
//// if (camera != null) {
|
||||
//// this.env->getParticuleEngine().draw(*camera);
|
||||
//// }
|
||||
//// */
|
||||
//
|
||||
// }
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
// TODO Auto-generated method stub
|
||||
return ENGINE_NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -42,10 +120,56 @@ public class EngineRender extends Engine {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
// //ResourceColored3DObject debugDrawProperty;
|
||||
// void getOrderedElementForDisplay(etk::Vector<ege::render::Engine::ResultNearestElement>& resultList,
|
||||
// const vec3& position,
|
||||
// const vec3& direction) {
|
||||
// // TODO : Set it back ... corrected...
|
||||
// // remove all unneeded elements (old display...)
|
||||
// resultList.clear();
|
||||
// // basic element result
|
||||
// ege::render::Engine::ResultNearestElement result;
|
||||
// result.dist = 99999999999.0f;
|
||||
// result.element = null;
|
||||
// // for all element in the game we chek if it is needed to display it ...
|
||||
// for (ComponentRender it: this.components) {
|
||||
// // check null pointer
|
||||
// if (it == null) {
|
||||
// // no pointer null are set in the output list ...
|
||||
// continue;
|
||||
// }
|
||||
// result.element = it;
|
||||
// // check distance ...
|
||||
// vec3 destPosition = result.element->getTransform().getPosition();
|
||||
// vec3 angleView = (destPosition - position);
|
||||
// angleView.safeNormalize();
|
||||
// float dotResult = angleView.dot(direction);
|
||||
// //Log.debug("Dot position : " + destPosition + " == > dot=" + dotResult);
|
||||
// /*
|
||||
// if (dotResult <= 0.85f) {
|
||||
// // they are not in the camera angle view ... == > no need to process display
|
||||
// continue;
|
||||
// }
|
||||
// */
|
||||
// result.dist = (position - destPosition).length();
|
||||
// /*
|
||||
// if (result.dist>500.0f) {
|
||||
// // The element is realy too far ... == > no need to display
|
||||
// continue;
|
||||
// }
|
||||
// */
|
||||
// // try to add the element at the best positions:
|
||||
// sizet jjj;
|
||||
// for (jjj=0; jjj<resultList.size(); jjj++) {
|
||||
// if (resultList[jjj].dist>result.dist) {
|
||||
// resultList.insert(resultList.begin()+jjj, result);
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// // add element at the end :
|
||||
// if (jjj >= resultList.size()) {
|
||||
// resultList.pushBack(result);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
@ -1,5 +0,0 @@
|
||||
package org.atriaSoft.gameEngine.resource;
|
||||
|
||||
public class Mesh {
|
||||
|
||||
}
|
962
src/org/atriaSoft/gameEngine/resource/ResourceMesh.java
Normal file
962
src/org/atriaSoft/gameEngine/resource/ResourceMesh.java
Normal file
@ -0,0 +1,962 @@
|
||||
package org.atriaSoft.gameEngine.resource;
|
||||
|
||||
enum NormalMode {
|
||||
none,
|
||||
face,
|
||||
vertex,
|
||||
}
|
||||
|
||||
public class ResourceMesh {
|
||||
protected NormalMode normalMode; // select the normal mode of display
|
||||
public void setNormalMode(NormalMode _mode) {
|
||||
normalMode = _mode;
|
||||
}
|
||||
|
||||
protected bool checkNormal; //!< when enable, this check the normal of the mesh before sending it at the 3d card
|
||||
protected:
|
||||
ememory::SharedPtr<gale::resource::Program> GLprogram;
|
||||
int32_t GLPosition;
|
||||
int32_t GLMatrix;
|
||||
int32_t GLMatrixPosition;
|
||||
int32_t GLNormal;
|
||||
int32_t GLtexture;
|
||||
int32_t GLColor;
|
||||
int32_t bufferOfset;
|
||||
int32_t numberOfElments;
|
||||
MaterialGlId GLMaterial;
|
||||
ege::Light light;
|
||||
protected:
|
||||
etk::Vector<vec3> listVertex; //!< List of all vertex in the element
|
||||
etk::Vector<vec2> listUV; //!< List of all UV point in the mesh (for the specify texture)
|
||||
etk::Vector<Color> listColor; //!< List of all Color point in the mesh
|
||||
etk::Vector<vec3> listFacesNormal; //!< List of all Face normal, when calculated
|
||||
etk::Vector<vec3> listVertexNormal; //!< List of all Face normal, when calculated
|
||||
etk::Map<etk::String,FaceIndexing> listFaces; //!< List of all Face for the mesh
|
||||
etk::Map<etk::String,ememory::SharedPtr<ege::Material>> materials;
|
||||
etk::Vector<ememory::SharedPtr<ege::physics::Shape>> physics; //!< collision shape module ... (independent of bullet lib)
|
||||
void clean() {
|
||||
physics.clear();
|
||||
materials.clear();
|
||||
listFaces.clear();
|
||||
listColor.clear();
|
||||
listVertexNormal.clear();
|
||||
listFacesNormal.clear();
|
||||
listUV.clear();
|
||||
listVertex.clear();
|
||||
}
|
||||
protected:
|
||||
ememory::SharedPtr<gale::resource::VirtualBufferObject> verticesVBO;
|
||||
protected:
|
||||
Mesh()
|
||||
normalMode(ege::resource::Mesh::normalMode::none),
|
||||
checkNormal(false),
|
||||
GLPosition(-1),
|
||||
GLMatrix(-1),
|
||||
GLMatrixPosition(-1),
|
||||
GLNormal(-1),
|
||||
GLtexture(-1),
|
||||
GLColor(-1),
|
||||
bufferOfset(-1),
|
||||
numberOfElments(-1),
|
||||
listFaces(0,false),
|
||||
materials(0,false),
|
||||
pointerShape(null),
|
||||
functionFreeShape(null) {
|
||||
addResourceType("ege::resource::Mesh");
|
||||
}
|
||||
void init(const etk::Uri& _fileName="---",
|
||||
const etk::Uri& _shaderName=etk::Uri() //==> Shader is automatically selected (depending on the presence or ot of texture...
|
||||
) {
|
||||
gale::Resource::init(_fileName.getString());
|
||||
EGE_VERBOSE("Load a new mesh : '" << _fileName << "'");
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// get the shader resource :
|
||||
GLPosition = 0;
|
||||
|
||||
light.setDirection(vec3(0.0f,0.0f,10));
|
||||
light.setHalfPlane(vec3(1.0f,0.0f,0.0f));
|
||||
light.setAmbientColor(vec4(1.0f,1.0f,1.0f,1.0f)); // Global anbiant color of the scene
|
||||
light.setDiffuseColor(vec4(1.0f,1.0f,1.0f,1.0f)); // Color of the object
|
||||
light.setSpecularColor(vec4(0.0f,0.0f,0.0f,1.0f)); // Light color reflection
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// this is the properties of the buffer requested : "r"/"w" + "-" + buffer type "f"=flaot "i"=integer
|
||||
verticesVBO = gale::resource::VirtualBufferObject::create(5);
|
||||
if (verticesVBO == null) {
|
||||
EGE_ERROR("can not instanciate VBO ...");
|
||||
return;
|
||||
}
|
||||
// TO facilitate some debugs we add a name of the VBO:
|
||||
verticesVBO->setName("[VBO] of " + _fileName.getString());
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// load the curent file :
|
||||
etk::String extention = etk::toLower(_fileName.getPath().getExtention());
|
||||
// select the corect loader :
|
||||
if (extention == "obj") {
|
||||
if (loadOBJ(_fileName) == false) {
|
||||
EGE_ERROR("Error To load OBJ file " << _fileName );
|
||||
return;
|
||||
}
|
||||
} else if (extention == "emf") {
|
||||
if (loadEMF(_fileName) == false) {
|
||||
EGE_ERROR("Error To load EMF file " << _fileName );
|
||||
return;
|
||||
}
|
||||
//EGE_CRITICAL("Load a new mesh : '" << _fileName << "' (end)");
|
||||
} else {
|
||||
// nothing to do == > reqiest an enmpty mesh ==> user manage it ...
|
||||
}
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
etk::Uri shaderName = _shaderName;
|
||||
if (shaderName.isEmpty() == true) {
|
||||
shaderName = "DATA:///material3D.prog";
|
||||
for (auto &it: materials) {
|
||||
if (it.second->haveTexture() == true) {
|
||||
shaderName = "DATA:///material3DTextured.prog";
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
EGE_VERBOSE(name << " " << light << " shader=" << shaderName);
|
||||
GLprogram = gale::resource::Program::create(shaderName);
|
||||
if (GLprogram != null) {
|
||||
GLPosition = GLprogram->getAttribute("EW_coord3d");
|
||||
GLtexture = GLprogram->getAttribute("EW_texture2d");
|
||||
GLNormal = GLprogram->getAttribute("EW_normal");
|
||||
GLColor = GLprogram->getAttribute("EW_color");
|
||||
GLMatrix = GLprogram->getUniform("EW_MatrixTransformation");
|
||||
GLMatrixPosition = GLprogram->getUniform("EW_MatrixPosition");
|
||||
// Link material and Lights
|
||||
GLMaterial.link(GLprogram, "EW_material");
|
||||
light.link(GLprogram, "EW_directionalLight");
|
||||
}
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
}
|
||||
@Override
|
||||
public void cleanUp() {
|
||||
// remove dynamics dependencies :
|
||||
if (functionFreeShape != null) {
|
||||
functionFreeShape(pointerShape);
|
||||
pointerShape = null;
|
||||
}
|
||||
}
|
||||
public:
|
||||
virtual void draw(mat4& _positionMatrix, bool _enableDepthTest=true, bool _enableDepthUpdate=true) {
|
||||
// TODO : Remove this, it is just for test the 23-04-2016
|
||||
//checkNormal = false;
|
||||
EGE_VERBOSE("draw Mesh : " << name << " (start)");
|
||||
if (GLprogram == null) {
|
||||
EGE_ERROR("No shader ...");
|
||||
return;
|
||||
}
|
||||
//EGE_DEBUG(name << " " << light);
|
||||
if (_enableDepthTest == true) {
|
||||
gale::openGL::enable(gale::openGL::flag_depthTest);
|
||||
if (_enableDepthUpdate == false) {
|
||||
glDepthMask(GL_FALSE);
|
||||
}
|
||||
} else {
|
||||
gale::openGL::disable(gale::openGL::flag_depthTest);
|
||||
}
|
||||
//EGE_DEBUG(" display " << coord.size() << " elements" );
|
||||
GLprogram->use();
|
||||
// set Matrix : translation/positionMatrix
|
||||
mat4 projMatrix = gale::openGL::getMatrix();
|
||||
mat4 camMatrix = gale::openGL::getCameraMatrix();
|
||||
mat4 tmpMatrix = projMatrix * camMatrix;
|
||||
GLprogram->uniformMatrix(GLMatrix, tmpMatrix);
|
||||
GLprogram->uniformMatrix(GLMatrixPosition, _positionMatrix);
|
||||
// position :
|
||||
GLprogram->sendAttributePointer(GLPosition, verticesVBO, MESH_VBO_VERTICES);
|
||||
// Texture (if needed):
|
||||
if (listUV.size() != 0) {
|
||||
GLprogram->sendAttributePointer(GLtexture, verticesVBO, MESH_VBO_TEXTURE);
|
||||
}
|
||||
// position :
|
||||
if (normalMode != ege::resource::Mesh::normalMode::none) {
|
||||
GLprogram->sendAttributePointer(GLNormal, verticesVBO, MESH_VBO_VERTICES_NORMAL);
|
||||
#if DEBUG
|
||||
// TODO : ...
|
||||
#endif
|
||||
#if DEBUG
|
||||
} else {
|
||||
// TODO : ...
|
||||
}
|
||||
#else
|
||||
}
|
||||
#endif
|
||||
// colors :
|
||||
GLprogram->sendAttributePointer(GLColor, verticesVBO, MESH_VBO_COLOR);
|
||||
// draw lights :
|
||||
//EGE_INFO("light : " << light);
|
||||
light.draw(GLprogram);
|
||||
#ifdef DISPLAY_NB_VERTEX_DISPLAYED
|
||||
int32_t nbElementDrawTheoric = 0;
|
||||
int32_t nbElementDraw = 0;
|
||||
#endif
|
||||
for (size_t kkk=0; kkk<listFaces.size(); kkk++) {
|
||||
if (materials.exist(listFaces.getKey(kkk)) == false) {
|
||||
EGE_WARNING("missing materials : '" << listFaces.getKey(kkk) << "'");
|
||||
continue;
|
||||
}
|
||||
materials[listFaces.getKey(kkk)]->draw(GLprogram, GLMaterial);
|
||||
if (true) { // TODO : understand why the optimisation does not work at all ... : if (checkNormal == false) {
|
||||
gale::openGL::drawElements(materials[listFaces.getKey(kkk)]->getRenderModeOpenGl(), listFaces.getValue(kkk).index);
|
||||
#ifdef DISPLAY_NB_VERTEX_DISPLAYED
|
||||
nbElementDraw += listFaces.getValue(kkk).index.size();
|
||||
nbElementDrawTheoric += listFaces.getValue(kkk).index.size();
|
||||
#endif
|
||||
} else {
|
||||
mat4 mattttt = (projMatrix * camMatrix) * _positionMatrix;
|
||||
mattttt.mat[3] = 0;
|
||||
mattttt.mat[7] = 0;
|
||||
mattttt.mat[11] = 0;
|
||||
//vec3 cameraNormal = vec3(-mattttt.mat[2], -mattttt.mat[6], -mattttt.mat[10]);
|
||||
vec3 cameraNormal = vec3(0,0,-1);
|
||||
cameraNormal.normalized();
|
||||
// remove face that is notin the view ...
|
||||
etk::Vector<uint32_t> tmpIndexResult;
|
||||
etk::Vector<ege::Face>& tmppFaces = listFaces.getValue(kkk).faces;
|
||||
//etk::Vector<uint32_t>& tmppIndex = listFaces.getValue(kkk).index;
|
||||
switch(normalMode) {
|
||||
case ege::resource::Mesh::normalMode::face:
|
||||
for(size_t iii=0; iii<tmppFaces.size() ; ++iii) {
|
||||
if((mattttt * listFacesNormal[tmppFaces[iii].normal[0]]).dot(cameraNormal) >= 0.0f) {
|
||||
tmpIndexResult.pushBack(iii*3);
|
||||
tmpIndexResult.pushBack(iii*3+1);
|
||||
tmpIndexResult.pushBack(iii*3+2);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ege::resource::Mesh::normalMode::vertex:
|
||||
for(size_t iii=0; iii<tmppFaces.size() ; ++iii) {
|
||||
if( ((mattttt * listVertexNormal[tmppFaces[iii].normal[0]]).dot(cameraNormal) >= -0.2f)
|
||||
|| ((mattttt * listVertexNormal[tmppFaces[iii].normal[1]]).dot(cameraNormal) >= -0.2f)
|
||||
|| ((mattttt * listVertexNormal[tmppFaces[iii].normal[2]]).dot(cameraNormal) >= -0.2f) ) {
|
||||
tmpIndexResult.pushBack(iii*3);
|
||||
tmpIndexResult.pushBack(iii*3+1);
|
||||
tmpIndexResult.pushBack(iii*3+2);
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
for(size_t iii=0; iii<tmppFaces.size() ; ++iii) {
|
||||
tmpIndexResult.pushBack(iii*3);
|
||||
tmpIndexResult.pushBack(iii*3+1);
|
||||
tmpIndexResult.pushBack(iii*3+2);
|
||||
}
|
||||
break;
|
||||
}
|
||||
gale::openGL::drawElements(materials[listFaces.getKey(kkk)]->getRenderModeOpenGl(), tmpIndexResult);
|
||||
#ifdef DISPLAY_NB_VERTEX_DISPLAYED
|
||||
nbElementDraw += tmpIndexResult.size();
|
||||
nbElementDrawTheoric += listFaces.getValue(kkk).index.size();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#ifdef DISPLAY_NB_VERTEX_DISPLAYED
|
||||
if (listFaces.size() == 0) {
|
||||
EGE_ERROR(" !!!! No Face to display elements [" << name << "]");
|
||||
} else {
|
||||
if (nbElementDrawTheoric != 0) {
|
||||
EGE_WARNING(((float)nbElementDraw/(float)nbElementDrawTheoric*100.0f) << "% Request draw : " << listFaces.size() << ":" << nbElementDraw << "/" << nbElementDrawTheoric << " elements [" << name << "]");
|
||||
} else {
|
||||
EGE_WARNING("0% Request draw : " << listFaces.size() << ":" << nbElementDraw << "/" << nbElementDrawTheoric << " elements [" << name << "]");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
GLprogram->unUse();
|
||||
|
||||
if (_enableDepthTest == true){
|
||||
if (_enableDepthUpdate == false) {
|
||||
glDepthMask(GL_TRUE);
|
||||
}
|
||||
gale::openGL::disable(gale::openGL::flag_depthTest);
|
||||
}
|
||||
// TODO : UNDERSTAND why ... it is needed
|
||||
gale::openGL::unbindBuffer();
|
||||
EGE_VERBOSE("draw Mesh : " << name << " ( end )");
|
||||
}
|
||||
|
||||
virtual void draw(mat4& _positionMatrix,
|
||||
Color _mainColor,
|
||||
bool _enableDepthTest = true,
|
||||
bool _enableDepthUpdate = true) {
|
||||
draw(_positionMatrix, _enableDepthTest, _enableDepthUpdate);
|
||||
}
|
||||
// For debug only ...
|
||||
void drawNormal(mat4& _positionMatrix,
|
||||
ememory::SharedPtr<ewol::resource::Colored3DObject> _draw) {
|
||||
Color tmpColor(0.0, 1.0, 0.0, 1.0);
|
||||
etk::Vector<vec3> vertices;
|
||||
// generate element in 2 pass :
|
||||
// - create new index dependeng a vertex is a unique componenet of position, texture, normal
|
||||
// - the index list generation (can be dynamic ... (TODO later)
|
||||
for (size_t kkk=0; kkk<listFaces.size(); kkk++) {
|
||||
// clean faces indexes :
|
||||
size_t nbIndicInFace = 3;
|
||||
switch (materials[listFaces.getKey(kkk)]->getRenderMode()) {
|
||||
case gale::openGL::renderMode::triangle:
|
||||
case gale::openGL::renderMode::triangleStrip:
|
||||
case gale::openGL::renderMode::triangleFan:
|
||||
nbIndicInFace = 3;
|
||||
break;
|
||||
case gale::openGL::renderMode::line:
|
||||
case gale::openGL::renderMode::lineStrip:
|
||||
case gale::openGL::renderMode::lineLoop:
|
||||
nbIndicInFace = 2;
|
||||
break;
|
||||
case gale::openGL::renderMode::point:
|
||||
nbIndicInFace = 1;
|
||||
break;
|
||||
case gale::openGL::renderMode::quad:
|
||||
case gale::openGL::renderMode::quadStrip:
|
||||
nbIndicInFace = 4;
|
||||
break;
|
||||
case gale::openGL::renderMode::polygon:
|
||||
nbIndicInFace = 3;
|
||||
break;
|
||||
}
|
||||
FaceIndexing& tmpFaceList = listFaces.getValue(kkk);
|
||||
for (size_t iii=0; iii<tmpFaceList.faces.size() ; iii++) {
|
||||
switch(normalMode) {
|
||||
case ege::resource::Mesh::normalMode::vertex:
|
||||
{
|
||||
// dsplay normal for each vertice ... (TODO: not tested ...)
|
||||
for(size_t indice=0 ; indice<nbIndicInFace; indice++) {
|
||||
vec3 position = listVertex[tmpFaceList.faces[iii].vertex[indice]];
|
||||
vec3 normal = listVertexNormal[tmpFaceList.faces[iii].normal[indice]];
|
||||
vertices.pushBack(position);
|
||||
vertices.pushBack(position+normal*0.5f);
|
||||
}
|
||||
} break;
|
||||
case ege::resource::Mesh::normalMode::face:
|
||||
{
|
||||
vec3 center(0,0,0);
|
||||
for(size_t indice=0 ; indice<nbIndicInFace; indice++) {
|
||||
vec3 position = listVertex[tmpFaceList.faces[iii].vertex[indice]];
|
||||
center += position;
|
||||
}
|
||||
center /= float(nbIndicInFace);
|
||||
size_t index = tmpFaceList.faces[iii].normal[0];
|
||||
if (index >= listFacesNormal.size()) {
|
||||
EGE_ERROR("not enougth normal in the buffer ... " << index << " >= " << listFacesNormal.size());
|
||||
return;
|
||||
}
|
||||
vec3 normal = listFacesNormal[index];
|
||||
vertices.pushBack(center);
|
||||
vertices.pushBack(center+normal*0.5f);
|
||||
} break;
|
||||
case ege::resource::Mesh::normalMode::none:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
_draw->drawLine(vertices, tmpColor, _positionMatrix);
|
||||
}
|
||||
void generateVBO() {
|
||||
// calculate the normal of all faces if needed
|
||||
if ( normalMode != ege::resource::Mesh::normalMode::none
|
||||
&& listFacesNormal.size() == 0) {
|
||||
// when no normal detected == > auto generate Face normal ....
|
||||
EGE_ERROR("Calculate normal face ... in case ????");
|
||||
calculateNormaleFace(listFaces.getKeys()[0]);
|
||||
}
|
||||
EGE_WARNING("Generate VBO for nb faces layers: " << listFaces.size() << " list layer=" << etk::toString(listFaces.getKeys()));
|
||||
|
||||
// generate element in 2 pass:
|
||||
// - create new index depending on a vertex is a unique component of position, texture, normal
|
||||
// - the index list generation (can be dynamic ... (TODO later))
|
||||
for (size_t kkk=0; kkk<listFaces.size(); kkk++) {
|
||||
// clean faces indexes :
|
||||
listFaces.getValue(kkk).index.clear();
|
||||
int32_t nbIndicInFace = 3;
|
||||
if (materials.exist(listFaces.getKey(kkk)) == false) {
|
||||
EGE_WARNING("missing materials : '" << listFaces.getKey(kkk) << "' not in " << materials.getKeys() );
|
||||
continue;
|
||||
}
|
||||
if (materials[listFaces.getKey(kkk)] == null) {
|
||||
EGE_ERROR("Can not get material : " << listFaces.getKey(kkk) << " pointer value: " << size_t(materials[listFaces.getKey(kkk)].get()));
|
||||
continue;
|
||||
}
|
||||
switch (materials[listFaces.getKey(kkk)]->getRenderMode()) {
|
||||
case gale::openGL::renderMode::triangle:
|
||||
case gale::openGL::renderMode::triangleStrip:
|
||||
case gale::openGL::renderMode::triangleFan:
|
||||
nbIndicInFace = 3;
|
||||
break;
|
||||
case gale::openGL::renderMode::line:
|
||||
case gale::openGL::renderMode::lineStrip:
|
||||
case gale::openGL::renderMode::lineLoop:
|
||||
nbIndicInFace = 2;
|
||||
break;
|
||||
case gale::openGL::renderMode::point:
|
||||
nbIndicInFace = 1;
|
||||
break;
|
||||
case gale::openGL::renderMode::quad:
|
||||
case gale::openGL::renderMode::quadStrip:
|
||||
nbIndicInFace = 4;
|
||||
break;
|
||||
case gale::openGL::renderMode::polygon:
|
||||
nbIndicInFace = 3;
|
||||
break;
|
||||
}
|
||||
#ifdef TRY_MINIMAL_VBO
|
||||
int64_t tmpppppp=0;
|
||||
#endif
|
||||
FaceIndexing& tmpFaceList = listFaces.getValue(kkk);
|
||||
for (size_t iii=0; iii<tmpFaceList.faces.size() ; iii++) {
|
||||
int32_t vertexVBOId[3];
|
||||
for(size_t indice=0 ; indice<nbIndicInFace; indice++) {
|
||||
// ghet position
|
||||
vec3 position = listVertex[tmpFaceList.faces[iii].vertex[indice]];
|
||||
// get Color
|
||||
Color color;
|
||||
if (tmpFaceList.faces[iii].color[indice] != -1) {
|
||||
color = listColor[tmpFaceList.faces[iii].color[indice]];
|
||||
} else {
|
||||
color = etk::color::white;
|
||||
}
|
||||
// get Normal
|
||||
vec3 normal;
|
||||
switch(normalMode) {
|
||||
case ege::resource::Mesh::normalMode::vertex:
|
||||
normal = listVertexNormal[tmpFaceList.faces[iii].normal[indice]];
|
||||
break;
|
||||
case ege::resource::Mesh::normalMode::face:
|
||||
normal = listFacesNormal[tmpFaceList.faces[iii].normal[indice]];
|
||||
break;
|
||||
default:
|
||||
case ege::resource::Mesh::normalMode::none:
|
||||
break;
|
||||
}
|
||||
// get Texture Position
|
||||
vec2 texturepos;
|
||||
if (tmpFaceList.faces[iii].uv[indice] == -1) {
|
||||
texturepos.setValue(0,0);
|
||||
} else {
|
||||
texturepos.setValue(listUV[tmpFaceList.faces[iii].uv[indice]].x(),1.0f-listUV[tmpFaceList.faces[iii].uv[indice]].y());
|
||||
}
|
||||
// Create the vectex Buffer list:
|
||||
bool elementFind = false;
|
||||
#ifdef TRY_MINIMAL_VBO
|
||||
for (int32_t jjj=0; jjj<verticesVBO->sizeOnBufferVec3(MESH_VBO_VERTICES); jjj++) {
|
||||
if( verticesVBO->getOnBufferVec3(MESH_VBO_VERTICES,jjj) == position
|
||||
&& verticesVBO->getOnBufferVec3(MESH_VBO_VERTICES_NORMAL,jjj) == normal
|
||||
&& verticesVBO->getOnBufferVec2(MESH_VBO_TEXTURE,jjj) == texturepos) {
|
||||
vertexVBOId[indice] = jjj;
|
||||
elementFind = true;
|
||||
//EGE_DEBUG("search indice : " << jjj);
|
||||
tmpppppp += jjj;
|
||||
// stop searching ...
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
if (elementFind == false) {
|
||||
verticesVBO->pushOnBuffer(MESH_VBO_VERTICES, position);
|
||||
if (normalMode != ege::resource::Mesh::normalMode::none) {
|
||||
verticesVBO->pushOnBuffer(MESH_VBO_VERTICES_NORMAL, normal);
|
||||
}
|
||||
verticesVBO->pushOnBuffer(MESH_VBO_TEXTURE, texturepos);
|
||||
verticesVBO->pushOnBuffer(MESH_VBO_COLOR, color);
|
||||
vertexVBOId[indice] = verticesVBO->bufferSize(MESH_VBO_VERTICES)-1;
|
||||
}
|
||||
}
|
||||
for(size_t indice=0 ; indice<nbIndicInFace; indice++) {
|
||||
tmpFaceList.index.pushBack(vertexVBOId[indice]);
|
||||
}
|
||||
}
|
||||
#ifdef TRY_MINIMAL_VBO
|
||||
EGE_DEBUG("nb cycle ? : " << tmpppppp);
|
||||
#endif
|
||||
}
|
||||
// update all the VBO elements ...
|
||||
verticesVBO->flush();
|
||||
}
|
||||
private:
|
||||
void calculateNormaleFace(const etk::String& _materialName) {
|
||||
listFacesNormal.clear();
|
||||
if (normalMode == ege::resource::Mesh::normalMode::face) {
|
||||
EGE_VERBOSE("calculateNormaleFace(" << _materialName << ")");
|
||||
gale::openGL::renderMode tmpRenderMode = materials[_materialName]->getRenderMode();
|
||||
if ( tmpRenderMode == gale::openGL::renderMode::point
|
||||
|| tmpRenderMode == gale::openGL::renderMode::line
|
||||
|| tmpRenderMode == gale::openGL::renderMode::lineStrip
|
||||
|| tmpRenderMode == gale::openGL::renderMode::lineLoop) {
|
||||
EGE_ERROR("calculateNormaleFace(" << _materialName << ") : can not calculate normal on lines ...");
|
||||
normalMode = ege::resource::Mesh::normalMode::none;
|
||||
return;
|
||||
}
|
||||
for(auto &it : listFaces[_materialName].faces) {
|
||||
// for all case, We use only the 3 vertex for quad element, in theory 3D modeler export element in triangle if it is not a real plane.
|
||||
vec3 normal = (listVertex[it.vertex[0]]-listVertex[it.vertex[1]]).cross(listVertex[it.vertex[1]]-listVertex[it.vertex[2]]);
|
||||
//EGE_INFO("normal: " << normal.normalized());
|
||||
if (normal == vec3(0,0,0)) {
|
||||
EGE_ERROR("Null vertor for a face ... " << listVertex[it.vertex[0]] << " " << listVertex[it.vertex[1]] << " " << listVertex[it.vertex[2]]);
|
||||
listFacesNormal.pushBack(vec3(1,0,0));
|
||||
} else {
|
||||
listFacesNormal.pushBack(normal.normalized());
|
||||
}
|
||||
int32_t normalID = listFacesNormal.size() - 1;
|
||||
it.normal[0] = normalID;
|
||||
it.normal[1] = normalID;
|
||||
it.normal[2] = normalID;
|
||||
}
|
||||
}
|
||||
}
|
||||
void calculateNormaleEdge(const etk::String& _materialName) {
|
||||
listVertexNormal.clear();
|
||||
if (normalMode == ege::resource::Mesh::normalMode::vertex) {
|
||||
EGE_INFO("calculateNormaleEdge(" << _materialName << ")");
|
||||
gale::openGL::renderMode tmpRenderMode = materials[_materialName]->getRenderMode();
|
||||
if ( tmpRenderMode == gale::openGL::renderMode::point
|
||||
|| tmpRenderMode == gale::openGL::renderMode::line
|
||||
|| tmpRenderMode == gale::openGL::renderMode::lineStrip
|
||||
|| tmpRenderMode == gale::openGL::renderMode::lineLoop) {
|
||||
EGE_ERROR("calculateNormaleEdge(" << _materialName << ") : can not calculate normal on lines ...");
|
||||
normalMode = ege::resource::Mesh::normalMode::none;
|
||||
return;
|
||||
}
|
||||
for(size_t iii=0 ; iii<listVertex.size() ; iii++) {
|
||||
etk::Vector<Face>& tmpFaceList = listFaces[_materialName].faces;
|
||||
vec3 normal(0,0,0);
|
||||
// add the vertex from all the element in the list for face when the element in the face ...
|
||||
for(size_t jjj=0 ; jjj<tmpFaceList.size() ; jjj++) {
|
||||
verticesVBO->pushOnBuffer(MESH_VBO_VERTICES_NORMAL, normal);
|
||||
if( tmpFaceList[jjj].vertex[0] == (int32_t)iii
|
||||
|| tmpFaceList[jjj].vertex[1] == (int32_t)iii
|
||||
|| tmpFaceList[jjj].vertex[2] == (int32_t)iii) {
|
||||
normal += listFacesNormal[jjj];
|
||||
}
|
||||
}
|
||||
if (normal == vec3(0,0,0)) {
|
||||
listVertexNormal.pushBack(vec3(1,1,1));
|
||||
} else {
|
||||
listVertexNormal.pushBack(normal.normalized());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
public :
|
||||
void createViewBox(const etk::String& _materialName,float _size=1.0) {
|
||||
normalMode = ege::resource::Mesh::normalMode::none;
|
||||
ege::viewBox::create(materials, listFaces, listVertex, listUV,
|
||||
_materialName, _size);
|
||||
calculateNormaleFace(_materialName);
|
||||
}
|
||||
void createIcoSphere(const etk::String& _materialName,float _size=1.0, int32_t _subdivision=3) {
|
||||
normalMode = ege::resource::Mesh::normalMode::none;
|
||||
ege::icoSphere::create(materials, listFaces, listVertex, listUV,
|
||||
_materialName, _size, _subdivision);
|
||||
calculateNormaleFace(_materialName);
|
||||
}
|
||||
private:
|
||||
bool loadOBJ(const etk::Uri& _fileName);
|
||||
bool loadEMF(const etk::Uri& _fileName);
|
||||
public:
|
||||
void addMaterial(const etk::String& _name, ememory::SharedPtr<ege::Material> _data) {
|
||||
if (_data == null) {
|
||||
EGE_ERROR(" can not add material with null pointer");
|
||||
return;
|
||||
}
|
||||
if (_name == "") {
|
||||
EGE_ERROR(" can not add material with no name");
|
||||
return;
|
||||
}
|
||||
// really add the material:
|
||||
EGE_WARNING("Add material: " << _name);
|
||||
materials.add(_name, _data);
|
||||
}
|
||||
public:
|
||||
/**
|
||||
* @brief set the check of normal position befor sending it to the openGl card
|
||||
* @param[in] _status New state.
|
||||
*/
|
||||
void setCheckNormal(bool _status) {
|
||||
checkNormal=_status;
|
||||
};
|
||||
/**
|
||||
* @brief get the check value of normal position befor sending it to the openGl card
|
||||
* @return get the chcking stus of normal or not
|
||||
*/
|
||||
bool getCheckNormal() {
|
||||
return checkNormal;
|
||||
};
|
||||
const etk::Vector<ememory::SharedPtr<ege::physics::Shape>>& getPhysicalProperties() {
|
||||
for (auto &it: physics) {
|
||||
if (it == null) {
|
||||
EGE_WARNING("Get null ... ");
|
||||
continue;
|
||||
}
|
||||
if (it->getType() == ege::physics::Shape::type::concave) {
|
||||
// need to generate the internal list of point and triangle needed:
|
||||
ege::physics::shape::Concave* tmpElement = it->toConcave();
|
||||
if (tmpElement == null) {
|
||||
EGE_ERROR(" Concave ==> can not cast in Concave");
|
||||
return physics;
|
||||
}
|
||||
tmpElement->clear();
|
||||
//EGE_INFO(" add vertices : " << listVertex);
|
||||
tmpElement->setListOfVertex(listVertex);
|
||||
for (size_t kkk=0; kkk<listFaces.size(); ++kkk) {
|
||||
etk::Vector<uint32_t> index;
|
||||
for (auto &it : listFaces.getValue(kkk).faces) {
|
||||
index.pushBack(it.vertex[0]);
|
||||
index.pushBack(it.vertex[1]);
|
||||
index.pushBack(it.vertex[2]);
|
||||
}
|
||||
//EGE_INFO(" add triangle : " << listFaces.getValue(kkk).index);
|
||||
|
||||
//tmpElement->addTriangle(listFaces.getValue(kkk).index);
|
||||
tmpElement->addTriangle(index);
|
||||
}
|
||||
//EGE_CRITICAL("kjlkj");
|
||||
// Can have only one concave element in a mesh ...
|
||||
//return physics;
|
||||
}
|
||||
}
|
||||
return physics;
|
||||
}
|
||||
void addPhysicElement(const ememory::SharedPtr<ege::physics::Shape>& _shape) {
|
||||
if (_shape == null) {
|
||||
return;
|
||||
}
|
||||
physics.pushBack(_shape);
|
||||
}
|
||||
private:
|
||||
void* pointerShape; //!< all mesh have a basic shape (bullet or other) the void pointer mermit to not depent on the bullet lib
|
||||
public:
|
||||
/**
|
||||
* @brief set the shape pointer (no type == > user might know it ...)
|
||||
* @param[in] _shape The new shape (this remove the previous one)
|
||||
*/
|
||||
void setShape(void* _shape) {
|
||||
if (functionFreeShape!=null) {
|
||||
functionFreeShape(pointerShape);
|
||||
pointerShape = null;
|
||||
}
|
||||
pointerShape=_shape;
|
||||
}
|
||||
/**
|
||||
* @brief get the pointer on the shame (no type)
|
||||
* @return Pointer on shape.
|
||||
*/
|
||||
void* getShape() {
|
||||
return pointerShape;
|
||||
};
|
||||
private:
|
||||
void (*functionFreeShape)(void* _pointer);
|
||||
public:
|
||||
void setFreeShapeFunction(void (*_functionFreeShape)(void* _pointer)) {
|
||||
functionFreeShape = _functionFreeShape;
|
||||
};
|
||||
/**
|
||||
* @brief Add in the faces list the layer requested
|
||||
* @param[in] _layerName face index to add
|
||||
*/
|
||||
void addFaceIndexing(const etk::String& _layerName) {
|
||||
if (listFaces.exist(_layerName) == false) {
|
||||
FaceIndexing empty;
|
||||
listFaces.add(_layerName, empty);
|
||||
}
|
||||
}
|
||||
public:
|
||||
|
||||
void addPoint(const etk::String& _layerName, const vec3& _pos, Color _color) {
|
||||
if ( listFaces.exist(_layerName) == false
|
||||
|| materials.exist(_layerName) == false) {
|
||||
EGE_ERROR("Mesh layer : " << _layerName << " does not exist in list faces=" << listFaces.exist(_layerName) << " materials=" << listFaces.exist(_layerName) << " ...");
|
||||
return;
|
||||
}
|
||||
gale::openGL::renderMode tmpRenderMode = materials[_layerName]->getRenderMode();
|
||||
if (tmpRenderMode != gale::openGL::renderMode::point) {
|
||||
EGE_ERROR("try to add Point in a mesh material section that not support Point");
|
||||
return;
|
||||
}
|
||||
// try to find position:
|
||||
int32_t pos = findPositionInList(_pos);
|
||||
// try to find UV mapping:
|
||||
int32_t color = findColorInList(_color);
|
||||
Face tmpFace;
|
||||
tmpFace.setVertex(pos);
|
||||
tmpFace.setColor(color, color, color);
|
||||
listFaces[_layerName].faces.pushBack(tmpFace);
|
||||
}
|
||||
|
||||
void addLine(const etk::String& _layerName, const vec3& _pos1, const vec3& _pos2, Color _color) {
|
||||
addLine( _layerName, _pos1, _pos2, _color, _color);
|
||||
}
|
||||
void addLine(const etk::String& _layerName, const vec3& _pos1, const vec3& _pos2, Color _color1, Color _color2) {
|
||||
if ( listFaces.exist(_layerName) == false
|
||||
|| materials.exist(_layerName) == false) {
|
||||
EGE_ERROR("Mesh layer : " << _layerName << " does not exist in list faces=" << listFaces.exist(_layerName) << " materials=" << listFaces.exist(_layerName) << " ...");
|
||||
return;
|
||||
}
|
||||
gale::openGL::renderMode tmpRenderMode = materials[_layerName]->getRenderMode();
|
||||
if ( tmpRenderMode != gale::openGL::renderMode::line
|
||||
&& tmpRenderMode != gale::openGL::renderMode::lineStrip
|
||||
&& tmpRenderMode != gale::openGL::renderMode::lineLoop) {
|
||||
EGE_ERROR("try to add Line in a mesh material section that not support Line");
|
||||
return;
|
||||
}
|
||||
// try to find position:
|
||||
int32_t pos1 = findPositionInList(_pos1);
|
||||
int32_t pos2 = findPositionInList(_pos2);
|
||||
// try to find UV mapping:
|
||||
int32_t color1 = findColorInList(_color1);
|
||||
int32_t color2 = findColorInList(_color2);
|
||||
Face tmpFace;
|
||||
tmpFace.setVertex(pos1, pos2);
|
||||
tmpFace.setColor(color1, color2, color2);
|
||||
listFaces[_layerName].faces.pushBack(tmpFace);
|
||||
}
|
||||
|
||||
void addLines(const etk::String& _layerName, const etk::Vector<vec3>& _list, Color _color){
|
||||
for (size_t iii=1; iii<_list.size(); ++iii) {
|
||||
addLine(_layerName, _list[iii-1], _list[iii], _color);
|
||||
}
|
||||
}
|
||||
|
||||
void addLines(const etk::String& _layerName, const etk::Vector<vec3>& _list, const etk::Vector<Color>& _color) {
|
||||
if (_color.size() != _list.size()) {
|
||||
EGE_ERROR("Can not add line with changing color without same number of color");
|
||||
return;
|
||||
}
|
||||
for (size_t iii=1; iii<_list.size(); ++iii) {
|
||||
addLine(_layerName, _list[iii-1], _list[iii], _color[iii-1], _color[iii]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @not_in_doc
|
||||
* @brief draw a colored triangle (usefull for debug and test)
|
||||
* @param[in] _layerName Material and face indexing layer name
|
||||
* @param[in] _pos1 First point position
|
||||
* @param[in] _pos2 Second point position
|
||||
* @param[in] _pos3 Third point position
|
||||
* @param[in] _color1 color of the _pos1 element
|
||||
* @param[in] _color2 color of the _pos2 element
|
||||
* @param[in] _color3 color of the _pos3 element
|
||||
*/
|
||||
void addTriangle(const etk::String& _layerName, const vec3& _pos1, const vec3& _pos2, const vec3& _pos3, Color _color) {
|
||||
addTriangle(_layerName, _pos1, _pos2, _pos3, _color, _color, _color);
|
||||
}
|
||||
/**
|
||||
* @not_in_doc
|
||||
* @brief draw a colored triangle (usefull for debug and test)
|
||||
* @param[in] _layerName Material and face indexing layer name
|
||||
* @param[in] _pos1 First point position
|
||||
* @param[in] _pos2 Second point position
|
||||
* @param[in] _pos3 Third point position
|
||||
* @param[in] _color1 color of the _pos1 element
|
||||
* @param[in] _color2 color of the _pos2 element
|
||||
* @param[in] _color3 color of the _pos3 element
|
||||
*/
|
||||
void addTriangle(const etk::String& _layerName, const vec3& _pos1, const vec3& _pos2, const vec3& _pos3,
|
||||
Color _color1, Color _color2, Color _color3) {
|
||||
if ( listFaces.exist(_layerName) == false
|
||||
|| materials.exist(_layerName) == false) {
|
||||
EGE_ERROR("Mesh layer : " << _layerName << " does not exist in list faces=" << listFaces.exist(_layerName) << " materials=" << listFaces.exist(_layerName) << " ...");
|
||||
return;
|
||||
}
|
||||
gale::openGL::renderMode tmpRenderMode = materials[_layerName]->getRenderMode();
|
||||
if ( tmpRenderMode == gale::openGL::renderMode::quad
|
||||
|| tmpRenderMode == gale::openGL::renderMode::quadStrip) {
|
||||
EGE_TODO("Create quad interface ...");
|
||||
} else if ( tmpRenderMode == gale::openGL::renderMode::triangle
|
||||
|| tmpRenderMode == gale::openGL::renderMode::lineStrip
|
||||
|| tmpRenderMode == gale::openGL::renderMode::triangleFan) {
|
||||
|
||||
// try to find position:
|
||||
int32_t pos1 = findPositionInList(_pos1);
|
||||
int32_t pos2 = findPositionInList(_pos2);
|
||||
int32_t pos3 = findPositionInList(_pos3);
|
||||
// try to find Color:
|
||||
int32_t color1 = findColorInList(_color1);
|
||||
int32_t color2 = findColorInList(_color2);
|
||||
int32_t color3 = findColorInList(_color3);
|
||||
Face tmpFace(pos1, -1,
|
||||
pos2, -1,
|
||||
pos3, -1);
|
||||
tmpFace.setColor(color1, color2, color3);
|
||||
listFaces[_layerName].faces.pushBack(tmpFace);
|
||||
} else {
|
||||
EGE_ERROR("try to add Quad in a mesh material section that not support Quad");
|
||||
return;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @not_in_doc
|
||||
* @brief draw a colored quad (usefull for debug and test)
|
||||
* @param[in] _layerName Material and face indexing layer name
|
||||
* @param[in] _pos1 First point position
|
||||
* @param[in] _pos2 Second point position
|
||||
* @param[in] _pos3 Third point position
|
||||
* @param[in] _pos4 faurth point position
|
||||
* @param[in] _color color of all elements
|
||||
*/
|
||||
void addQuad(const etk::String& _layerName, const vec3& _pos1, const vec3& _pos2, const vec3& _pos3, const vec3& _pos4, Color _color) {
|
||||
addQuad(_layerName, _pos1, _pos2, _pos3, _pos4, _color, _color, _color, _color);
|
||||
}
|
||||
/**
|
||||
* @not_in_doc
|
||||
* @brief draw a colored quad (usefull for debug and test)
|
||||
* @param[in] _layerName Material and face indexing layer name
|
||||
* @param[in] _pos1 First point position
|
||||
* @param[in] _pos2 Second point position
|
||||
* @param[in] _pos3 Third point position
|
||||
* @param[in] _pos4 faurth point position
|
||||
* @param[in] _color1 color of the _pos1 element
|
||||
* @param[in] _color2 color of the _pos2 element
|
||||
* @param[in] _color3 color of the _pos3 element
|
||||
* @param[in] _color4 color of the _pos4 element
|
||||
*/
|
||||
void addQuad(const etk::String& _layerName, const vec3& _pos1, const vec3& _pos2, const vec3& _pos3, const vec3& _pos4,
|
||||
Color _color1, Color _color2, Color _color3, Color _color4) {
|
||||
addTriangle(_layerName, _pos1, _pos2, _pos3, _color1, _color2, _color3);
|
||||
addTriangle(_layerName, _pos1, _pos3, _pos4, _color1, _color3, _color4);
|
||||
}
|
||||
/**
|
||||
* @not_in_doc
|
||||
* @brief draw a textured colored triangle (usefull for debug and test)
|
||||
* @param[in] _layerName Material and face indexing layer name
|
||||
* @param[in] _pos1 First point position
|
||||
* @param[in] _pos2 Second point position
|
||||
* @param[in] _pos3 Third point position
|
||||
* @param[in] _color color of all elements
|
||||
* @param[in] _uv1 texture position of the _pos1 element
|
||||
* @param[in] _uv2 texture position of the _pos2 element
|
||||
* @param[in] _uv3 texture position of the _pos3 element
|
||||
*/
|
||||
void addTriangle(const etk::String& _layerName,
|
||||
const vec3& _pos1, const vec3& _pos2, const vec3& _pos3,
|
||||
const vec2& _uv1, const vec2& _uv2, const vec2& _uv3,
|
||||
Color _color) {
|
||||
addTriangle(_layerName, _pos1, _pos2, _pos3, _uv1, _uv2, _uv3, _color, _color, _color);
|
||||
}
|
||||
/**
|
||||
* @not_in_doc
|
||||
* @brief draw a textured colored triangle (usefull for debug and test)
|
||||
* @param[in] _layerName Material and face indexing layer name
|
||||
* @param[in] _pos1 First point position
|
||||
* @param[in] _pos2 Second point position
|
||||
* @param[in] _pos3 Third point position
|
||||
* @param[in] _color1 color of the _pos1 element
|
||||
* @param[in] _color2 color of the _pos2 element
|
||||
* @param[in] _color3 color of the _pos3 element
|
||||
* @param[in] _uv1 texture position of the _pos1 element
|
||||
* @param[in] _uv2 texture position of the _pos2 element
|
||||
* @param[in] _uv3 texture position of the _pos3 element
|
||||
*/
|
||||
void addTriangle(const etk::String& _layerName,
|
||||
const vec3& _pos1, const vec3& _pos2, const vec3& _pos3,
|
||||
const vec2& _uv1, const vec2& _uv2, const vec2& _uv3,
|
||||
Color _color1=etk::color::white, Color _color2=etk::color::white, Color _color3=etk::color::white) {
|
||||
EGE_INFO("add Triangle: " << _layerName << " ...");
|
||||
if ( listFaces.exist(_layerName) == false
|
||||
|| materials.exist(_layerName) == false) {
|
||||
EGE_ERROR("Mesh layer : " << _layerName << " does not exist in list faces=" << listFaces.exist(_layerName) << " materials=" << listFaces.exist(_layerName) << " ...");
|
||||
return;
|
||||
}
|
||||
gale::openGL::renderMode tmpRenderMode = materials[_layerName]->getRenderMode();
|
||||
if ( tmpRenderMode != gale::openGL::renderMode::triangle
|
||||
&& tmpRenderMode != gale::openGL::renderMode::triangleStrip
|
||||
&& tmpRenderMode != gale::openGL::renderMode::triangleFan) {
|
||||
EGE_ERROR("try to add Line in a mesh material section that not support Line");
|
||||
return;
|
||||
}
|
||||
// try to find position:
|
||||
int32_t pos1 = findPositionInList(_pos1);
|
||||
int32_t pos2 = findPositionInList(_pos2);
|
||||
int32_t pos3 = findPositionInList(_pos3);
|
||||
// try to find UV mapping:
|
||||
int32_t uv1 = findTextureInList(_uv1);
|
||||
int32_t uv2 = findTextureInList(_uv2);
|
||||
int32_t uv3 = findTextureInList(_uv3);
|
||||
// try to find Color:
|
||||
int32_t color1 = findColorInList(_color1);
|
||||
int32_t color2 = findColorInList(_color2);
|
||||
int32_t color3 = findColorInList(_color3);
|
||||
Face tmpFace(pos1, uv1,
|
||||
pos2, uv2,
|
||||
pos3, uv3);
|
||||
tmpFace.setColor(color1, color2, color3);
|
||||
listFaces[_layerName].faces.pushBack(tmpFace);
|
||||
EGE_INFO(" nbFace: " << listFaces[_layerName].faces.size());
|
||||
}
|
||||
/**
|
||||
* @not_in_doc
|
||||
* @brief draw a textured colored quad (usefull for debug and test)
|
||||
* @param[in] _layerName Material and face indexing layer name
|
||||
* @param[in] _pos1 First point position
|
||||
* @param[in] _pos2 Second point position
|
||||
* @param[in] _pos3 Third point position
|
||||
* @param[in] _pos4 faurth point position
|
||||
* @param[in] _color color of all elements
|
||||
* @param[in] _uv1 texture position of the _pos1 element
|
||||
* @param[in] _uv2 texture position of the _pos2 element
|
||||
* @param[in] _uv3 texture position of the _pos3 element
|
||||
* @param[in] _uv4 texture position of the _pos4 element
|
||||
*/
|
||||
void addQuad(const etk::String& _layerName,
|
||||
const vec3& _pos1, const vec3& _pos2, const vec3& _pos3, const vec3& _pos4,
|
||||
const vec2& _uv1, const vec2& _uv2, const vec2& _uv3, const vec2& _uv4,
|
||||
Color _color) {
|
||||
addQuad(_layerName, _pos1, _pos2, _pos3, _pos4, _uv1, _uv2, _uv3, _uv4, _color, _color, _color, _color);
|
||||
}
|
||||
/**
|
||||
* @not_in_doc
|
||||
* @brief draw a textured quad (usefull for debug and test)
|
||||
* @param[in] _layerName Material and face indexing layer name
|
||||
* @param[in] _pos1 First point position
|
||||
* @param[in] _pos2 Second point position
|
||||
* @param[in] _pos3 Third point position
|
||||
* @param[in] _pos4 faurth point position
|
||||
* @param[in] _uv1 texture position of the _pos1 element
|
||||
* @param[in] _uv2 texture position of the _pos2 element
|
||||
* @param[in] _uv3 texture position of the _pos3 element
|
||||
* @param[in] _uv4 texture position of the _pos4 element
|
||||
* @param[in] _color1 color of the _pos1 element
|
||||
* @param[in] _color2 color of the _pos2 element
|
||||
* @param[in] _color3 color of the _pos3 element
|
||||
* @param[in] _color4 color of the _pos4 element
|
||||
*/
|
||||
void addQuad(const etk::String& _layerName,
|
||||
const vec3& _pos1, const vec3& _pos2, const vec3& _pos3, const vec3& _pos4,
|
||||
const vec2& _uv1, const vec2& _uv2, const vec2& _uv3, const vec2& _uv4,
|
||||
Color _color1=etk::color::white, Color _color2=etk::color::white, Color _color3=etk::color::white, Color _color4=etk::color::white) {
|
||||
addTriangle(_layerName, _pos1, _pos2, _pos3, _uv1, _uv2, _uv3, _color1, _color2, _color3);
|
||||
addTriangle(_layerName, _pos1, _pos3, _pos4, _uv1, _uv3, _uv4, _color1, _color3, _color4);
|
||||
}
|
||||
protected:
|
||||
int32_t findPositionInList(const vec3& _pos) {
|
||||
for (size_t iii=0; iii<listVertex.size(); ++iii) {
|
||||
if (listVertex[iii] == _pos) {
|
||||
return iii;
|
||||
}
|
||||
}
|
||||
listVertex.pushBack(_pos);
|
||||
return listVertex.size()-1;
|
||||
}
|
||||
int32_t findTextureInList(const vec2& _uv) {
|
||||
for (size_t iii=0; iii<listUV.size(); ++iii) {
|
||||
if (listUV[iii] == _uv) {
|
||||
return iii;
|
||||
}
|
||||
}
|
||||
listUV.pushBack(_uv);
|
||||
return listUV.size()-1;
|
||||
}
|
||||
int32_t findColorInList(Color _color) {
|
||||
for (size_t iii=0; iii<listColor.size(); ++iii) {
|
||||
if (listColor[iii] == _color) {
|
||||
return iii;
|
||||
}
|
||||
}
|
||||
listColor.pushBack(_color);
|
||||
return listColor.size()-1;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
package org.atriaSoft.gameEngine.resource;
|
||||
|
||||
import org.atriaSoft.etk.Uri;
|
||||
import org.atriaSoft.gale.Log;
|
||||
import org.atriaSoft.gale.backend3d.OpenGL.RenderMode;
|
||||
import org.atriaSoft.gale.resource.Resource;
|
||||
import org.atriaSoft.gale.resource.ResourceVirtualArrayObject;
|
||||
|
||||
|
||||
public class ResourceStaticColoredMesh extends ResourceStaticMesh {
|
||||
protected float[] vertices = null;
|
||||
protected float[] colors = null;
|
||||
protected float[] normals = null;
|
||||
protected int[] indices = null;
|
||||
|
||||
protected ResourceStaticColoredMesh(Uri uriFile) {
|
||||
super(uriFile);
|
||||
addResourceType("ResourceStaticColoredMesh");
|
||||
}
|
||||
protected ResourceStaticColoredMesh(float[] vertices, float[] colors,
|
||||
float[] normals, int[] indices, RenderMode mode) {
|
||||
super(mode);
|
||||
addResourceType("ResourceStaticColoredMesh");
|
||||
this.vertices = vertices;
|
||||
this.colors = colors;
|
||||
this.normals = normals;
|
||||
this.indices = indices;
|
||||
flush();
|
||||
}
|
||||
/**
|
||||
* @brief Send the data to the graphic card.
|
||||
*/
|
||||
public void flush() {
|
||||
// request to the manager to be call at the next update ...
|
||||
vao = ResourceVirtualArrayObject.create(this.vertices, this.colors, null, this.normals, this.indices);
|
||||
vao.flush();
|
||||
}
|
||||
|
||||
public static ResourceStaticColoredMesh create(float[] vertices, float[] colors,
|
||||
float[] normals, int[] indices, RenderMode mode) {
|
||||
ResourceStaticColoredMesh resource = new ResourceStaticColoredMesh(vertices, colors, normals, indices, mode);
|
||||
if (resource.resourceHasBeenCorectlyInit() == false) {
|
||||
Log.critical("resource Is not correctly init: ResourceVirtualBufferObject");
|
||||
}
|
||||
getManager().localAdd(resource);
|
||||
return resource;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,58 @@
|
||||
package org.atriaSoft.gameEngine.resource;
|
||||
|
||||
import org.atriaSoft.etk.Uri;
|
||||
import org.atriaSoft.gale.Log;
|
||||
import org.atriaSoft.gale.backend3d.OpenGL.RenderMode;
|
||||
import org.atriaSoft.gale.resource.Resource;
|
||||
import org.atriaSoft.gale.resource.ResourceVirtualArrayObject;
|
||||
|
||||
|
||||
public class ResourceStaticMesh extends Resource {
|
||||
protected ResourceVirtualArrayObject vao = null;
|
||||
protected RenderMode mode = RenderMode.quadStrip;
|
||||
|
||||
protected ResourceStaticMesh(Uri uriFile) {
|
||||
super(uriFile);
|
||||
addResourceType("ResourceStaticMesh");
|
||||
}
|
||||
protected ResourceStaticMesh(RenderMode mode) {
|
||||
super();
|
||||
addResourceType("ResourceStaticMesh");
|
||||
this.mode = mode;
|
||||
}
|
||||
|
||||
public void bindForRendering() {
|
||||
if (vao == null) {
|
||||
return;
|
||||
}
|
||||
vao.bindForRendering();
|
||||
}
|
||||
|
||||
public void unBindForRendering() {
|
||||
if (vao == null) {
|
||||
return;
|
||||
}
|
||||
vao.unBindForRendering();
|
||||
}
|
||||
|
||||
public void render() {
|
||||
if (vao == null) {
|
||||
return;
|
||||
}
|
||||
vao.render(mode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cleanUp() {
|
||||
vao.cleanUp();
|
||||
}
|
||||
|
||||
public RenderMode getMode() {
|
||||
return mode;
|
||||
}
|
||||
|
||||
public void setMode(RenderMode mode) {
|
||||
this.mode = mode;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,59 @@
|
||||
package org.atriaSoft.gameEngine.resource;
|
||||
|
||||
import org.atriaSoft.etk.Uri;
|
||||
import org.atriaSoft.gale.Log;
|
||||
import org.atriaSoft.gale.backend3d.OpenGL.RenderMode;
|
||||
import org.atriaSoft.gale.resource.Resource;
|
||||
|
||||
import objConverter.ModelData;
|
||||
import objConverter.OBJFileLoader;
|
||||
|
||||
public class ResourceStaticMeshObj extends ResourceStaticTexturedMesh {
|
||||
private final Uri uriFile;
|
||||
|
||||
public ResourceStaticMeshObj(Uri uriFile) {
|
||||
super(uriFile);
|
||||
addResourceType("ResourceStaticMeshObj");
|
||||
this.uriFile = uriFile;
|
||||
System.out.println("Load file " + uriFile);
|
||||
ModelData data = OBJFileLoader.loadOBJ(uriFile.get());
|
||||
this.vertices = data.getVertices();
|
||||
this.textureCoords = data.getTextureCoords();
|
||||
this.normals = data.getNormals();
|
||||
this.indices = data.getIndices();
|
||||
mode = RenderMode.triangle;
|
||||
flush();
|
||||
}
|
||||
|
||||
public Uri getUriFile() {
|
||||
return uriFile;
|
||||
}
|
||||
|
||||
|
||||
public static ResourceStaticMeshObj create(Uri uriObj) {
|
||||
ResourceStaticMeshObj resource;
|
||||
Resource resource2;
|
||||
String name = uriObj.getValue();
|
||||
if (name.isEmpty() == false && name != "---") {
|
||||
resource2 = getManager().localKeep(name);
|
||||
} else {
|
||||
Log.error("Can not create a shader without a filaname");
|
||||
return null;
|
||||
}
|
||||
if (resource2 != null) {
|
||||
if (resource2 instanceof ResourceStaticMeshObj) {
|
||||
resource2.keep();
|
||||
return (ResourceStaticMeshObj)resource2;
|
||||
}
|
||||
Log.critical("Request resource file : '" + name + "' With the wrong type (dynamic cast error)");
|
||||
return null;
|
||||
}
|
||||
resource = new ResourceStaticMeshObj(uriObj);
|
||||
if (resource.resourceHasBeenCorectlyInit() == false) {
|
||||
Log.critical("resource Is not correctly init : ResourceProgram" );
|
||||
return null;
|
||||
}
|
||||
getManager().localAdd(resource);
|
||||
return resource;
|
||||
}
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
package org.atriaSoft.gameEngine.resource;
|
||||
|
||||
import org.atriaSoft.etk.Uri;
|
||||
import org.atriaSoft.gale.Log;
|
||||
import org.atriaSoft.gale.backend3d.OpenGL.RenderMode;
|
||||
import org.atriaSoft.gale.resource.Resource;
|
||||
import org.atriaSoft.gale.resource.ResourceVirtualArrayObject;
|
||||
|
||||
|
||||
public class ResourceStaticTexturedMesh extends ResourceStaticMesh {
|
||||
protected float[] vertices = null;
|
||||
protected float[] textureCoords = null;
|
||||
protected float[] normals = null;
|
||||
protected int[] indices = null;
|
||||
|
||||
protected ResourceStaticTexturedMesh(Uri uriFile) {
|
||||
super(uriFile);
|
||||
addResourceType("ResourceStaticTexturedMesh");
|
||||
}
|
||||
protected ResourceStaticTexturedMesh(float[] vertices, float[] textureCoordinates,
|
||||
float[] normals, int[] indices, RenderMode mode) {
|
||||
super(mode);
|
||||
addResourceType("ResourceStaticTexturedMesh");
|
||||
this.vertices = vertices;
|
||||
this.textureCoords = textureCoordinates;
|
||||
this.normals = normals;
|
||||
this.indices = indices;
|
||||
}
|
||||
/**
|
||||
* @brief Send the data to the graphic card.
|
||||
*/
|
||||
public void flush() {
|
||||
// request to the manager to be call at the next update ...
|
||||
vao = ResourceVirtualArrayObject.create(this.vertices, this.textureCoords, this.normals, this.indices);
|
||||
vao.flush();
|
||||
}
|
||||
|
||||
public static ResourceStaticTexturedMesh create(float[] vertices, float[] textureCoordinates,
|
||||
float[] normals, int[] indices, RenderMode mode) {
|
||||
ResourceStaticTexturedMesh resource = new ResourceStaticTexturedMesh(vertices, textureCoordinates, normals, indices, mode);
|
||||
if (resource.resourceHasBeenCorectlyInit() == false) {
|
||||
Log.critical("resource Is not correctly init: ResourceVirtualBufferObject");
|
||||
}
|
||||
getManager().localAdd(resource);
|
||||
return resource;
|
||||
}
|
||||
|
||||
}
|
29
src/org/atriaSoft/gameEngine/sample/lowPoly/Log.java
Normal file
29
src/org/atriaSoft/gameEngine/sample/lowPoly/Log.java
Normal file
@ -0,0 +1,29 @@
|
||||
package org.atriaSoft.gameEngine.sample.lowPoly;
|
||||
|
||||
public class Log {
|
||||
private static String LIBNAME = "Sample1";
|
||||
public static void print(String data) {
|
||||
System.out.println(data);
|
||||
}
|
||||
public static void critical(String data) {
|
||||
System.out.println("[C] " + LIBNAME + " | " + data);
|
||||
}
|
||||
public static void error(String data) {
|
||||
System.out.println("[E] " + LIBNAME + " | " + data);
|
||||
}
|
||||
public static void warning(String data) {
|
||||
System.out.println("[W] " + LIBNAME + " | " + data);
|
||||
}
|
||||
public static void info(String data) {
|
||||
System.out.println("[I] " + LIBNAME + " | " + data);
|
||||
}
|
||||
public static void debug(String data) {
|
||||
System.out.println("[D] " + LIBNAME + " | " + data);
|
||||
}
|
||||
public static void verbose(String data) {
|
||||
System.out.println("[V] " + LIBNAME + " | " + data);
|
||||
}
|
||||
public static void todo(String data) {
|
||||
System.out.println("[TODO] " + LIBNAME + " | " + data);
|
||||
}
|
||||
}
|
@ -0,0 +1,169 @@
|
||||
package org.atriaSoft.gameEngine.sample.lowPoly;
|
||||
|
||||
import org.atriaSoft.etk.Color;
|
||||
import org.atriaSoft.etk.Uri;
|
||||
import org.atriaSoft.etk.math.Matrix4f;
|
||||
import org.atriaSoft.etk.math.Quaternion;
|
||||
import org.atriaSoft.etk.math.Transform3D;
|
||||
import org.atriaSoft.etk.math.Vector2f;
|
||||
import org.atriaSoft.etk.math.Vector3f;
|
||||
import org.atriaSoft.gale.Application;
|
||||
import org.atriaSoft.gale.backend3d.OpenGL;
|
||||
import org.atriaSoft.gale.backend3d.OpenGL.Flag;
|
||||
import org.atriaSoft.gale.context.Context;
|
||||
import org.atriaSoft.gameEngine.ControlCameraSimple;
|
||||
import org.atriaSoft.gameEngine.Entity;
|
||||
import org.atriaSoft.gameEngine.Environement;
|
||||
import org.atriaSoft.gameEngine.GameStatus;
|
||||
import org.atriaSoft.gameEngine.Light;
|
||||
import org.atriaSoft.gameEngine.Material;
|
||||
import org.atriaSoft.gameEngine.camera.Camera;
|
||||
import org.atriaSoft.gameEngine.components.ComponentLight;
|
||||
import org.atriaSoft.gameEngine.components.ComponentLightSun;
|
||||
import org.atriaSoft.gameEngine.components.ComponentMaterial;
|
||||
import org.atriaSoft.gameEngine.components.ComponentPosition;
|
||||
import org.atriaSoft.gameEngine.components.ComponentRenderColoredStaticMesh;
|
||||
import org.atriaSoft.gameEngine.components.ComponentRenderTexturedMaterialsStaticMesh;
|
||||
import org.atriaSoft.gameEngine.components.ComponentRenderTexturedStaticMesh;
|
||||
import org.atriaSoft.gameEngine.components.ComponentStaticMesh;
|
||||
import org.atriaSoft.gameEngine.components.ComponentTexture;
|
||||
import org.atriaSoft.gameEngine.engines.EngineLight;
|
||||
import org.atriaSoft.gameEngine.tools.MeshGenerator;
|
||||
import org.atriaSoft.gale.key.KeyKeyboard;
|
||||
import org.atriaSoft.gale.key.KeySpecial;
|
||||
import org.atriaSoft.gale.key.KeyStatus;
|
||||
import org.atriaSoft.gale.key.KeyType;
|
||||
|
||||
public class LowPolyApplication extends Application {
|
||||
private Environement env;
|
||||
private ComponentPosition objectPosition;
|
||||
private Quaternion basicRotation = Quaternion.identity();
|
||||
private Quaternion basicRotation2 = Quaternion.identity();
|
||||
private boolean creationDone;
|
||||
private ControlCameraSimple simpleControl;
|
||||
private Material materialCube;
|
||||
public LowPolyApplication(){
|
||||
creationDone = false;
|
||||
}
|
||||
@Override
|
||||
public void onCreate(Context _context) {
|
||||
env = new Environement();
|
||||
this.canDraw = true;
|
||||
setSize(new Vector2f(800, 600));
|
||||
setTitle("Low Poly sample");
|
||||
|
||||
// simple sun to have a global light ...
|
||||
Entity sun = new Entity(this.env);
|
||||
sun.addComponent(new ComponentPosition(new Transform3D(new Vector3f(1000,1000,1000))));
|
||||
sun.addComponent(new ComponentLightSun(new Light(new Vector3f(1,0,0), new Vector3f(0,0,0), new Vector3f(1,0,0))));
|
||||
env.addEntity(sun);
|
||||
|
||||
// add a cube to show where in the light ...
|
||||
Entity localLight = new Entity(this.env);
|
||||
localLight.addComponent(new ComponentPosition(new Transform3D(new Vector3f(-10,-10,0))));
|
||||
localLight.addComponent(new ComponentStaticMesh(new Uri("RES", "cube.obj")));
|
||||
localLight.addComponent(new ComponentTexture(new Uri("RES", "dirt.png")));
|
||||
localLight.addComponent(new ComponentLight(new Light(new Vector3f(0,1,0), new Vector3f(0,0,0), new Vector3f(1,0,0))));
|
||||
localLight.addComponent(new ComponentRenderTexturedStaticMesh(new Uri("DATA", "basic.vert"), new Uri("DATA", "basic.frag")));
|
||||
env.addEntity(localLight);
|
||||
|
||||
Entity gird = new Entity(this.env);
|
||||
gird.addComponent(new ComponentPosition(new Transform3D(new Vector3f(0,0,0))));
|
||||
gird.addComponent(new ComponentStaticMesh(MeshGenerator.createGrid(5)));
|
||||
gird.addComponent(new ComponentRenderColoredStaticMesh(new Uri("DATA_EGE", "wireColor.vert"), new Uri("DATA_EGE", "wireColor.frag")));
|
||||
env.addEntity(gird);
|
||||
|
||||
Entity basicTree = new Entity(this.env);
|
||||
objectPosition = new ComponentPosition(new Transform3D(new Vector3f(0,0,0)));
|
||||
basicTree.addComponent(objectPosition);
|
||||
materialCube = new Material();
|
||||
basicTree.addComponent(new ComponentMaterial(materialCube));
|
||||
basicTree.addComponent(new ComponentStaticMesh(new Uri("RES", "cube.obj")));
|
||||
basicTree.addComponent(new ComponentTexture(new Uri("RES", "dirt.png")));
|
||||
basicTree.addComponent(new ComponentRenderTexturedMaterialsStaticMesh(
|
||||
new Uri("DATA", "basicMaterial.vert"),
|
||||
new Uri("DATA", "basicMaterial.frag"),
|
||||
(EngineLight)env.getEngine(EngineLight.ENGINE_NAME)));
|
||||
env.addEntity(basicTree);
|
||||
|
||||
|
||||
Camera mainView = new Camera();
|
||||
env.addCamera("default", mainView);
|
||||
mainView.setPitch((float)Math.PI*-0.25f);
|
||||
mainView.setPosition(new Vector3f(0,-5,5));
|
||||
|
||||
this.simpleControl = new ControlCameraSimple(mainView);
|
||||
env.addControlInterface(simpleControl);
|
||||
|
||||
// start the engine.
|
||||
env.setPropertyStatus(GameStatus.gameStart);
|
||||
|
||||
basicRotation.setEulerAngles(new Vector3f(0.005f,0.005f,0.01f));
|
||||
basicRotation2.setEulerAngles(new Vector3f(0.003f,0.01f,0.001f));
|
||||
// ready to let Gale & Ege manage the display
|
||||
Log.info("==> Init APPL (END)");
|
||||
creationDone = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRegenerateDisplay(Context context) {
|
||||
//Log.verbose("Regenerate Gale Application");
|
||||
if (this.creationDone == false) {
|
||||
return;
|
||||
}
|
||||
materialCube.setAmbientFactor(new Vector3f(1.0f,1.0f,1.0f));
|
||||
// apply a little rotation to show the element move
|
||||
objectPosition.getTransform().applyRotation(basicRotation);
|
||||
objectPosition.getTransform().applyRotation(basicRotation2);
|
||||
env.periodicCall();
|
||||
markDrawingIsNeeded();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDraw(Context _context) {
|
||||
//Log.info("==> appl Draw ...");
|
||||
Vector2f size = getSize();
|
||||
if (this.creationDone == false) {
|
||||
OpenGL.setViewPort(new Vector2f(0,0), size);
|
||||
Color bgColor = new Color(0.8f, 0.5f, 0.5f, 1.0f);
|
||||
OpenGL.clearColor(bgColor);
|
||||
return;
|
||||
}
|
||||
// Store openGl context.
|
||||
OpenGL.push();
|
||||
// set projection matrix:
|
||||
Matrix4f tmpProjection = Matrix4f.createMatrixPerspective(3.14f*0.5f, getAspectRatio(), 0.1f, 50000);
|
||||
OpenGL.setMatrix(tmpProjection);
|
||||
|
||||
// set the basic openGL view port: (Draw in all the windows...)
|
||||
OpenGL.setViewPort(new Vector2f(0,0), size);
|
||||
|
||||
// clear background
|
||||
Color bgColor = new Color(0.0f, 1.0f, 0.0f, 1.0f);
|
||||
OpenGL.clearColor(bgColor);
|
||||
// real clear request:
|
||||
OpenGL.clear(OpenGL.ClearFlag.clearFlag_colorBuffer);
|
||||
OpenGL.clear(OpenGL.ClearFlag.clearFlag_depthBuffer);
|
||||
OpenGL.enable(Flag.flag_depthTest);
|
||||
|
||||
env.render(20, "default");
|
||||
|
||||
// Restore context of matrix
|
||||
OpenGL.pop();
|
||||
}
|
||||
@Override
|
||||
public void onPointer(KeySpecial special,
|
||||
KeyType type,
|
||||
int pointerID,
|
||||
Vector2f pos,
|
||||
KeyStatus state) {
|
||||
env.onPointer(special, type, pointerID, pos, state);
|
||||
}
|
||||
@Override
|
||||
public void onKeyboard(KeySpecial special,
|
||||
KeyKeyboard type,
|
||||
Character value,
|
||||
KeyStatus state) {
|
||||
env.onKeyboard(special, type, value, state);
|
||||
}
|
||||
}
|
17
src/org/atriaSoft/gameEngine/sample/lowPoly/basic.frag
Normal file
17
src/org/atriaSoft/gameEngine/sample/lowPoly/basic.frag
Normal file
@ -0,0 +1,17 @@
|
||||
#version 400 core
|
||||
|
||||
#ifdef GL_ES
|
||||
precision mediump float;
|
||||
precision mediump int;
|
||||
#endif
|
||||
|
||||
in vec2 io_textureCoords;
|
||||
|
||||
uniform sampler2D in_textureBase;
|
||||
|
||||
// output:
|
||||
out vec4 out_Color;
|
||||
|
||||
void main(void) {
|
||||
out_Color = texture(in_textureBase, io_textureCoords);
|
||||
}
|
21
src/org/atriaSoft/gameEngine/sample/lowPoly/basic.vert
Normal file
21
src/org/atriaSoft/gameEngine/sample/lowPoly/basic.vert
Normal file
@ -0,0 +1,21 @@
|
||||
#version 400 core
|
||||
|
||||
#ifdef GL_ES
|
||||
precision mediump float;
|
||||
precision mediump int;
|
||||
#endif
|
||||
|
||||
// Input:
|
||||
in vec3 in_position;
|
||||
in vec2 in_textureCoords;
|
||||
uniform mat4 in_matrixTransformation;
|
||||
uniform mat4 in_matrixProjection;
|
||||
uniform mat4 in_matrixView;
|
||||
|
||||
// output:
|
||||
out vec2 io_textureCoords;
|
||||
|
||||
void main(void) {
|
||||
gl_Position = in_matrixProjection * in_matrixView * in_matrixTransformation * vec4(in_position, 1.0);
|
||||
io_textureCoords = in_textureCoords;
|
||||
}
|
@ -0,0 +1,80 @@
|
||||
#version 400 core
|
||||
|
||||
#ifdef GL_ES
|
||||
precision mediump float;
|
||||
precision mediump int;
|
||||
#endif
|
||||
|
||||
struct Light {
|
||||
vec3 color;
|
||||
vec3 position;
|
||||
vec3 attenuation;
|
||||
};
|
||||
|
||||
struct Material {
|
||||
vec3 ambientFactor;
|
||||
vec3 diffuseFactor;
|
||||
vec3 specularFactor;
|
||||
float shininess;
|
||||
};
|
||||
const int MAX_LIGHT_NUMBER = 8;
|
||||
|
||||
|
||||
in vec2 io_textureCoords;
|
||||
in vec3 io_surfaceNormal;
|
||||
in vec3 io_toCameraVector;
|
||||
in vec3 io_toLightVector[MAX_LIGHT_NUMBER];
|
||||
// FOW: Fog Of War result calculation
|
||||
in float io_fowVisibility;
|
||||
|
||||
// texture properties
|
||||
uniform sampler2D in_textureBase;
|
||||
// Material
|
||||
uniform Material in_material;
|
||||
// 2 light for suns and other for locals ...
|
||||
uniform Light in_lights[MAX_LIGHT_NUMBER];
|
||||
// global color of the sky ... needed to have a better color for the FOW
|
||||
//uniform vec3 in_sky_color;
|
||||
const vec3 in_sky_color = vec3(1.0,1.0,0.5);
|
||||
|
||||
// output:
|
||||
out vec4 out_Color;
|
||||
|
||||
void main(void) {
|
||||
// disable transparency elements in the texture ...
|
||||
// Can be set at the start of the shader ...
|
||||
vec4 textureColour = texture(in_textureBase, io_textureCoords);
|
||||
if (textureColour.a < 0.5) {
|
||||
discard;
|
||||
}
|
||||
|
||||
vec3 unitNormal = normalize(io_surfaceNormal);
|
||||
vec3 unitVectorToCamera = normalize(io_toCameraVector);
|
||||
vec3 totalDiffuse = vec3(0.0);
|
||||
vec3 totalSpecular = vec3(0.0);
|
||||
for(int iii=0; iii<MAX_LIGHT_NUMBER; iii++) {
|
||||
float distance = length(io_toLightVector[iii]);
|
||||
float attenuationFactor = in_lights[iii].attenuation.x + (in_lights[iii].attenuation.y * distance) + (in_lights[iii].attenuation.z * distance * distance);
|
||||
vec3 unitLightVector = normalize(io_toLightVector[iii]);
|
||||
float nDot1 = dot(unitNormal, unitLightVector);
|
||||
float brightness = max(nDot1, 0.0);
|
||||
vec3 lightDirection = -unitLightVector;
|
||||
vec3 reflectedLightDirection = reflect(lightDirection, unitNormal);
|
||||
float specularFactor = dot(reflectedLightDirection, unitVectorToCamera);
|
||||
specularFactor = max(specularFactor, 0.0);
|
||||
float damperFactor = pow(specularFactor, in_material.shininess);
|
||||
vec3 diffuse = (brightness * in_lights[iii].color) / attenuationFactor;;
|
||||
vec3 finalSpecular = (damperFactor * in_material.specularFactor.x * in_lights[iii].color) / attenuationFactor; // TODO: Remove the x ....
|
||||
totalDiffuse = totalDiffuse + diffuse;
|
||||
totalSpecular = totalSpecular + finalSpecular;
|
||||
}
|
||||
// the 0.2 represent the ambiant lightning ==> maybe set an uniform for this
|
||||
totalDiffuse = max(totalDiffuse, 0.2);
|
||||
|
||||
out_Color = vec4(totalDiffuse,1.0) * textureColour + vec4(totalSpecular, 1.0);
|
||||
out_Color = mix(vec4(in_sky_color,1.0), out_Color, io_fowVisibility);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -0,0 +1,59 @@
|
||||
#version 400 core
|
||||
|
||||
#ifdef GL_ES
|
||||
precision mediump float;
|
||||
precision mediump int;
|
||||
#endif
|
||||
|
||||
struct Light {
|
||||
vec3 color;
|
||||
vec3 position;
|
||||
vec3 attenuation;
|
||||
};
|
||||
const int MAX_LIGHT_NUMBER = 8;
|
||||
|
||||
// Input:
|
||||
in vec3 in_position;
|
||||
in vec3 in_normal;
|
||||
in vec2 in_textureCoords;
|
||||
// 2 light for suns and other for locals ...
|
||||
uniform Light in_lights[MAX_LIGHT_NUMBER];
|
||||
|
||||
uniform mat4 in_matrixTransformation;
|
||||
uniform mat4 in_matrixProjection;
|
||||
uniform mat4 in_matrixView;
|
||||
|
||||
//uniform float in_numberOfRows;
|
||||
//uniform vec2 in_offset;
|
||||
const float in_numberOfRows = 1;
|
||||
const vec2 in_offset = vec2(0.0,0.0);
|
||||
|
||||
// Configuration of the FOV ==> TODO: Set it in parameter uniform ...
|
||||
const float c_density = 0.007;
|
||||
const float c_gradient = 1.5;
|
||||
|
||||
// output:
|
||||
out vec2 io_textureCoords;
|
||||
out vec3 io_surfaceNormal;
|
||||
out vec3 io_toCameraVector;
|
||||
out vec3 io_toLightVector[MAX_LIGHT_NUMBER];
|
||||
// FOW: Fog Of War result calculation
|
||||
out float io_fowVisibility;
|
||||
|
||||
void main(void) {
|
||||
vec4 worldPosition = in_matrixTransformation * vec4(in_position, 1.0);
|
||||
vec4 positionRelativeToCam = in_matrixView * worldPosition;
|
||||
gl_Position = in_matrixProjection * positionRelativeToCam;
|
||||
io_textureCoords = (in_textureCoords/in_numberOfRows) + in_offset;
|
||||
|
||||
io_surfaceNormal = (in_matrixTransformation * vec4(in_normal, 0.0)).xyz;
|
||||
for(int iii=0;iii<MAX_LIGHT_NUMBER;iii++) {
|
||||
io_toLightVector[iii] = in_lights[iii].position - worldPosition.xyz;
|
||||
}
|
||||
io_toCameraVector = (inverse(in_matrixView) * vec4(0.0,0.0,0.0,1.0)).xyz - worldPosition.xyz;
|
||||
|
||||
float distance = length(positionRelativeToCam.xyz);
|
||||
|
||||
io_fowVisibility = exp(-pow((distance*c_density),c_gradient));
|
||||
io_fowVisibility = clamp(io_fowVisibility, 0.0, 1.0);
|
||||
}
|
@ -1,5 +1,13 @@
|
||||
package org.atriaSoft.gameEngine.sample.lowPoly;
|
||||
|
||||
public class sample_lowPoly {
|
||||
import org.atriaSoft.etk.Uri;
|
||||
import org.atriaSoft.gale.Gale;
|
||||
|
||||
public class sample_lowPoly {
|
||||
public static void main(String[] args) {
|
||||
Uri.setGroup("DATA", "src/org/atriaSoft/gameEngine/sample/lowPoly/");
|
||||
Uri.setGroup("DATA_EGE", "src/org/atriaSoft/gameEngine/data/");
|
||||
Uri.setGroup("RES", "res");
|
||||
Gale.run(new LowPolyApplication(), args);
|
||||
}
|
||||
}
|
||||
|
29
src/org/atriaSoft/gameEngine/sample/s1_texturedCube/Log.java
Normal file
29
src/org/atriaSoft/gameEngine/sample/s1_texturedCube/Log.java
Normal file
@ -0,0 +1,29 @@
|
||||
package org.atriaSoft.gameEngine.sample.s1_texturedCube;
|
||||
|
||||
public class Log {
|
||||
private static String LIBNAME = "Sample1";
|
||||
public static void print(String data) {
|
||||
System.out.println(data);
|
||||
}
|
||||
public static void critical(String data) {
|
||||
System.out.println("[C] " + LIBNAME + " | " + data);
|
||||
}
|
||||
public static void error(String data) {
|
||||
System.out.println("[E] " + LIBNAME + " | " + data);
|
||||
}
|
||||
public static void warning(String data) {
|
||||
System.out.println("[W] " + LIBNAME + " | " + data);
|
||||
}
|
||||
public static void info(String data) {
|
||||
System.out.println("[I] " + LIBNAME + " | " + data);
|
||||
}
|
||||
public static void debug(String data) {
|
||||
System.out.println("[D] " + LIBNAME + " | " + data);
|
||||
}
|
||||
public static void verbose(String data) {
|
||||
System.out.println("[V] " + LIBNAME + " | " + data);
|
||||
}
|
||||
public static void todo(String data) {
|
||||
System.out.println("[TODO] " + LIBNAME + " | " + data);
|
||||
}
|
||||
}
|
@ -0,0 +1,140 @@
|
||||
package org.atriaSoft.gameEngine.sample.s1_texturedCube;
|
||||
|
||||
import org.atriaSoft.etk.Color;
|
||||
import org.atriaSoft.etk.Uri;
|
||||
import org.atriaSoft.etk.math.Matrix4f;
|
||||
import org.atriaSoft.etk.math.Quaternion;
|
||||
import org.atriaSoft.etk.math.Transform3D;
|
||||
import org.atriaSoft.etk.math.Vector2f;
|
||||
import org.atriaSoft.etk.math.Vector3f;
|
||||
import org.atriaSoft.gale.Application;
|
||||
import org.atriaSoft.gale.backend3d.OpenGL;
|
||||
import org.atriaSoft.gale.backend3d.OpenGL.Flag;
|
||||
import org.atriaSoft.gale.context.Context;
|
||||
import org.atriaSoft.gameEngine.ControlCameraSimple;
|
||||
import org.atriaSoft.gameEngine.Entity;
|
||||
import org.atriaSoft.gameEngine.Environement;
|
||||
import org.atriaSoft.gameEngine.GameStatus;
|
||||
import org.atriaSoft.gameEngine.camera.Camera;
|
||||
import org.atriaSoft.gameEngine.components.ComponentPosition;
|
||||
import org.atriaSoft.gameEngine.components.ComponentRenderColoredStaticMesh;
|
||||
import org.atriaSoft.gameEngine.components.ComponentRenderTexturedStaticMesh;
|
||||
import org.atriaSoft.gameEngine.components.ComponentStaticMesh;
|
||||
import org.atriaSoft.gameEngine.components.ComponentTexture;
|
||||
import org.atriaSoft.gameEngine.tools.MeshGenerator;
|
||||
import org.atriaSoft.gale.key.KeyKeyboard;
|
||||
import org.atriaSoft.gale.key.KeySpecial;
|
||||
import org.atriaSoft.gale.key.KeyStatus;
|
||||
import org.atriaSoft.gale.key.KeyType;
|
||||
|
||||
public class S1Application extends Application {
|
||||
private Environement env;
|
||||
private ComponentPosition objectPosition;
|
||||
private Quaternion basicRotation = Quaternion.identity();
|
||||
private Quaternion basicRotation2 = Quaternion.identity();
|
||||
private boolean creationDone;
|
||||
private ControlCameraSimple simpleControl;
|
||||
public S1Application(){
|
||||
creationDone = false;
|
||||
}
|
||||
@Override
|
||||
public void onCreate(Context _context) {
|
||||
env = new Environement();
|
||||
this.canDraw = true;
|
||||
setSize(new Vector2f(800, 600));
|
||||
setTitle("Low Poly sample");
|
||||
|
||||
Entity gird = new Entity(this.env);
|
||||
gird.addComponent(new ComponentPosition(new Transform3D(new Vector3f(0,0,0))));
|
||||
gird.addComponent(new ComponentStaticMesh(MeshGenerator.createGrid(5)));
|
||||
gird.addComponent(new ComponentRenderColoredStaticMesh(new Uri("DATA_EGE", "wireColor.vert"), new Uri("DATA_EGE", "wireColor.frag")));
|
||||
env.addEntity(gird);
|
||||
|
||||
Entity basicTree = new Entity(this.env);
|
||||
objectPosition = new ComponentPosition(new Transform3D(new Vector3f(0,0,0)));
|
||||
basicTree.addComponent(objectPosition);
|
||||
basicTree.addComponent(new ComponentStaticMesh(new Uri("RES", "cube.obj")));
|
||||
basicTree.addComponent(new ComponentTexture(new Uri("RES", "dirt.png")));
|
||||
basicTree.addComponent(new ComponentRenderTexturedStaticMesh(new Uri("DATA", "basic.vert"), new Uri("DATA", "basic.frag")));
|
||||
env.addEntity(basicTree);
|
||||
|
||||
|
||||
Camera mainView = new Camera();
|
||||
env.addCamera("default", mainView);
|
||||
mainView.setPitch((float)Math.PI*-0.25f);
|
||||
mainView.setPosition(new Vector3f(0,-5,5));
|
||||
|
||||
this.simpleControl = new ControlCameraSimple(mainView);
|
||||
env.addControlInterface(simpleControl);
|
||||
|
||||
// start the engine.
|
||||
env.setPropertyStatus(GameStatus.gameStart);
|
||||
|
||||
basicRotation.setEulerAngles(new Vector3f(0.005f,0.005f,0.01f));
|
||||
basicRotation2.setEulerAngles(new Vector3f(0.003f,0.01f,0.001f));
|
||||
// ready to let Gale & Ege manage the display
|
||||
Log.info("==> Init APPL (END)");
|
||||
creationDone = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRegenerateDisplay(Context context) {
|
||||
//Log.verbose("Regenerate Gale Application");
|
||||
if (this.creationDone == false) {
|
||||
return;
|
||||
}
|
||||
// apply a litthe rotation to show the element move
|
||||
objectPosition.getTransform().applyRotation(basicRotation);
|
||||
objectPosition.getTransform().applyRotation(basicRotation2);
|
||||
env.periodicCall();
|
||||
markDrawingIsNeeded();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDraw(Context _context) {
|
||||
//Log.info("==> appl Draw ...");
|
||||
Vector2f size = getSize();
|
||||
if (this.creationDone == false) {
|
||||
OpenGL.setViewPort(new Vector2f(0,0), size);
|
||||
Color bgColor = new Color(0.8f, 0.5f, 0.5f, 1.0f);
|
||||
OpenGL.clearColor(bgColor);
|
||||
return;
|
||||
}
|
||||
// Store openGl context.
|
||||
OpenGL.push();
|
||||
// set projection matrix:
|
||||
Matrix4f tmpProjection = Matrix4f.createMatrixPerspective(3.14f*0.5f, getAspectRatio(), 0.1f, 50000);
|
||||
OpenGL.setMatrix(tmpProjection);
|
||||
|
||||
// set the basic openGL view port: (Draw in all the windows...)
|
||||
OpenGL.setViewPort(new Vector2f(0,0), size);
|
||||
|
||||
// clear background
|
||||
Color bgColor = new Color(0.0f, 1.0f, 0.0f, 1.0f);
|
||||
OpenGL.clearColor(bgColor);
|
||||
// real clear request:
|
||||
OpenGL.clear(OpenGL.ClearFlag.clearFlag_colorBuffer);
|
||||
OpenGL.clear(OpenGL.ClearFlag.clearFlag_depthBuffer);
|
||||
OpenGL.enable(Flag.flag_depthTest);
|
||||
|
||||
env.render(20, "default");
|
||||
|
||||
// Restore context of matrix
|
||||
OpenGL.pop();
|
||||
}
|
||||
@Override
|
||||
public void onPointer(KeySpecial special,
|
||||
KeyType type,
|
||||
int pointerID,
|
||||
Vector2f pos,
|
||||
KeyStatus state) {
|
||||
env.onPointer(special, type, pointerID, pos, state);
|
||||
}
|
||||
@Override
|
||||
public void onKeyboard(KeySpecial special,
|
||||
KeyKeyboard type,
|
||||
Character value,
|
||||
KeyStatus state) {
|
||||
env.onKeyboard(special, type, value, state);
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package org.atriaSoft.gameEngine.sample.s1_texturedCube;
|
||||
|
||||
import org.atriaSoft.etk.Uri;
|
||||
import org.atriaSoft.gale.Gale;
|
||||
|
||||
public class Sample1TexturedCube {
|
||||
public static void main(String[] args) {
|
||||
Uri.setGroup("DATA", "src/org/atriaSoft/gameEngine/sample/s1_texturedCube/");
|
||||
Uri.setGroup("DATA_EGE", "src/org/atriaSoft/gameEngine/data/");
|
||||
Uri.setGroup("RES", "res");
|
||||
Gale.run(new S1Application(), args);
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
#version 400 core
|
||||
|
||||
#ifdef GL_ES
|
||||
precision mediump float;
|
||||
precision mediump int;
|
||||
#endif
|
||||
|
||||
in vec2 io_textureCoords;
|
||||
|
||||
uniform sampler2D in_textureBase;
|
||||
|
||||
// output:
|
||||
out vec4 out_Color;
|
||||
|
||||
void main(void) {
|
||||
out_Color = texture(in_textureBase, io_textureCoords);
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
#version 400 core
|
||||
|
||||
#ifdef GL_ES
|
||||
precision mediump float;
|
||||
precision mediump int;
|
||||
#endif
|
||||
|
||||
// Input:
|
||||
in vec3 in_position;
|
||||
in vec2 in_textureCoords;
|
||||
uniform mat4 in_matrixTransformation;
|
||||
uniform mat4 in_matrixProjection;
|
||||
uniform mat4 in_matrixView;
|
||||
|
||||
// output:
|
||||
out vec2 io_textureCoords;
|
||||
|
||||
void main(void) {
|
||||
gl_Position = in_matrixProjection * in_matrixView * in_matrixTransformation * vec4(in_position, 1.0);
|
||||
io_textureCoords = in_textureCoords;
|
||||
}
|
13
src/org/atriaSoft/gameEngine/sample/todo_sample.md
Normal file
13
src/org/atriaSoft/gameEngine/sample/todo_sample.md
Normal file
@ -0,0 +1,13 @@
|
||||
TODO sample in order...
|
||||
=======================
|
||||
|
||||
- [ OK ] Textured cube
|
||||
- [TODO] Material
|
||||
- [TODO] Simple Light
|
||||
- [TODO] Multiple Lights
|
||||
- [TODO] Map (simple plan)
|
||||
- [TODO] Fog
|
||||
- [TODO] EnvironementBox with night and day
|
||||
- [TODO] Ray tracing
|
||||
- [TODO] Simple player moving (FPS/behind)
|
||||
|
467
src/org/atriaSoft/gameEngine/tools/MeshGenerator.java
Normal file
467
src/org/atriaSoft/gameEngine/tools/MeshGenerator.java
Normal file
@ -0,0 +1,467 @@
|
||||
package org.atriaSoft.gameEngine.tools;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.atriaSoft.etk.Color;
|
||||
import org.atriaSoft.etk.math.Vector3f;
|
||||
import org.atriaSoft.gale.backend3d.OpenGL.RenderMode;
|
||||
import org.atriaSoft.gameEngine.resource.ResourceStaticColoredMesh;
|
||||
|
||||
class MeshData {
|
||||
public List<Vector3f> vertices = new ArrayList<Vector3f>();
|
||||
public List<Color> colors = new ArrayList<Color>();
|
||||
public List<Integer> indices = new ArrayList<Integer>();
|
||||
|
||||
|
||||
public void addLine(Vector3f pos1, Vector3f pos2, Color color) {
|
||||
vertices.add(pos1);
|
||||
vertices.add(pos2);
|
||||
colors.add(color);
|
||||
colors.add(color);
|
||||
indices.add(vertices.size()-2);
|
||||
indices.add(vertices.size()-1);
|
||||
}
|
||||
public void addLines(List<Vector3f> pos, Color color) {
|
||||
for (int iii=1; iii<pos.size(); iii++) {
|
||||
addLine(pos.get(iii-1), pos.get(iii), color);
|
||||
}
|
||||
}
|
||||
public float[] getListOfVertices() {
|
||||
float[] out = new float[vertices.size()*3];
|
||||
for (int iii=0; iii<vertices.size(); iii++) {
|
||||
out[iii*3] = vertices.get(iii).x;
|
||||
out[iii*3+1] = vertices.get(iii).y;
|
||||
out[iii*3+2] = vertices.get(iii).z;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
public float[] getListOfColors() {
|
||||
float[] out = new float[colors.size()*4];
|
||||
for (int iii=0; iii<colors.size(); iii++) {
|
||||
out[iii*4] = colors.get(iii).r;
|
||||
out[iii*4+1] = colors.get(iii).g;
|
||||
out[iii*4+2] = colors.get(iii).b;
|
||||
out[iii*4+3] = colors.get(iii).a;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
public int[] getListOfIndices() {
|
||||
int[] out = new int[indices.size()];
|
||||
for (int iii=0; iii<indices.size(); iii++) {
|
||||
out[iii] = indices.get(iii);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public class MeshGenerator {
|
||||
|
||||
public static ResourceStaticColoredMesh createGrid(int _lineCount) {
|
||||
MeshData meshData = new MeshData();
|
||||
Color colorRed = new Color(1,0,0,1);
|
||||
Color colorGreen = new Color(0,1,0,1);
|
||||
Color colorBlue = new Color(0,0,1,1);
|
||||
Color colorGray = new Color(0.5f,0.5f,0.5f,1);
|
||||
// create X lines
|
||||
for (int iii=-_lineCount; iii<=_lineCount; ++iii) {
|
||||
if (iii==0) {
|
||||
meshData.addLine(new Vector3f(-_lineCount,0,0), new Vector3f(_lineCount+1,0,0), colorRed);
|
||||
// arrow
|
||||
meshData.addLine(new Vector3f(_lineCount+1.0f,0,0), new Vector3f(_lineCount+0.5f,0.5f,0), colorRed);
|
||||
meshData.addLine(new Vector3f(_lineCount+1.0f,0,0), new Vector3f(_lineCount+0.5f,-0.5f,0), colorRed);
|
||||
meshData.addLine(new Vector3f(_lineCount+1.0f,0,0), new Vector3f(_lineCount+0.5f,0,0.5f), colorRed);
|
||||
meshData.addLine(new Vector3f(_lineCount+1.0f,0,0), new Vector3f(_lineCount+0.5f,0,-0.5f), colorRed);
|
||||
// X letter
|
||||
meshData.addLine(new Vector3f(_lineCount+2.0f,1.0f,-1.0f), new Vector3f(_lineCount+2.0f,-1.0f,1.0f), colorRed);
|
||||
meshData.addLine(new Vector3f(_lineCount+2.0f,-1.0f,-1.0f), new Vector3f(_lineCount+2.0f,1.0f,1.0f), colorRed);
|
||||
} else {
|
||||
meshData.addLine(new Vector3f(-_lineCount,iii,0), new Vector3f(_lineCount,iii,0), colorGray);
|
||||
}
|
||||
//out.addPoint(new Vector3f(-_lineCount,iii,0), etk::color::white);
|
||||
//out.addPoint(new Vector3f(_lineCount,iii,0), etk::color::white);
|
||||
}
|
||||
// create Y lines
|
||||
for (int iii=-_lineCount; iii<=_lineCount; ++iii) {
|
||||
if (iii==0) {
|
||||
meshData.addLine(new Vector3f(0,-_lineCount,0), new Vector3f(0,_lineCount+1,0), colorGreen);
|
||||
// arrow
|
||||
meshData.addLine(new Vector3f(0,_lineCount+1.0f,0), new Vector3f(0.5f,_lineCount+0.5f,0), colorGreen);
|
||||
meshData.addLine(new Vector3f(0,_lineCount+1.0f,0), new Vector3f(-0.5f,_lineCount+0.5f,0), colorGreen);
|
||||
meshData.addLine(new Vector3f(0,_lineCount+1.0f,0), new Vector3f(0,_lineCount+0.5f,0.5f), colorGreen);
|
||||
meshData.addLine(new Vector3f(0,_lineCount+1.0f,0), new Vector3f(0,_lineCount+0.5f,-0.5f), colorGreen);
|
||||
// Y letter
|
||||
meshData.addLine(new Vector3f(0,_lineCount+2.0f,0), new Vector3f(0.7f,_lineCount+2.0f,1.0f), colorGreen);
|
||||
meshData.addLine(new Vector3f(0,_lineCount+2.0f,0), new Vector3f(-0.7f,_lineCount+2.0f,1.0f), colorGreen);
|
||||
meshData.addLine(new Vector3f(0,_lineCount+2.0f,0), new Vector3f(0,_lineCount+2.0f,-1.0f), colorGreen);
|
||||
} else {
|
||||
meshData.addLine(new Vector3f(iii,-_lineCount,0), new Vector3f(iii,_lineCount,0), colorGray);
|
||||
}
|
||||
//out.addPoint(new Vector3f(iii,-_lineCount,0), etk::color::white);
|
||||
//out.addPoint(new Vector3f(iii,_lineCount,0), etk::color::white);
|
||||
}
|
||||
// create Z lines
|
||||
for (int iii=-_lineCount; iii<=_lineCount; ++iii) {
|
||||
if (iii==0) {
|
||||
meshData.addLine(new Vector3f(0,0,-_lineCount), new Vector3f(0,0,_lineCount+1), colorBlue);
|
||||
// arrow
|
||||
meshData.addLine(new Vector3f(0,0,_lineCount+1), new Vector3f(0.5f,0,_lineCount+0.5f), colorBlue);
|
||||
meshData.addLine(new Vector3f(0,0,_lineCount+1), new Vector3f(-0.5f,0,_lineCount+0.5f), colorBlue);
|
||||
meshData.addLine(new Vector3f(0,0,_lineCount+1), new Vector3f(0,0.5f,_lineCount+0.5f), colorBlue);
|
||||
meshData.addLine(new Vector3f(0,0,_lineCount+1), new Vector3f(0,-0.5f,_lineCount+0.5f), colorBlue);
|
||||
// Z letter
|
||||
meshData.addLine(new Vector3f( 1,-1,_lineCount+2.0f), new Vector3f( 1, 1,_lineCount+2.0f), colorBlue);
|
||||
meshData.addLine(new Vector3f( 1, 1,_lineCount+2.0f), new Vector3f(-1,-1,_lineCount+2.0f), colorBlue);
|
||||
meshData.addLine(new Vector3f(-1,-1,_lineCount+2.0f), new Vector3f(-1, 1,_lineCount+2.0f), colorBlue);
|
||||
|
||||
} else {
|
||||
List<Vector3f> list = new ArrayList<Vector3f>();
|
||||
list.add(new Vector3f(-1,-1,iii));
|
||||
list.add(new Vector3f(1,-1,iii));
|
||||
list.add(new Vector3f(1,1,iii));
|
||||
list.add(new Vector3f(-1,1,iii));
|
||||
list.add(new Vector3f(-1,-1,iii));
|
||||
meshData.addLines(list, colorGray);
|
||||
}
|
||||
//out.addPoint(_materialName, new Vector3f(iii,-_lineCount,0), etk::color::white);
|
||||
//out.addPoint(_materialName, new Vector3f(iii,_lineCount,0), etk::color::white);
|
||||
}
|
||||
return ResourceStaticColoredMesh.create(meshData.getListOfVertices(), meshData.getListOfColors(),
|
||||
null, meshData.getListOfIndices(), RenderMode.line);
|
||||
}
|
||||
|
||||
// public static ResourceMesh createCube(float _size=1.0f,
|
||||
// const etk::String& _materialName="basics",
|
||||
// Color _color=etk::color::green) {
|
||||
// return createCube(new Vector3f(_size, _size, _size), _materialName, _color);
|
||||
// }
|
||||
// public static ResourceMesh createCube(const new Vector3f& _size=new Vector3f(1.0f, 1.0f, 1.0f),
|
||||
// const etk::String& _materialName="basics",
|
||||
// Color _color=etk::color::green) {
|
||||
// EGE_VERBOSE(" create a cube _size=" << _size << " _materialName=" << _materialName << " _color=" << _color);
|
||||
// ememory::SharedPtr<ege::resource::Mesh> out = ege::resource::Mesh::create("---", "DATA:///color3.prog");
|
||||
// if (out != null) {
|
||||
// ememory::SharedPtr<ege::Material> material = ememory::makeShared<ege::Material>();
|
||||
// // set the element material properties :
|
||||
// material.setAmbientFactor(vec4(1,1,1,1));
|
||||
// material.setDiffuseFactor(vec4(0,0,0,1));
|
||||
// material.setSpecularFactor(vec4(0,0,0,1));
|
||||
// material.setShininess(1);
|
||||
// material.setRenderMode(gale::openGL::renderMode::triangle);
|
||||
// out.addMaterial(_materialName, material);
|
||||
//
|
||||
// out.addFaceIndexing(_materialName);
|
||||
//
|
||||
// out.addQuad(_materialName, new Vector3f(-1,-1, 1)*_size, new Vector3f(-1,-1,-1)*_size, new Vector3f( 1,-1,-1)*_size, new Vector3f( 1,-1, 1)*_size, _color);
|
||||
// out.addQuad(_materialName, new Vector3f(-1, 1,-1)*_size, new Vector3f(-1, 1, 1)*_size, new Vector3f( 1, 1, 1)*_size, new Vector3f( 1, 1,-1)*_size, _color);
|
||||
// out.addQuad(_materialName, new Vector3f(-1, 1,-1)*_size, new Vector3f(-1,-1,-1)*_size, new Vector3f(-1,-1, 1)*_size, new Vector3f(-1, 1, 1)*_size, _color);
|
||||
// out.addQuad(_materialName, new Vector3f( 1,-1,-1)*_size, new Vector3f( 1, 1,-1)*_size, new Vector3f( 1, 1, 1)*_size, new Vector3f( 1,-1, 1)*_size, _color);
|
||||
// out.addQuad(_materialName, new Vector3f(-1,-1,-1)*_size, new Vector3f(-1, 1,-1)*_size, new Vector3f( 1, 1,-1)*_size, new Vector3f( 1,-1,-1)*_size, _color);
|
||||
// out.addQuad(_materialName, new Vector3f(-1, 1, 1)*_size, new Vector3f(-1,-1, 1)*_size, new Vector3f( 1,-1, 1)*_size, new Vector3f( 1, 1, 1)*_size, _color);
|
||||
// out.setNormalMode(ege::resource::Mesh::normalMode::face);
|
||||
// out.calculateNormaleFace(_materialName);
|
||||
// // generate the VBO
|
||||
// out.generateVBO();
|
||||
// } else {
|
||||
// EGE_ERROR("can not create the basic mesh interface");
|
||||
// }
|
||||
// return out;
|
||||
// }
|
||||
// public static ResourceMesh createSphere(float _size=1.0f,
|
||||
// const etk::String& _materialName="basics",
|
||||
// Color _color=etk::color::green,
|
||||
// int _lats = 10,
|
||||
// int _longs = 10) {
|
||||
// EGE_VERBOSE(" create a sphere _size=" << _radius << " _materialName=" << _materialName << " _color=" << _color);
|
||||
// ememory::SharedPtr<ege::resource::Mesh> out = ege::resource::Mesh::create("---", "DATA:///color3.prog");
|
||||
// if (out != null) {
|
||||
// ememory::SharedPtr<ege::Material> material = ememory::makeShared<ege::Material>();
|
||||
// // set the element material properties :
|
||||
// material.setAmbientFactor(vec4(1,1,1,1));
|
||||
// material.setDiffuseFactor(vec4(0,0,0,1));
|
||||
// material.setSpecularFactor(vec4(0,0,0,1));
|
||||
// material.setShininess(1);
|
||||
// material.setRenderMode(gale::openGL::renderMode::triangle);
|
||||
// out.addMaterial(_materialName, material);
|
||||
//
|
||||
// out.addFaceIndexing(_materialName);
|
||||
// for(int iii=0; iii<=_lats; ++iii) {
|
||||
// float lat0 = PI * (-0.5f + float(iii - 1) / _lats);
|
||||
// float z0 = _radius*sin(lat0);
|
||||
// float zr0 = _radius*cos(lat0);
|
||||
//
|
||||
// float lat1 = PI * (-0.5f + float(iii) / _lats);
|
||||
// float z1 = _radius*sin(lat1);
|
||||
// float zr1 = _radius*cos(lat1);
|
||||
//
|
||||
// for(int jjj=0; jjj<_longs; ++jjj) {
|
||||
// float lng = 2.0f * PI * float(jjj - 1) / _longs;
|
||||
// float x = cos(lng);
|
||||
// float y = sin(lng);
|
||||
// new Vector3f v1 = new Vector3f(x * zr1, y * zr1, z1);
|
||||
// new Vector3f v4 = new Vector3f(x * zr0, y * zr0, z0);
|
||||
//
|
||||
// lng = 2 * PI * float(jjj) / _longs;
|
||||
// x = cos(lng);
|
||||
// y = sin(lng);
|
||||
// new Vector3f v2 = new Vector3f(x * zr1, y * zr1, z1);
|
||||
// new Vector3f v3 = new Vector3f(x * zr0, y * zr0, z0);
|
||||
//
|
||||
// out.addTriangle(_materialName, v1, v3, v2, _color);
|
||||
// out.addTriangle(_materialName, v1, v4, v3, _color);
|
||||
// }
|
||||
// }
|
||||
// out.setNormalMode(ege::resource::Mesh::normalMode::face);
|
||||
// out.calculateNormaleFace(_materialName);
|
||||
// // generate the VBO
|
||||
// out.generateVBO();
|
||||
// } else {
|
||||
// EGE_ERROR("can not create the basic mesh interface");
|
||||
// }
|
||||
// return out;
|
||||
// }
|
||||
// public static ResourceMesh createCylinder(float _radius = 1.0f,
|
||||
// float _size = 1.0f,
|
||||
// const etk::String& _materialName="basics",
|
||||
// Color _color=etk::color::green,
|
||||
// int _lats = 10,
|
||||
// int _longs = 10) {
|
||||
// EGE_VERBOSE(" create a cylinder _size=" << _size << " _materialName=" << _materialName << " _color=" << _color);
|
||||
// ememory::SharedPtr<ege::resource::Mesh> out = ege::resource::Mesh::create("---", "DATA:///color3.prog");
|
||||
// if (out != null) {
|
||||
// ememory::SharedPtr<ege::Material> material = ememory::makeShared<ege::Material>();
|
||||
// // set the element material properties :
|
||||
// material.setAmbientFactor(vec4(1,1,1,1));
|
||||
// material.setDiffuseFactor(vec4(0,0,0,1));
|
||||
// material.setSpecularFactor(vec4(0,0,0,1));
|
||||
// material.setShininess(1);
|
||||
// material.setRenderMode(gale::openGL::renderMode::triangle);
|
||||
// out.addMaterial(_materialName, material);
|
||||
//
|
||||
// out.addFaceIndexing(_materialName);
|
||||
//
|
||||
// // center to border (TOP)
|
||||
// for(int jjj=0; jjj<_longs; ++jjj) {
|
||||
// float lng = 2.0f * PI * float(jjj - 1) / _longs;
|
||||
//
|
||||
// float z = _size*0.5f;
|
||||
// new Vector3f v1 = new Vector3f(0.0f, 0.0f, z);
|
||||
//
|
||||
// float x = cos(lng)*_radius;
|
||||
// float y = sin(lng)*_radius;
|
||||
// new Vector3f v2 = new Vector3f(x, y, z);
|
||||
//
|
||||
// lng = 2.0f * PI * float(jjj) / _longs;
|
||||
// x = cos(lng)*_radius;
|
||||
// y = sin(lng)*_radius;
|
||||
// new Vector3f v3 = new Vector3f(x, y, z);
|
||||
// out.addTriangle(_materialName, v1, v2, v3, _color);
|
||||
// }
|
||||
// // Cylinder
|
||||
// for(int jjj=0; jjj<_longs; ++jjj) {
|
||||
// float lng = 2.0f * PI * float(jjj - 1) / _longs;
|
||||
//
|
||||
// float z = _size*0.5f;
|
||||
//
|
||||
// float x = cos(lng)*_radius;
|
||||
// float y = sin(lng)*_radius;
|
||||
// new Vector3f v2 = new Vector3f(x, y, z);
|
||||
// new Vector3f v2b = new Vector3f(x, y, -z);
|
||||
//
|
||||
// lng = 2.0f * PI * float(jjj) / _longs;
|
||||
// x = cos(lng)*_radius;
|
||||
// y = sin(lng)*_radius;
|
||||
// new Vector3f v3 = new Vector3f(x, y, z);
|
||||
// new Vector3f v3b = new Vector3f(x, y, -z);
|
||||
//
|
||||
// out.addQuad(_materialName, v3, v2, v2b, v3b, _color);
|
||||
// }
|
||||
// // center to border (BUTTOM)
|
||||
// for(int jjj=0; jjj<_longs; ++jjj) {
|
||||
// float lng = 2.0f * PI * float(jjj - 1) / _longs;
|
||||
//
|
||||
// float z = _size*-0.5f;
|
||||
// new Vector3f v1 = new Vector3f(0.0f, 0.0f, z);
|
||||
//
|
||||
// float x = cos(lng)*_radius;
|
||||
// float y = sin(lng)*_radius;
|
||||
// new Vector3f v2 = new Vector3f(x, y, z);
|
||||
//
|
||||
// lng = 2.0f * PI * float(jjj) / _longs;
|
||||
// x = cos(lng)*_radius;
|
||||
// y = sin(lng)*_radius;
|
||||
// new Vector3f v3 = new Vector3f(x, y, z);
|
||||
// out.addTriangle(_materialName, v1, v3, v2, _color);
|
||||
// }
|
||||
// out.setNormalMode(ege::resource::Mesh::normalMode::face);
|
||||
// out.calculateNormaleFace(_materialName);
|
||||
// // generate the VBO
|
||||
// out.generateVBO();
|
||||
// } else {
|
||||
// EGE_ERROR("can not create the basic mesh interface");
|
||||
// }
|
||||
// return out;
|
||||
// }
|
||||
// public static ResourceMesh createCapsule(float _radius = 1.0f,
|
||||
// float _size = 1.0f,
|
||||
// const etk::String& _materialName="basics",
|
||||
// Color _color=etk::color::green,
|
||||
// int _lats = 10,
|
||||
// int _longs = 10) {
|
||||
// EGE_VERBOSE(" create a capsule _size=" << _size << " _materialName=" << _materialName << " _color=" << _color);
|
||||
// ememory::SharedPtr<ege::resource::Mesh> out = ege::resource::Mesh::create("---", "DATA:///color3.prog");
|
||||
// if (out != null) {
|
||||
// ememory::SharedPtr<ege::Material> material = ememory::makeShared<ege::Material>();
|
||||
// // set the element material properties :
|
||||
// material.setAmbientFactor(vec4(1,1,1,1));
|
||||
// material.setDiffuseFactor(vec4(0,0,0,1));
|
||||
// material.setSpecularFactor(vec4(0,0,0,1));
|
||||
// material.setShininess(1);
|
||||
// material.setRenderMode(gale::openGL::renderMode::triangle);
|
||||
// out.addMaterial(_materialName, material);
|
||||
//
|
||||
// out.addFaceIndexing(_materialName);
|
||||
//
|
||||
// // center to border (TOP)
|
||||
// float offset = _size*0.5f;
|
||||
// for(int iii=_lats/2+1; iii<=_lats; ++iii) {
|
||||
// float lat0 = PI * (-0.5f + float(iii - 1) / _lats);
|
||||
// float z0 = _radius*sin(lat0);
|
||||
// float zr0 = _radius*cos(lat0);
|
||||
//
|
||||
// float lat1 = PI * (-0.5f + float(iii) / _lats);
|
||||
// float z1 = _radius*sin(lat1);
|
||||
// float zr1 = _radius*cos(lat1);
|
||||
//
|
||||
// for(int jjj=0; jjj<_longs; ++jjj) {
|
||||
// float lng = 2.0f * PI * float(jjj - 1) / _longs;
|
||||
// float x = cos(lng);
|
||||
// float y = sin(lng);
|
||||
// new Vector3f v1 = new Vector3f(x * zr1, y * zr1, z1+offset);
|
||||
// new Vector3f v4 = new Vector3f(x * zr0, y * zr0, z0+offset);
|
||||
//
|
||||
// lng = 2 * PI * float(jjj) / _longs;
|
||||
// x = cos(lng);
|
||||
// y = sin(lng);
|
||||
// new Vector3f v2 = new Vector3f(x * zr1, y * zr1, z1+offset);
|
||||
// new Vector3f v3 = new Vector3f(x * zr0, y * zr0, z0+offset);
|
||||
// out.addQuad(_materialName, v2, v1, v4, v3, _color);
|
||||
// }
|
||||
// }
|
||||
// // Cylinder
|
||||
// for(int jjj=0; jjj<_longs; ++jjj) {
|
||||
// float lng = 2.0f * PI * float(jjj - 1) / _longs;
|
||||
//
|
||||
// float z = _size*0.5f;
|
||||
//
|
||||
// float x = cos(lng)*_radius;
|
||||
// float y = sin(lng)*_radius;
|
||||
// new Vector3f v2 = new Vector3f(x, y, z);
|
||||
// new Vector3f v2b = new Vector3f(x, y, -z);
|
||||
//
|
||||
// lng = 2.0f * PI * float(jjj) / _longs;
|
||||
// x = cos(lng)*_radius;
|
||||
// y = sin(lng)*_radius;
|
||||
// new Vector3f v3 = new Vector3f(x, y, z);
|
||||
// new Vector3f v3b = new Vector3f(x, y, -z);
|
||||
//
|
||||
// out.addQuad(_materialName, v3, v2, v2b, v3b, _color);
|
||||
// }
|
||||
// // center to border (BUTTOM)
|
||||
// offset = -_size*0.5f;
|
||||
// for(int iii=0; iii<=_lats/2; ++iii) {
|
||||
// float lat0 = PI * (-0.5f + float(iii - 1) / _lats);
|
||||
// float z0 = _radius*sin(lat0);
|
||||
// float zr0 = _radius*cos(lat0);
|
||||
//
|
||||
// float lat1 = PI * (-0.5f + float(iii) / _lats);
|
||||
// float z1 = _radius*sin(lat1);
|
||||
// float zr1 = _radius*cos(lat1);
|
||||
//
|
||||
// for(int jjj=0; jjj<_longs; ++jjj) {
|
||||
// float lng = 2.0f * PI * float(jjj - 1) / _longs;
|
||||
// float x = cos(lng);
|
||||
// float y = sin(lng);
|
||||
// new Vector3f v1 = new Vector3f(x * zr1, y * zr1, z1+offset);
|
||||
// new Vector3f v4 = new Vector3f(x * zr0, y * zr0, z0+offset);
|
||||
//
|
||||
// lng = 2 * PI * float(jjj) / _longs;
|
||||
// x = cos(lng);
|
||||
// y = sin(lng);
|
||||
// new Vector3f v2 = new Vector3f(x * zr1, y * zr1, z1+offset);
|
||||
// new Vector3f v3 = new Vector3f(x * zr0, y * zr0, z0+offset);
|
||||
// out.addQuad(_materialName, v2, v1, v4, v3, _color);
|
||||
// }
|
||||
// }
|
||||
// out.setNormalMode(ege::resource::Mesh::normalMode::face);
|
||||
// out.calculateNormaleFace(_materialName);
|
||||
// // generate the VBO
|
||||
// out.generateVBO();
|
||||
// } else {
|
||||
// EGE_ERROR("can not create the basic mesh interface");
|
||||
// }
|
||||
// return out;
|
||||
// }
|
||||
// public static ResourceMesh createCone(float _radius = 1.0f,
|
||||
// float _size = 1.0f,
|
||||
// const etk::String& _materialName="basics",
|
||||
// Color _color=etk::color::green,
|
||||
// int _lats = 10,
|
||||
// int _longs = 10) {
|
||||
// EGE_VERBOSE(" create a cylinder _size=" << _size << " _materialName=" << _materialName << " _color=" << _color);
|
||||
// ememory::SharedPtr<ege::resource::Mesh> out = ege::resource::Mesh::create("---", "DATA:///color3.prog");
|
||||
// if (out != null) {
|
||||
// ememory::SharedPtr<ege::Material> material = ememory::makeShared<ege::Material>();
|
||||
// // set the element material properties :
|
||||
// material.setAmbientFactor(vec4(1,1,1,1));
|
||||
// material.setDiffuseFactor(vec4(0,0,0,1));
|
||||
// material.setSpecularFactor(vec4(0,0,0,1));
|
||||
// material.setShininess(1);
|
||||
// material.setRenderMode(gale::openGL::renderMode::triangle);
|
||||
// out.addMaterial(_materialName, material);
|
||||
//
|
||||
// out.addFaceIndexing(_materialName);
|
||||
//
|
||||
// // center to border (TOP)
|
||||
// for(int jjj=0; jjj<_longs; ++jjj) {
|
||||
// float lng = 2.0f * PI * float(jjj - 1) / _longs;
|
||||
// new Vector3f v1 = new Vector3f(0.0f, 0.0f, _size/2);
|
||||
//
|
||||
// float x = cos(lng)*_radius;
|
||||
// float y = sin(lng)*_radius;
|
||||
// new Vector3f v2 = new Vector3f(x, y, -_size/2);
|
||||
//
|
||||
// lng = 2.0f * PI * float(jjj) / _longs;
|
||||
// x = cos(lng)*_radius;
|
||||
// y = sin(lng)*_radius;
|
||||
// new Vector3f v3 = new Vector3f(x, y, -_size/2);
|
||||
// out.addTriangle(_materialName, v1, v2, v3, _color);
|
||||
// }
|
||||
// // center to border (BUTTOM)
|
||||
// for(int jjj=0; jjj<_longs; ++jjj) {
|
||||
// float lng = 2.0f * PI * float(jjj - 1) / _longs;
|
||||
//
|
||||
// new Vector3f v1 = new Vector3f(0.0f, 0.0f, -_size/2);
|
||||
//
|
||||
// float x = cos(lng)*_radius;
|
||||
// float y = sin(lng)*_radius;
|
||||
// new Vector3f v2 = new Vector3f(x, y, -_size/2);
|
||||
//
|
||||
// lng = 2.0f * PI * float(jjj) / _longs;
|
||||
// x = cos(lng)*_radius;
|
||||
// y = sin(lng)*_radius;
|
||||
// new Vector3f v3 = new Vector3f(x, y, -_size/2);
|
||||
// out.addTriangle(_materialName, v1, v3, v2, _color);
|
||||
// }
|
||||
// out.setNormalMode(ege::resource::Mesh::normalMode::face);
|
||||
// out.calculateNormaleFace(_materialName);
|
||||
// // generate the VBO
|
||||
// out.generateVBO();
|
||||
// } else {
|
||||
// EGE_ERROR("can not create the basic mesh interface");
|
||||
// }
|
||||
// return out;
|
||||
// }
|
||||
}
|
@ -1,11 +1,11 @@
|
||||
#version 400 core
|
||||
|
||||
in vec2 pass_textureCoordinates;
|
||||
in vec3 surfaceNormal;
|
||||
in vec3 toLightVector[4];
|
||||
in vec3 toCameraVector;
|
||||
in vec2 io_textureCoords;
|
||||
in vec3 io_textureCoords;
|
||||
in vec3 io_toLightVector[4];
|
||||
in vec3 io_toCameraVector;
|
||||
// FOW: Fog Of War result calculation
|
||||
in float visibility;
|
||||
in float io_fowVisibility;
|
||||
|
||||
out vec4 out_Color;
|
||||
|
||||
@ -19,14 +19,14 @@ uniform vec3 skyColor;
|
||||
|
||||
void main(void) {
|
||||
|
||||
vec3 unitNormal = normalize(surfaceNormal);
|
||||
vec3 unitVectorToCamera = normalize(toCameraVector);
|
||||
vec3 unitNormal = normalize(io_textureCoords);
|
||||
vec3 unitVectorToCamera = normalize(io_toCameraVector);
|
||||
vec3 totalDiffuse = vec3(0.0);
|
||||
vec3 totalSpecular = vec3(0.0);
|
||||
for(int i=0;i<4;i++) {
|
||||
float distance = length(toLightVector[i]);
|
||||
float distance = length(io_toLightVector[i]);
|
||||
float attenuationFactor = lightAttenuation[i].x + (lightAttenuation[i].y * distance) + (lightAttenuation[i].z * distance * distance);
|
||||
vec3 unitLightVector = normalize(toLightVector[i]);
|
||||
vec3 unitLightVector = normalize(io_toLightVector[i]);
|
||||
float nDot1 = dot(unitNormal, unitLightVector);
|
||||
float brightness = max(nDot1, 0.0);
|
||||
vec3 lightDirection = -unitLightVector;
|
||||
@ -40,16 +40,16 @@ void main(void) {
|
||||
totalSpecular = totalSpecular + finalSpecular;
|
||||
}
|
||||
// the 0.2 represent the ambiant lightning ==> maybe set an uniform for this
|
||||
totalDiffuse = max (totalDiffuse, 0.2);
|
||||
totalDiffuse = max(totalDiffuse, 0.2);
|
||||
|
||||
// disable transparency elements in the texture ...
|
||||
// Can be set at the start of the shader ...
|
||||
vec4 textureColour = texture(textureSampler,pass_textureCoordinates);
|
||||
vec4 textureColour = texture(textureSampler,io_textureCoords);
|
||||
if (textureColour.a < 0.5) {
|
||||
discard;
|
||||
}
|
||||
|
||||
out_Color = vec4(totalDiffuse,1.0) * textureColour + vec4(totalSpecular, 1.0);
|
||||
out_Color = mix(vec4(skyColor,1.0), out_Color, visibility);
|
||||
out_Color = mix(vec4(skyColor,1.0), out_Color, io_fowVisibility);
|
||||
}
|
||||
|
||||
|
@ -4,12 +4,12 @@ in vec3 position;
|
||||
in vec2 textureCoords;
|
||||
in vec3 normal;
|
||||
|
||||
out vec2 pass_textureCoordinates;
|
||||
out vec3 surfaceNormal;
|
||||
out vec3 toLightVector[4];
|
||||
out vec3 toCameraVector;
|
||||
out vec2 io_textureCoords;
|
||||
out vec3 io_textureCoords;
|
||||
out vec3 io_toLightVector[4];
|
||||
out vec3 io_toCameraVector;
|
||||
// FOW: Fog Of War result calculation
|
||||
out float visibility;
|
||||
out float io_fowVisibility;
|
||||
|
||||
uniform mat4 transformationMatrix;
|
||||
uniform mat4 projectionMatrix;
|
||||
@ -24,25 +24,24 @@ uniform vec2 offset;
|
||||
const float density = 0.007;
|
||||
const float gradient = 1.5;
|
||||
|
||||
|
||||
void main(void) {
|
||||
vec4 worldPosition = transformationMatrix * vec4(position, 1.0);
|
||||
vec4 positionRelativeToCam = viewMatrix * worldPosition;
|
||||
gl_Position = projectionMatrix * positionRelativeToCam;
|
||||
pass_textureCoordinates = (textureCoords/numberOfRows) + offset;
|
||||
io_textureCoords = (textureCoords/numberOfRows) + offset;
|
||||
|
||||
vec3 actualNormal = normal;
|
||||
if (useFakeLighting > 0.5) {
|
||||
actualNormal = vec3(0.0, 1.0, 0.0);
|
||||
}
|
||||
surfaceNormal = (transformationMatrix * vec4(actualNormal, 0.0)).xyz;
|
||||
io_textureCoords = (transformationMatrix * vec4(actualNormal, 0.0)).xyz;
|
||||
for(int i=0;i<4;i++) {
|
||||
toLightVector[i] = lightPosition[i] - worldPosition.xyz;
|
||||
io_toLightVector[i] = lightPosition[i] - worldPosition.xyz;
|
||||
}
|
||||
toCameraVector = (inverse(viewMatrix) * vec4(0.0,0.0,0.0,1.0)).xyz - worldPosition.xyz;
|
||||
io_toCameraVector = (inverse(viewMatrix) * vec4(0.0,0.0,0.0,1.0)).xyz - worldPosition.xyz;
|
||||
|
||||
float distance = length(positionRelativeToCam.xyz);
|
||||
visibility = exp(-pow((distance*density),gradient));
|
||||
visibility = clamp(visibility, 0.0, 1.0);
|
||||
io_fowVisibility = exp(-pow((distance*density),gradient));
|
||||
io_fowVisibility = clamp(io_fowVisibility, 0.0, 1.0);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user