diff --git a/res/dirt.png b/res/dirt.png index 4e139ae..77251a8 100644 Binary files a/res/dirt.png and b/res/dirt.png differ diff --git a/src/entities/Camera.java b/src/entities/Camera.java index d171751..e50a1d2 100644 --- a/src/entities/Camera.java +++ b/src/entities/Camera.java @@ -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)); } diff --git a/src/objConverter/OBJFileLoader.java b/src/objConverter/OBJFileLoader.java index b9271f7..8462df0 100644 --- a/src/objConverter/OBJFileLoader.java +++ b/src/objConverter/OBJFileLoader.java @@ -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) { diff --git a/src/org/atriaSoft/etk/math/Matrix4f.java b/src/org/atriaSoft/etk/math/Matrix4f.java index fc1d02d..7db2c8b 100644 --- a/src/org/atriaSoft/etk/math/Matrix4f.java +++ b/src/org/atriaSoft/etk/math/Matrix4f.java @@ -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 */ diff --git a/src/org/atriaSoft/etk/math/Transform3D.java b/src/org/atriaSoft/etk/math/Transform3D.java index baf3462..bf540c4 100644 --- a/src/org/atriaSoft/etk/math/Transform3D.java +++ b/src/org/atriaSoft/etk/math/Transform3D.java @@ -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); + } } diff --git a/src/org/atriaSoft/gale/Application.java b/src/org/atriaSoft/gale/Application.java index 976fac6..4f4112c 100644 --- a/src/org/atriaSoft/gale/Application.java +++ b/src/org/atriaSoft/gale/Application.java @@ -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) { } /** diff --git a/src/org/atriaSoft/gale/context/Context.java b/src/org/atriaSoft/gale/context/Context.java index bc4eb07..962985f 100644 --- a/src/org/atriaSoft/gale/context/Context.java +++ b/src/org/atriaSoft/gale/context/Context.java @@ -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(); diff --git a/src/org/atriaSoft/gale/context/LWJGL/ContextLWJGL.java b/src/org/atriaSoft/gale/context/LWJGL/ContextLWJGL.java index ec9ac1a..358904e 100644 --- a/src/org/atriaSoft/gale/context/LWJGL/ContextLWJGL.java +++ b/src/org/atriaSoft/gale/context/LWJGL/ContextLWJGL.java @@ -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; iii0) { 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() { diff --git a/src/org/atriaSoft/gale/event/EventEntry.java b/src/org/atriaSoft/gale/event/EventEntry.java new file mode 100644 index 0000000..7fceb6d --- /dev/null +++ b/src/org/atriaSoft/gale/event/EventEntry.java @@ -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 + "]"; + } +} diff --git a/src/org/atriaSoft/gale/event/EventInput.java b/src/org/atriaSoft/gale/event/EventInput.java new file mode 100644 index 0000000..1e089b5 --- /dev/null +++ b/src/org/atriaSoft/gale/event/EventInput.java @@ -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 + "]"; + } + +} diff --git a/src/org/atriaSoft/gale/event/EventTime.java b/src/org/atriaSoft/gale/event/EventTime.java new file mode 100644 index 0000000..a1e94eb --- /dev/null +++ b/src/org/atriaSoft/gale/event/EventTime.java @@ -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]"; + } + +} diff --git a/src/org/atriaSoft/gale/key/Keyboard.java b/src/org/atriaSoft/gale/key/KeyKeyboard.java similarity index 98% rename from src/org/atriaSoft/gale/key/Keyboard.java rename to src/org/atriaSoft/gale/key/KeyKeyboard.java index d41a4d8..df21655 100644 --- a/src/org/atriaSoft/gale/key/Keyboard.java +++ b/src/org/atriaSoft/gale/key/KeyKeyboard.java @@ -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 <-- diff --git a/src/org/atriaSoft/gale/key/Special.java b/src/org/atriaSoft/gale/key/KeySpecial.java similarity index 98% rename from src/org/atriaSoft/gale/key/Special.java rename to src/org/atriaSoft/gale/key/KeySpecial.java index ab3ea88..e15a2ab 100644 --- a/src/org/atriaSoft/gale/key/Special.java +++ b/src/org/atriaSoft/gale/key/KeySpecial.java @@ -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(); diff --git a/src/org/atriaSoft/gale/key/Status.java b/src/org/atriaSoft/gale/key/KeyStatus.java similarity index 96% rename from src/org/atriaSoft/gale/key/Status.java rename to src/org/atriaSoft/gale/key/KeyStatus.java index b810709..a08b9ab 100644 --- a/src/org/atriaSoft/gale/key/Status.java +++ b/src/org/atriaSoft/gale/key/KeyStatus.java @@ -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 diff --git a/src/org/atriaSoft/gale/key/Type.java b/src/org/atriaSoft/gale/key/KeyType.java similarity index 87% rename from src/org/atriaSoft/gale/key/Type.java rename to src/org/atriaSoft/gale/key/KeyType.java index a5630b8..5a403f8 100644 --- a/src/org/atriaSoft/gale/key/Type.java +++ b/src/org/atriaSoft/gale/key/KeyType.java @@ -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 diff --git a/src/org/atriaSoft/gale/resource/Resource.java b/src/org/atriaSoft/gale/resource/Resource.java index df4124c..e783431 100644 --- a/src/org/atriaSoft/gale/resource/Resource.java +++ b/src/org/atriaSoft/gale/resource/Resource.java @@ -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 ... diff --git a/src/org/atriaSoft/gale/resource/ResourceProgram.java b/src/org/atriaSoft/gale/resource/ResourceProgram.java index 74ab03f..bb7fd1a 100644 --- a/src/org/atriaSoft/gale/resource/ResourceProgram.java +++ b/src/org/atriaSoft/gale/resource/ResourceProgram.java @@ -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; } + } diff --git a/src/org/atriaSoft/gale/resource/ResourceTexture.java b/src/org/atriaSoft/gale/resource/ResourceTexture.java index a16c70f..551c586 100644 --- a/src/org/atriaSoft/gale/resource/ResourceTexture.java +++ b/src/org/atriaSoft/gale/resource/ResourceTexture.java @@ -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; } diff --git a/src/org/atriaSoft/gale/resource/ResourceVirtualArrayObject.java b/src/org/atriaSoft/gale/resource/ResourceVirtualArrayObject.java index a5617f3..002fca6 100644 --- a/src/org/atriaSoft/gale/resource/ResourceVirtualArrayObject.java +++ b/src/org/atriaSoft/gale/resource/ResourceVirtualArrayObject.java @@ -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) { diff --git a/src/org/atriaSoft/gale/test/sample1/MainApplication.java b/src/org/atriaSoft/gale/test/sample1/Sample1Application.java similarity index 88% rename from src/org/atriaSoft/gale/test/sample1/MainApplication.java rename to src/org/atriaSoft/gale/test/sample1/Sample1Application.java index 8a0c6cc..fc6218a 100644 --- a/src/org/atriaSoft/gale/test/sample1/MainApplication.java +++ b/src/org/atriaSoft/gale/test/sample1/Sample1Application.java @@ -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 + "'"); diff --git a/src/org/atriaSoft/gale/test/sample1/basic.frag b/src/org/atriaSoft/gale/test/sample1/basic.frag index 58f5960..d290abb 100644 --- a/src/org/atriaSoft/gale/test/sample1/basic.frag +++ b/src/org/atriaSoft/gale/test/sample1/basic.frag @@ -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; } diff --git a/src/org/atriaSoft/gale/test/sample1/basic.vert b/src/org/atriaSoft/gale/test/sample1/basic.vert index 31c4de6..00c9732 100644 --- a/src/org/atriaSoft/gale/test/sample1/basic.vert +++ b/src/org/atriaSoft/gale/test/sample1/basic.vert @@ -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; } diff --git a/src/org/atriaSoft/gale/test/sample1/sample_1.java b/src/org/atriaSoft/gale/test/sample1/sample_1.java index a12afec..35bc930 100644 --- a/src/org/atriaSoft/gale/test/sample1/sample_1.java +++ b/src/org/atriaSoft/gale/test/sample1/sample_1.java @@ -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); } } diff --git a/src/org/atriaSoft/gale/test/sample2/MainApplication.java b/src/org/atriaSoft/gale/test/sample2/Sample2Application.java similarity index 93% rename from src/org/atriaSoft/gale/test/sample2/MainApplication.java rename to src/org/atriaSoft/gale/test/sample2/Sample2Application.java index 3698ce3..a209b00 100644 --- a/src/org/atriaSoft/gale/test/sample2/MainApplication.java +++ b/src/org/atriaSoft/gale/test/sample2/Sample2Application.java @@ -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 + "'"); diff --git a/src/org/atriaSoft/gale/test/sample2/basic.frag b/src/org/atriaSoft/gale/test/sample2/basic.frag index a347c03..13d2aa8 100644 --- a/src/org/atriaSoft/gale/test/sample2/basic.frag +++ b/src/org/atriaSoft/gale/test/sample2/basic.frag @@ -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); } diff --git a/src/org/atriaSoft/gale/test/sample2/basic.vert b/src/org/atriaSoft/gale/test/sample2/basic.vert index 439636f..c0dcaa7 100644 --- a/src/org/atriaSoft/gale/test/sample2/basic.vert +++ b/src/org/atriaSoft/gale/test/sample2/basic.vert @@ -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; } diff --git a/src/org/atriaSoft/gale/test/sample2/sample_2.java b/src/org/atriaSoft/gale/test/sample2/sample_2.java index c84632b..87fe7ca 100644 --- a/src/org/atriaSoft/gale/test/sample2/sample_2.java +++ b/src/org/atriaSoft/gale/test/sample2/sample_2.java @@ -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); } } diff --git a/src/org/atriaSoft/gameEngine/ControlCameraSimple.java b/src/org/atriaSoft/gameEngine/ControlCameraSimple.java new file mode 100644 index 0000000..3808143 --- /dev/null +++ b/src/org/atriaSoft/gameEngine/ControlCameraSimple.java @@ -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; + } + } + } + } + +} diff --git a/src/org/atriaSoft/gameEngine/ControlInterface.java b/src/org/atriaSoft/gameEngine/ControlInterface.java new file mode 100644 index 0000000..5dc5da9 --- /dev/null +++ b/src/org/atriaSoft/gameEngine/ControlInterface.java @@ -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); +} diff --git a/src/org/atriaSoft/gameEngine/Entity.java b/src/org/atriaSoft/gameEngine/Entity.java index 4b4c53b..ad9d4c0 100644 --- a/src/org/atriaSoft/gameEngine/Entity.java +++ b/src/org/atriaSoft/gameEngine/Entity.java @@ -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 = new ArrayList(); /** * @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(); diff --git a/src/org/atriaSoft/gameEngine/Environement.java b/src/org/atriaSoft/gameEngine/Environement.java index 9282d1d..474b78f 100644 --- a/src/org/atriaSoft/gameEngine/Environement.java +++ b/src/org/atriaSoft/gameEngine/Environement.java @@ -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 signalPlayTimeChange = new Signal(); @@ -19,11 +29,14 @@ public class Environement { protected List engine = new ArrayList(); // !< EGE sub engine interface (like physique, rendering, // audio, ...). private List listEntity = new ArrayList(); // !< List of all entity added in the Game - + List controls = new ArrayList(); + long lastCallTime = 0; + // ! list of all camera in the world protected Map listCamera = new HashMap(); protected long gameTime = 0; // !< time of the game running - protected List listMeshToDrawFirst = new ArrayList(); + private long startTime; + //protected List listMeshToDrawFirst = new ArrayList(); 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 getStaticMeshToDraw() { - return listMeshToDrawFirst; - } +// public void addStaticMeshToDraw(Mesh mesh) { +// listMeshToDrawFirst.add(mesh); +// } +// +// public List 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); + } + } } /* diff --git a/src/org/atriaSoft/gameEngine/Light.java b/src/org/atriaSoft/gameEngine/Light.java new file mode 100644 index 0000000..4742cc3 --- /dev/null +++ b/src/org/atriaSoft/gameEngine/Light.java @@ -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; + } +} diff --git a/src/org/atriaSoft/gameEngine/Material.java b/src/org/atriaSoft/gameEngine/Material.java new file mode 100644 index 0000000..194ab5a --- /dev/null +++ b/src/org/atriaSoft/gameEngine/Material.java @@ -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; + } + +} diff --git a/src/org/atriaSoft/gameEngine/camera/Camera.java b/src/org/atriaSoft/gameEngine/camera/Camera.java index a3bd260..4840322 100644 --- a/src/org/atriaSoft/gameEngine/camera/Camera.java +++ b/src/org/atriaSoft/gameEngine/camera/Camera.java @@ -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; + } + } diff --git a/src/org/atriaSoft/gameEngine/components/ComponentAI.java b/src/org/atriaSoft/gameEngine/components/ComponentAI.java index 5c9b2bf..c20d0a4 100644 --- a/src/org/atriaSoft/gameEngine/components/ComponentAI.java +++ b/src/org/atriaSoft/gameEngine/components/ComponentAI.java @@ -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); } diff --git a/src/org/atriaSoft/gameEngine/components/ComponentLight.java b/src/org/atriaSoft/gameEngine/components/ComponentLight.java new file mode 100644 index 0000000..71bde8b --- /dev/null +++ b/src/org/atriaSoft/gameEngine/components/ComponentLight.java @@ -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()); + } + +} diff --git a/src/org/atriaSoft/gameEngine/components/ComponentLightSun.java b/src/org/atriaSoft/gameEngine/components/ComponentLightSun.java new file mode 100644 index 0000000..30af9ed --- /dev/null +++ b/src/org/atriaSoft/gameEngine/components/ComponentLightSun.java @@ -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"; +// } + +} diff --git a/src/org/atriaSoft/gameEngine/components/ComponentMaterial.java b/src/org/atriaSoft/gameEngine/components/ComponentMaterial.java new file mode 100644 index 0000000..e07ab37 --- /dev/null +++ b/src/org/atriaSoft/gameEngine/components/ComponentMaterial.java @@ -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; + } + +} diff --git a/src/org/atriaSoft/gameEngine/components/ComponentParticle.java b/src/org/atriaSoft/gameEngine/components/ComponentParticle.java index 82ccab6..9beb2d1 100644 --- a/src/org/atriaSoft/gameEngine/components/ComponentParticle.java +++ b/src/org/atriaSoft/gameEngine/components/ComponentParticle.java @@ -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; } } diff --git a/src/org/atriaSoft/gameEngine/components/ComponentRender.java b/src/org/atriaSoft/gameEngine/components/ComponentRender.java index 0be9bc3..fb17489 100644 --- a/src/org/atriaSoft/gameEngine/components/ComponentRender.java +++ b/src/org/atriaSoft/gameEngine/components/ComponentRender.java @@ -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(); } diff --git a/src/org/atriaSoft/gameEngine/components/ComponentRenderColoredStaticMesh.java b/src/org/atriaSoft/gameEngine/components/ComponentRenderColoredStaticMesh.java new file mode 100644 index 0000000..c6c974d --- /dev/null +++ b/src/org/atriaSoft/gameEngine/components/ComponentRenderColoredStaticMesh.java @@ -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(); + } +} diff --git a/src/org/atriaSoft/gameEngine/components/ComponentRenderTexturedMaterialsStaticMesh.java b/src/org/atriaSoft/gameEngine/components/ComponentRenderTexturedMaterialsStaticMesh.java new file mode 100644 index 0000000..f4d4b8b --- /dev/null +++ b/src/org/atriaSoft/gameEngine/components/ComponentRenderTexturedMaterialsStaticMesh.java @@ -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 need update before drawing... + OpenGL.updateAllFlags(); + // Request the draw all the elements: + this.mesh.render(); + this.texture.unBindForRendering(); + this.mesh.unBindForRendering(); + this.program.unUse(); + } +} + diff --git a/src/org/atriaSoft/gameEngine/components/ComponentRenderTexturedStaticMesh.java b/src/org/atriaSoft/gameEngine/components/ComponentRenderTexturedStaticMesh.java new file mode 100644 index 0000000..f1183f2 --- /dev/null +++ b/src/org/atriaSoft/gameEngine/components/ComponentRenderTexturedStaticMesh.java @@ -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(); + } +} + diff --git a/src/org/atriaSoft/gameEngine/components/ComponentStaticMesh.java b/src/org/atriaSoft/gameEngine/components/ComponentStaticMesh.java new file mode 100644 index 0000000..4103b55 --- /dev/null +++ b/src/org/atriaSoft/gameEngine/components/ComponentStaticMesh.java @@ -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(); + } +} diff --git a/src/org/atriaSoft/gameEngine/components/ComponentTexture.java b/src/org/atriaSoft/gameEngine/components/ComponentTexture.java new file mode 100644 index 0000000..22fb5ec --- /dev/null +++ b/src/org/atriaSoft/gameEngine/components/ComponentTexture.java @@ -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(); + } + +} diff --git a/src/org/atriaSoft/gameEngine/components/ComponentTexturePack.java b/src/org/atriaSoft/gameEngine/components/ComponentTexturePack.java new file mode 100644 index 0000000..06246b0 --- /dev/null +++ b/src/org/atriaSoft/gameEngine/components/ComponentTexturePack.java @@ -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"; + } + +} diff --git a/src/org/atriaSoft/gameEngine/components/CoponentPhysics.java b/src/org/atriaSoft/gameEngine/components/CoponentPhysics.java index 356b534..91b6bd9 100644 --- a/src/org/atriaSoft/gameEngine/components/CoponentPhysics.java +++ b/src/org/atriaSoft/gameEngine/components/CoponentPhysics.java @@ -7,6 +7,6 @@ public class CoponentPhysics extends Component { @Override public String getType() { // TODO Auto-generated method stub - return null; + return "physics"; } } diff --git a/src/org/atriaSoft/gameEngine/data/wireColor.frag b/src/org/atriaSoft/gameEngine/data/wireColor.frag new file mode 100644 index 0000000..2a8ac6b --- /dev/null +++ b/src/org/atriaSoft/gameEngine/data/wireColor.frag @@ -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; +} diff --git a/src/org/atriaSoft/gameEngine/data/wireColor.vert b/src/org/atriaSoft/gameEngine/data/wireColor.vert new file mode 100644 index 0000000..e674f99 --- /dev/null +++ b/src/org/atriaSoft/gameEngine/data/wireColor.vert @@ -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; +} diff --git a/src/org/atriaSoft/gameEngine/engines/EngineAI.java b/src/org/atriaSoft/gameEngine/engines/EngineAI.java index b94b070..fa60cb4 100644 --- a/src/org/atriaSoft/gameEngine/engines/EngineAI.java +++ b/src/org/atriaSoft/gameEngine/engines/EngineAI.java @@ -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 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; } } diff --git a/src/org/atriaSoft/gameEngine/engines/EngineLight.java b/src/org/atriaSoft/gameEngine/engines/EngineLight.java new file mode 100644 index 0000000..6775408 --- /dev/null +++ b/src/org/atriaSoft/gameEngine/engines/EngineLight.java @@ -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 componentLights = new Vector(); + private Vector componentSuns = new Vector(); + 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; + } + +} diff --git a/src/org/atriaSoft/gameEngine/engines/EngineParticle.java b/src/org/atriaSoft/gameEngine/engines/EngineParticle.java index 33ffe90..364ce00 100644 --- a/src/org/atriaSoft/gameEngine/engines/EngineParticle.java +++ b/src/org/atriaSoft/gameEngine/engines/EngineParticle.java @@ -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; } diff --git a/src/org/atriaSoft/gameEngine/engines/EnginePhysics.java b/src/org/atriaSoft/gameEngine/engines/EnginePhysics.java index ac381d0..266f572 100644 --- a/src/org/atriaSoft/gameEngine/engines/EnginePhysics.java +++ b/src/org/atriaSoft/gameEngine/engines/EnginePhysics.java @@ -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; } } diff --git a/src/org/atriaSoft/gameEngine/engines/EngineRender.java b/src/org/atriaSoft/gameEngine/engines/EngineRender.java index 5e54d83..14e7aaa 100644 --- a/src/org/atriaSoft/gameEngine/engines/EngineRender.java +++ b/src/org/atriaSoft/gameEngine/engines/EngineRender.java @@ -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 components = new Vector(); + private Vector displayElementOrdered = new Vector(); + //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> 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& 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; jjjresult.dist) { +// resultList.insert(resultList.begin()+jjj, result); +// break; +// } +// } +// // add element at the end : +// if (jjj >= resultList.size()) { +// resultList.pushBack(result); +// } +// } +// } diff --git a/src/org/atriaSoft/gameEngine/resource/Mesh.java b/src/org/atriaSoft/gameEngine/resource/Mesh.java deleted file mode 100644 index 84f2c8d..0000000 --- a/src/org/atriaSoft/gameEngine/resource/Mesh.java +++ /dev/null @@ -1,5 +0,0 @@ -package org.atriaSoft.gameEngine.resource; - -public class Mesh { - -} diff --git a/src/org/atriaSoft/gameEngine/resource/ResourceMesh.java b/src/org/atriaSoft/gameEngine/resource/ResourceMesh.java new file mode 100644 index 0000000..0b45d07 --- /dev/null +++ b/src/org/atriaSoft/gameEngine/resource/ResourceMesh.java @@ -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 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 listVertex; //!< List of all vertex in the element + etk::Vector listUV; //!< List of all UV point in the mesh (for the specify texture) + etk::Vector listColor; //!< List of all Color point in the mesh + etk::Vector listFacesNormal; //!< List of all Face normal, when calculated + etk::Vector listVertexNormal; //!< List of all Face normal, when calculated + etk::Map listFaces; //!< List of all Face for the mesh + etk::Map> materials; + etk::Vector> 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 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; kkkdraw(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 tmpIndexResult; + etk::Vector& tmppFaces = listFaces.getValue(kkk).faces; + //etk::Vector& tmppIndex = listFaces.getValue(kkk).index; + switch(normalMode) { + case ege::resource::Mesh::normalMode::face: + for(size_t iii=0; iii= 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= -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; iiigetRenderModeOpenGl(), 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 _draw) { + Color tmpColor(0.0, 1.0, 0.0, 1.0); + etk::Vector 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; kkkgetRenderMode()) { + 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= 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; kkkgetRenderMode()) { + 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; iiisizeOnBufferVec3(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 ; indiceflush(); + } + 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& 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 ; jjjpushOnBuffer(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 _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>& 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 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& _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& _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& _list, const etk::Vector& _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 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); + } +} diff --git a/src/org/atriaSoft/gameEngine/sample/lowPoly/basic.frag b/src/org/atriaSoft/gameEngine/sample/lowPoly/basic.frag new file mode 100644 index 0000000..13d2aa8 --- /dev/null +++ b/src/org/atriaSoft/gameEngine/sample/lowPoly/basic.frag @@ -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); +} diff --git a/src/org/atriaSoft/gameEngine/sample/lowPoly/basic.vert b/src/org/atriaSoft/gameEngine/sample/lowPoly/basic.vert new file mode 100644 index 0000000..c0dcaa7 --- /dev/null +++ b/src/org/atriaSoft/gameEngine/sample/lowPoly/basic.vert @@ -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; +} diff --git a/src/org/atriaSoft/gameEngine/sample/lowPoly/basicMaterial.frag b/src/org/atriaSoft/gameEngine/sample/lowPoly/basicMaterial.frag new file mode 100644 index 0000000..2ea36f9 --- /dev/null +++ b/src/org/atriaSoft/gameEngine/sample/lowPoly/basicMaterial.frag @@ -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 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); +} + + + + diff --git a/src/org/atriaSoft/gameEngine/sample/lowPoly/basicMaterial.vert b/src/org/atriaSoft/gameEngine/sample/lowPoly/basicMaterial.vert new file mode 100644 index 0000000..c75190f --- /dev/null +++ b/src/org/atriaSoft/gameEngine/sample/lowPoly/basicMaterial.vert @@ -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 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); + } +} diff --git a/src/org/atriaSoft/gameEngine/sample/s1_texturedCube/Sample1TexturedCube.java b/src/org/atriaSoft/gameEngine/sample/s1_texturedCube/Sample1TexturedCube.java new file mode 100644 index 0000000..7c3985f --- /dev/null +++ b/src/org/atriaSoft/gameEngine/sample/s1_texturedCube/Sample1TexturedCube.java @@ -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); + } +} diff --git a/src/org/atriaSoft/gameEngine/sample/s1_texturedCube/basic.frag b/src/org/atriaSoft/gameEngine/sample/s1_texturedCube/basic.frag new file mode 100644 index 0000000..13d2aa8 --- /dev/null +++ b/src/org/atriaSoft/gameEngine/sample/s1_texturedCube/basic.frag @@ -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); +} diff --git a/src/org/atriaSoft/gameEngine/sample/s1_texturedCube/basic.vert b/src/org/atriaSoft/gameEngine/sample/s1_texturedCube/basic.vert new file mode 100644 index 0000000..c0dcaa7 --- /dev/null +++ b/src/org/atriaSoft/gameEngine/sample/s1_texturedCube/basic.vert @@ -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; +} diff --git a/src/org/atriaSoft/gameEngine/sample/todo_sample.md b/src/org/atriaSoft/gameEngine/sample/todo_sample.md new file mode 100644 index 0000000..728fd92 --- /dev/null +++ b/src/org/atriaSoft/gameEngine/sample/todo_sample.md @@ -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) + diff --git a/src/org/atriaSoft/gameEngine/tools/MeshGenerator.java b/src/org/atriaSoft/gameEngine/tools/MeshGenerator.java new file mode 100644 index 0000000..6b621b5 --- /dev/null +++ b/src/org/atriaSoft/gameEngine/tools/MeshGenerator.java @@ -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 vertices = new ArrayList(); + public List colors = new ArrayList(); + public List indices = new ArrayList(); + + + 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 pos, Color color) { + for (int iii=1; iii list = new ArrayList(); + 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 out = ege::resource::Mesh::create("---", "DATA:///color3.prog"); +// if (out != null) { +// ememory::SharedPtr material = ememory::makeShared(); +// // 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 out = ege::resource::Mesh::create("---", "DATA:///color3.prog"); +// if (out != null) { +// ememory::SharedPtr material = ememory::makeShared(); +// // 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 out = ege::resource::Mesh::create("---", "DATA:///color3.prog"); +// if (out != null) { +// ememory::SharedPtr material = ememory::makeShared(); +// // 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 out = ege::resource::Mesh::create("---", "DATA:///color3.prog"); +// if (out != null) { +// ememory::SharedPtr material = ememory::makeShared(); +// // 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 out = ege::resource::Mesh::create("---", "DATA:///color3.prog"); +// if (out != null) { +// ememory::SharedPtr material = ememory::makeShared(); +// // 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; +// } +} diff --git a/src/shaders/static.frag b/src/shaders/static.frag index bdac457..0bde5aa 100644 --- a/src/shaders/static.frag +++ b/src/shaders/static.frag @@ -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); } diff --git a/src/shaders/static.vert b/src/shaders/static.vert index 233f1a9..b0a79bb 100644 --- a/src/shaders/static.vert +++ b/src/shaders/static.vert @@ -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); }