diff --git a/ImageSharp b/ImageSharp
new file mode 160000
index 0000000..8524b7e
--- /dev/null
+++ b/ImageSharp
@@ -0,0 +1 @@
+Subproject commit 8524b7e0a75bdb7398e8b60885c442a46c57ab91
diff --git a/NHEngine/BootStrap.cs b/NHEngine/BootStrap.cs
index 6b384f0..6dec481 100644
--- a/NHEngine/BootStrap.cs
+++ b/NHEngine/BootStrap.cs
@@ -10,8 +10,10 @@ using OpenTK.Audio.OpenAL;
using OpenTK.Audio;
using ImageSharp;
+using ImageSharp.Processing;
using org.niclasundharald.engine.graphics;
+using org.niclasundharald.engine;
namespace nhengine
{
@@ -58,16 +60,27 @@ namespace nhengine
public void bootMap(){
ImageSharp.Image i = ImageSharp.Image.Load( new FileStream("M3-wip.png",FileMode.Open));
i.Flip(ImageSharp.Processing.FlipType.Vertical);
+ i.Resize(500,500);
+
map = new SquaredMap(i);
glWindow.Scene.RootObject.addChild( map );
-
+
+ ModelManager.instance.addSearchPath("./models");
+
+ DumpObject dobj = new DumpObject();
+ dobj.Model3D = ModelManager.instance.loadModel("alfa147",0.0254f);
+ Vector3 v3 = map.ground(new Vector2(40,40));
+ v3.Z *= 2;
+ dobj.Position = v3;
+
+ glWindow.Scene.RootObject.addChild( dobj );
}
public void run(){
glWindow.MakeCurrent();
- glWindow.Run(30,30);
+ glWindow.Run(25,25);
}
diff --git a/NHEngine/OpenGLWindow.cs b/NHEngine/OpenGLWindow.cs
index 7cfabbb..e42f8aa 100644
--- a/NHEngine/OpenGLWindow.cs
+++ b/NHEngine/OpenGLWindow.cs
@@ -54,12 +54,12 @@ namespace nhengine
GL.Enable(EnableCap.Blend);
GL.BlendFunc(BlendingFactorSrc.SrcAlpha,BlendingFactorDest.OneMinusSrcAlpha);
- cube = new Cube(new Vector3(0,0,512), 128.0f);
- c1 = new Cube(new Vector3(512,0,512), 128.0f);
- c2 = new Cube(new Vector3(0,512,512), 128.0f);
- c3 = new Cube(new Vector3(512,512,512), 128.0f);
+ cube = new Cube(new Vector3(0,0,150), 16.0f);
+ c1 = new Cube(new Vector3(16,0,150), 8.0f);
+ c2 = new Cube(new Vector3(0,150,150), 8.0f);
+ c3 = new Cube(new Vector3(175,175,150), 8.0f);
- lookAt = new Vector3(0,0,0);
+ lookAt = new Vector3(0,0,128.0f);
lookDistance = 2048;
arcUpDown = MathHelper.PiOver6;
arcLeftRight = MathHelper.PiOver4;
@@ -94,6 +94,22 @@ namespace nhengine
scene.draw();
SwapBuffers();
+
+ Title = string.Format("{0:F}/s {1:F}/s [{2:F}s]", RenderFrequency,UpdateFrequency,UpdatePeriod);
+ }
+
+ protected override void OnUpdateFrame(FrameEventArgs e)
+ {
+ base.OnUpdateFrame(e);
+ Matrix4 m4 = Matrix4.CreateRotationZ(MathHelper.Pi / 90.0f);
+
+ cube.Rotation = m4 * cube.Rotation;
+ c1.Position = (m4.Inverted() * new Vector4(c1.Position)).Xyz;
+ c2.Rotation = (m4 * c2.Rotation);
+ c3.Position = (m4 * new Vector4(c3.Position)).Xyz;
+
+
+ Actor.updateAll( (float)UpdatePeriod );
}
private void captureMouse(){
@@ -164,15 +180,36 @@ namespace nhengine
rotateLeftRight(-MathHelper.Pi / 90.0f);
break;
case OpenTK.Input.Key.W:
- walk(250.0f);
+ walk(e.Shift ? 50.0f : 5.0f);
break;
case OpenTK.Input.Key.S:
- walk(-250.0f);
+ walk(e.Shift ? -50.0f : -5.0f);
+ break;
+ case OpenTK.Input.Key.A:
+ strafe(e.Shift ? -50.0f : -5.0f);
+ break;
+ case OpenTK.Input.Key.D:
+ strafe(e.Shift ? 50.0f : 5.0f);
+ break;
+
+ case OpenTK.Input.Key.Space:
+ fireBallistic();
break;
}
}
+ private void fireBallistic(){
+ Console.WriteLine("Fire Ballistic...");
+ BallisticActor ba = new BallisticActor(0);
+
+ ba.Position = BootStrap.instance().SquaredMap.ground(new Vector2(10,10));
+ ba.Velocity = new Vector3(1,1,1);// + (Matrix4.CreateRotationZ(arcLeftRight) * Vector4.UnitY).Xyz;
+ ba.Velocity.Normalize();
+ ba.Velocity *= 50;
+ }
+
+
public void rotateUpDown(float arc)
{
arcUpDown += arc;
@@ -191,6 +228,11 @@ namespace nhengine
setupCamera();
}
+ public void strafe(float distance){
+ lookAt += Vector3.Cross(new Vector3(sceneCamera.View.Xy),Vector3.UnitZ).Normalized() * distance;
+ setupCamera();
+ }
+
protected override void OnKeyUp(OpenTK.Input.KeyboardKeyEventArgs e)
{
}
diff --git a/NHEngine/models/ballistisch.mtl b/NHEngine/models/ballistisch.mtl
new file mode 100644
index 0000000..b88b8cb
--- /dev/null
+++ b/NHEngine/models/ballistisch.mtl
@@ -0,0 +1,10 @@
+# Blender MTL File: 'ballistisch.blend'
+# Material Count: 1
+
+newmtl None
+Ns 0
+Ka 0.000000 0.000000 0.000000
+Kd 0.8 0.8 0.8
+Ks 0.8 0.8 0.8
+d 1
+illum 2
diff --git a/NHEngine/models/ballistisch.obj b/NHEngine/models/ballistisch.obj
new file mode 100644
index 0000000..6d35ef3
--- /dev/null
+++ b/NHEngine/models/ballistisch.obj
@@ -0,0 +1,240 @@
+# Blender v2.78 (sub 0) OBJ File: 'ballistisch.blend'
+# www.blender.org
+mtllib ballistisch.mtl
+o Cylinder
+v 0.000000 -1.000000 -0.250000
+v 0.000000 1.000000 -0.250000
+v 0.048773 -1.000000 -0.245196
+v 0.048773 1.000000 -0.245196
+v 0.095671 -1.000000 -0.230970
+v 0.095671 1.000000 -0.230970
+v 0.138893 -1.000000 -0.207867
+v 0.138893 1.000000 -0.207867
+v 0.176777 -1.000000 -0.176777
+v 0.176777 1.000000 -0.176777
+v 0.207867 -1.000000 -0.138893
+v 0.207867 1.000000 -0.138893
+v 0.230970 -1.000000 -0.095671
+v 0.230970 1.000000 -0.095671
+v 0.245196 -1.000000 -0.048773
+v 0.245196 1.000000 -0.048773
+v 0.250000 -1.000000 -0.000000
+v 0.250000 1.000000 -0.000000
+v 0.245196 -1.000000 0.048773
+v 0.245196 1.000000 0.048773
+v 0.230970 -1.000000 0.095671
+v 0.230970 1.000000 0.095671
+v 0.207867 -1.000000 0.138893
+v 0.207867 1.000000 0.138893
+v 0.176777 -1.000000 0.176777
+v 0.176777 1.000000 0.176777
+v 0.138893 -1.000000 0.207867
+v 0.138893 1.000000 0.207867
+v 0.095671 -1.000000 0.230970
+v 0.095671 1.000000 0.230970
+v 0.048773 -1.000000 0.245196
+v 0.048773 1.000000 0.245196
+v -0.000000 -1.000000 0.250000
+v -0.000000 1.000000 0.250000
+v -0.048773 -1.000000 0.245196
+v -0.048773 1.000000 0.245196
+v -0.095671 -1.000000 0.230970
+v -0.095671 1.000000 0.230970
+v -0.138893 -1.000000 0.207867
+v -0.138893 1.000000 0.207867
+v -0.176777 -1.000000 0.176777
+v -0.176777 1.000000 0.176777
+v -0.207868 -1.000000 0.138892
+v -0.207868 1.000000 0.138892
+v -0.230970 -1.000000 0.095671
+v -0.230970 1.000000 0.095671
+v -0.245196 -1.000000 0.048772
+v -0.245196 1.000000 0.048772
+v -0.250000 -1.000000 -0.000000
+v -0.250000 1.000000 -0.000000
+v -0.245196 -1.000000 -0.048773
+v -0.245196 1.000000 -0.048773
+v -0.230970 -1.000000 -0.095671
+v -0.230970 1.000000 -0.095671
+v -0.207867 -1.000000 -0.138893
+v -0.207867 1.000000 -0.138893
+v -0.176776 -1.000000 -0.176777
+v -0.176776 1.000000 -0.176777
+v -0.138892 -1.000000 -0.207868
+v -0.138892 1.000000 -0.207868
+v -0.095671 -1.000000 -0.230970
+v -0.095671 1.000000 -0.230970
+v -0.048772 -1.000000 -0.245196
+v -0.048772 1.000000 -0.245196
+vn 0.0980 0.0000 -0.9952
+vn 0.2903 0.0000 -0.9569
+vn 0.4714 0.0000 -0.8819
+vn 0.6344 0.0000 -0.7730
+vn 0.7730 0.0000 -0.6344
+vn 0.8819 0.0000 -0.4714
+vn 0.9569 0.0000 -0.2903
+vn 0.9952 0.0000 -0.0980
+vn 0.9952 0.0000 0.0980
+vn 0.9569 0.0000 0.2903
+vn 0.8819 0.0000 0.4714
+vn 0.7730 0.0000 0.6344
+vn 0.6344 0.0000 0.7730
+vn 0.4714 0.0000 0.8819
+vn 0.2903 0.0000 0.9569
+vn 0.0980 0.0000 0.9952
+vn -0.0980 0.0000 0.9952
+vn -0.2903 0.0000 0.9569
+vn -0.4714 0.0000 0.8819
+vn -0.6344 0.0000 0.7730
+vn -0.7730 0.0000 0.6344
+vn -0.8819 0.0000 0.4714
+vn -0.9569 0.0000 0.2903
+vn -0.9952 0.0000 0.0980
+vn -0.9952 0.0000 -0.0980
+vn -0.9569 0.0000 -0.2903
+vn -0.8819 0.0000 -0.4714
+vn -0.7730 0.0000 -0.6344
+vn -0.6344 0.0000 -0.7730
+vn -0.4714 0.0000 -0.8819
+vn 0.0000 1.0000 0.0000
+vn -0.2903 0.0000 -0.9569
+vn -0.0980 0.0000 -0.9952
+vn 0.0000 -1.0000 -0.0000
+usemtl None
+s off
+f 1//1 2//1 4//1 3//1
+f 3//2 4//2 6//2 5//2
+f 5//3 6//3 8//3 7//3
+f 7//4 8//4 10//4 9//4
+f 9//5 10//5 12//5 11//5
+f 11//6 12//6 14//6 13//6
+f 13//7 14//7 16//7 15//7
+f 15//8 16//8 18//8 17//8
+f 17//9 18//9 20//9 19//9
+f 19//10 20//10 22//10 21//10
+f 21//11 22//11 24//11 23//11
+f 23//12 24//12 26//12 25//12
+f 25//13 26//13 28//13 27//13
+f 27//14 28//14 30//14 29//14
+f 29//15 30//15 32//15 31//15
+f 31//16 32//16 34//16 33//16
+f 33//17 34//17 36//17 35//17
+f 35//18 36//18 38//18 37//18
+f 37//19 38//19 40//19 39//19
+f 39//20 40//20 42//20 41//20
+f 41//21 42//21 44//21 43//21
+f 43//22 44//22 46//22 45//22
+f 45//23 46//23 48//23 47//23
+f 47//24 48//24 50//24 49//24
+f 49//25 50//25 52//25 51//25
+f 51//26 52//26 54//26 53//26
+f 53//27 54//27 56//27 55//27
+f 55//28 56//28 58//28 57//28
+f 57//29 58//29 60//29 59//29
+f 59//30 60//30 62//30 61//30
+f 4//31 2//31 64//31 62//31 60//31 58//31 56//31 54//31 52//31 50//31 48//31 46//31 44//31 42//31 40//31 38//31 36//31 34//31 32//31 30//31 28//31 26//31 24//31 22//31 20//31 18//31 16//31 14//31 12//31 10//31 8//31 6//31
+f 61//32 62//32 64//32 63//32
+f 63//33 64//33 2//33 1//33
+f 1//34 3//34 5//34 7//34 9//34 11//34 13//34 15//34 17//34 19//34 21//34 23//34 25//34 27//34 29//34 31//34 33//34 35//34 37//34 39//34 41//34 43//34 45//34 47//34 49//34 51//34 53//34 55//34 57//34 59//34 61//34 63//34
+o Cone
+v -0.000000 0.939394 -0.250000
+v 0.048773 0.939394 -0.245196
+v 0.095671 0.939394 -0.230970
+v 0.138893 0.939394 -0.207867
+v 0.176777 0.939394 -0.176777
+v 0.207867 0.939394 -0.138892
+v 0.230970 0.939394 -0.095671
+v 0.245196 0.939394 -0.048773
+v 0.250000 0.939394 0.000000
+v -0.000000 2.939394 0.000000
+v 0.245196 0.939394 0.048773
+v 0.230970 0.939394 0.095671
+v 0.207867 0.939394 0.138893
+v 0.176777 0.939394 0.176777
+v 0.138893 0.939394 0.207867
+v 0.095671 0.939394 0.230970
+v 0.048772 0.939394 0.245196
+v -0.000000 0.939394 0.250000
+v -0.048773 0.939394 0.245196
+v -0.095671 0.939394 0.230970
+v -0.138893 0.939394 0.207867
+v -0.176777 0.939394 0.176777
+v -0.207868 0.939394 0.138892
+v -0.230970 0.939394 0.095671
+v -0.245196 0.939394 0.048772
+v -0.250000 0.939394 -0.000000
+v -0.245196 0.939394 -0.048773
+v -0.230970 0.939394 -0.095671
+v -0.207867 0.939394 -0.138893
+v -0.176776 0.939394 -0.176777
+v -0.138892 0.939394 -0.207868
+v -0.095671 0.939394 -0.230970
+v -0.048772 0.939394 -0.245196
+vn 0.0973 0.1234 -0.9876
+vn 0.2881 0.1234 -0.9496
+vn 0.4678 0.1234 -0.8752
+vn 0.6295 0.1234 -0.7671
+vn 0.7671 0.1234 -0.6295
+vn 0.8752 0.1234 -0.4678
+vn 0.9496 0.1234 -0.2881
+vn 0.9876 0.1234 -0.0973
+vn 0.9876 0.1234 0.0973
+vn 0.9496 0.1234 0.2881
+vn 0.8752 0.1234 0.4678
+vn 0.7671 0.1234 0.6295
+vn 0.6295 0.1234 0.7671
+vn 0.4678 0.1234 0.8752
+vn 0.2881 0.1234 0.9496
+vn 0.0973 0.1234 0.9876
+vn -0.0973 0.1234 0.9876
+vn -0.2881 0.1234 0.9496
+vn -0.4678 0.1234 0.8752
+vn -0.6295 0.1234 0.7671
+vn -0.7671 0.1234 0.6295
+vn -0.8752 0.1234 0.4678
+vn -0.9496 0.1234 0.2881
+vn -0.9876 0.1234 0.0973
+vn -0.9876 0.1234 -0.0973
+vn -0.9496 0.1234 -0.2881
+vn -0.8752 0.1234 -0.4678
+vn -0.7671 0.1234 -0.6295
+vn -0.6295 0.1234 -0.7671
+vn -0.4678 0.1234 -0.8752
+vn -0.2881 0.1234 -0.9496
+vn -0.0973 0.1234 -0.9876
+vn 0.0000 -1.0000 0.0000
+usemtl None
+s off
+f 65//35 74//35 66//35
+f 66//36 74//36 67//36
+f 67//37 74//37 68//37
+f 68//38 74//38 69//38
+f 69//39 74//39 70//39
+f 70//40 74//40 71//40
+f 71//41 74//41 72//41
+f 72//42 74//42 73//42
+f 73//43 74//43 75//43
+f 75//44 74//44 76//44
+f 76//45 74//45 77//45
+f 77//46 74//46 78//46
+f 78//47 74//47 79//47
+f 79//48 74//48 80//48
+f 80//49 74//49 81//49
+f 81//50 74//50 82//50
+f 82//51 74//51 83//51
+f 83//52 74//52 84//52
+f 84//53 74//53 85//53
+f 85//54 74//54 86//54
+f 86//55 74//55 87//55
+f 87//56 74//56 88//56
+f 88//57 74//57 89//57
+f 89//58 74//58 90//58
+f 90//59 74//59 91//59
+f 91//60 74//60 92//60
+f 92//61 74//61 93//61
+f 93//62 74//62 94//62
+f 94//63 74//63 95//63
+f 95//64 74//64 96//64
+f 96//65 74//65 97//65
+f 97//66 74//66 65//66
+f 65//67 66//67 67//67 68//67 69//67 70//67 71//67 72//67 73//67 75//67 76//67 77//67 78//67 79//67 80//67 81//67 82//67 83//67 84//67 85//67 86//67 87//67 88//67 89//67 90//67 91//67 92//67 93//67 94//67 95//67 96//67 97//67
diff --git a/NHEngine/nhengine.csproj b/NHEngine/nhengine.csproj
index 7d6c13a..d25d4b8 100644
--- a/NHEngine/nhengine.csproj
+++ b/NHEngine/nhengine.csproj
@@ -19,6 +19,7 @@
4
false
true
+ anycpu
true
@@ -33,12 +34,10 @@
..\packages\OpenTK.2.0.0\lib\net20\OpenTK.dll
-
..\packages\System.Buffers.4.3.0\lib\netstandard1.1\System.Buffers.dll
-
..\packages\System.Numerics.Vectors.4.3.0\lib\portable-net45+win8+wp8+wpa81\System.Numerics.Vectors.dll
@@ -54,15 +53,15 @@
- ..\packages\ImageSharp.1.0.0-alpha7-00006\lib\netstandard1.1\ImageSharp.dll
+ ..\org.niclasundharald.engine\contrib\ImageSharp.dll
+
-
@@ -76,8 +75,13 @@
PreserveNewest
-
+
+ PreserveNewest
+
+
+ PreserveNewest
+
diff --git a/NHEngine/packages.config b/NHEngine/packages.config
index 0bf7a50..353e05a 100644
--- a/NHEngine/packages.config
+++ b/NHEngine/packages.config
@@ -1,6 +1,5 @@
-
diff --git a/nhengine.sln b/nhengine.sln
index 3859c4b..226eb9d 100644
--- a/nhengine.sln
+++ b/nhengine.sln
@@ -5,6 +5,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "nhengine", "NHEngine\nhengi
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "org.niclasundharald.engine", "org.niclasundharald.engine\org.niclasundharald.engine.csproj", "{3E812F66-D5F3-4599-8360-97F355B6CC1B}"
EndProject
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "contrib", "contrib", "{9BA2E63F-E39C-465C-AC48-45B30B532A0C}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ImageSharp", "ImageSharp\ImageSharp.csproj", "{4D1A7C04-2C4E-4C74-AD81-FE0DCA9C6DF0}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -19,5 +23,12 @@ Global
{3E812F66-D5F3-4599-8360-97F355B6CC1B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3E812F66-D5F3-4599-8360-97F355B6CC1B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3E812F66-D5F3-4599-8360-97F355B6CC1B}.Release|Any CPU.Build.0 = Release|Any CPU
+ {4D1A7C04-2C4E-4C74-AD81-FE0DCA9C6DF0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {4D1A7C04-2C4E-4C74-AD81-FE0DCA9C6DF0}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {4D1A7C04-2C4E-4C74-AD81-FE0DCA9C6DF0}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {4D1A7C04-2C4E-4C74-AD81-FE0DCA9C6DF0}.Release|Any CPU.Build.0 = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(NestedProjects) = preSolution
+ {4D1A7C04-2C4E-4C74-AD81-FE0DCA9C6DF0} = {9BA2E63F-E39C-465C-AC48-45B30B532A0C}
EndGlobalSection
EndGlobal
diff --git a/org.niclasundharald.engine/Actor.cs b/org.niclasundharald.engine/Actor.cs
new file mode 100644
index 0000000..e73f444
--- /dev/null
+++ b/org.niclasundharald.engine/Actor.cs
@@ -0,0 +1,72 @@
+using System;
+using System.Collections.Generic;
+
+using OpenTK;
+using org.niclasundharald.engine.graphics;
+
+
+namespace org.niclasundharald.engine
+{
+ public class Actor : WorldObject
+ {
+ public static List activeActors = new List();
+ public static List finishedActors = new List();
+
+ public static void updateAll(float timespan){
+ foreach (Actor a in activeActors){
+ a.update(timespan);
+ }
+
+ foreach (Actor a in finishedActors){
+ activeActors.Remove(a);
+ }
+ finishedActors.Clear();
+
+ }
+
+ private int id;
+
+ public Actor(int id)
+ {
+ Console.WriteLine("New Actor: {0} / {1}",id,this);
+ this.id = id;
+ activeActors.Add(this);
+ }
+
+ public void destroy(){
+ finishedActors.Add(this);
+ }
+
+ public Vector3 Heading { get; set; }
+ public Vector3 Velocity { get; set; }
+ public float Weight { get; set; }
+
+ public virtual void update(float timespan){
+ }
+
+ public void setHeading(Vector3 heading,Vector3 top){
+ Vector3 x,y,z;
+
+ z = heading.Normalized();
+ x = Vector3.Cross( top.Normalized(), z ).Normalized();
+ y = Vector3.Cross( x, z );
+
+ Matrix4 mRotation = new Matrix4(
+ new Vector4(x,0),
+ new Vector4(y,0),
+ new Vector4(z,0),
+ new Vector4(0,0,0,1)
+ );
+
+ Rotation = Matrix4.CreateRotationX(MathHelper.PiOver2) * mRotation;
+ }
+
+ public Model3D Model3D { get; set; }
+
+ public override Model3D getModel3D()
+ {
+ return Model3D;
+ }
+
+ }
+}
diff --git a/org.niclasundharald.engine/ActorAction.cs b/org.niclasundharald.engine/ActorAction.cs
new file mode 100644
index 0000000..abc36b7
--- /dev/null
+++ b/org.niclasundharald.engine/ActorAction.cs
@@ -0,0 +1,14 @@
+using System;
+namespace org.niclasundharald.engine
+{
+ /**
+ * @class ActorAction
+ * @brief Base Class to manage orders, jobs, other things to do and/or changes over time for Actors
+ */
+ public class ActorAction
+ {
+ public ActorAction(Actor actor)
+ {
+ }
+ }
+}
diff --git a/org.niclasundharald.engine/BallisticActor.cs b/org.niclasundharald.engine/BallisticActor.cs
new file mode 100644
index 0000000..90fd0de
--- /dev/null
+++ b/org.niclasundharald.engine/BallisticActor.cs
@@ -0,0 +1,43 @@
+using System;
+using org.niclasundharald.engine.graphics.primitives;
+using org.niclasundharald.engine.graphics;
+
+using OpenTK;
+
+namespace org.niclasundharald.engine
+{
+ public class BallisticActor : Actor
+ {
+ public BallisticActor(int id)
+ :base(id)
+ {
+ this.Model3D = ModelManager.instance.findModel("ballistisch");
+ }
+
+ public override void update(float timespan)
+ {
+ base.update(timespan);
+
+ Velocity += (Physics.Gravitation * timespan);
+ Position += Velocity * timespan;
+ Scale = Matrix4.CreateScale(3.0f);
+
+ setHeading( Velocity, Physics.Gravitation);
+
+ Console.WriteLine("BallisticActor update: {0} / {1}",Position,Velocity);
+
+ try{
+ Vector3 ground = SquaredMap.activeMap.ground(Position.Xy);
+
+ if (Position.Z <= ground.Z){
+ destroy();
+ }
+ } catch (OutOfWorldException e){
+ destroy();
+ }
+
+
+ }
+
+ }
+}
diff --git a/org.niclasundharald.engine/FileHelper.cs b/org.niclasundharald.engine/FileHelper.cs
index 84b6821..c7d31db 100644
--- a/org.niclasundharald.engine/FileHelper.cs
+++ b/org.niclasundharald.engine/FileHelper.cs
@@ -8,8 +8,10 @@ namespace org.niclasundharald.engine
public static string findFile(string filename,string[] searchPaths){
foreach (string searchPath in searchPaths){
- string fullname = String.Format("{0}{1}{2}",searchPath,Path.PathSeparator,filename);
+ string fullname = String.Format("{0}{1}{2}",searchPath,Path.DirectorySeparatorChar,filename);
+ Console.WriteLine("lookupFile: {0}",fullname);
if (File.Exists(fullname)){
+ Console.WriteLine("foundFile: {0}",fullname);
return fullname;
}
}
diff --git a/org.niclasundharald.engine/Physics.cs b/org.niclasundharald.engine/Physics.cs
new file mode 100644
index 0000000..2a438e7
--- /dev/null
+++ b/org.niclasundharald.engine/Physics.cs
@@ -0,0 +1,13 @@
+using System;
+
+using OpenTK;
+
+namespace org.niclasundharald.engine
+{
+ public abstract class Physics
+ {
+ public static Vector3 Gravitation { get; set; } = new Vector3(0,0,-9.81f);
+
+
+ }
+}
diff --git a/org.niclasundharald.engine/WorldObject.cs b/org.niclasundharald.engine/WorldObject.cs
index 3681906..d5e4c7d 100644
--- a/org.niclasundharald.engine/WorldObject.cs
+++ b/org.niclasundharald.engine/WorldObject.cs
@@ -9,13 +9,10 @@ namespace org.niclasundharald.engine
{
public abstract class WorldObject
{
- private Matrix4 transformation;
-
private List children;
public WorldObject()
{
- transformation = Matrix4.Identity;
children = new List();
}
@@ -23,15 +20,13 @@ namespace org.niclasundharald.engine
return null;
}
+ public Vector3 Position{ get; set; } = new Vector3();
+ public Matrix4 Rotation { get; set; } = Matrix4.Identity;
+ public Matrix4 Scale { get; set; } = Matrix4.Identity;
- public Vector3 Position{
- get { return this.transformation.ExtractTranslation(); }
- set { this.transformation += Matrix4.CreateTranslation(value - this.transformation.ExtractTranslation()); }
- }
public Matrix4 Transformation {
- get { return this.transformation; }
- set { this.transformation = value; }
+ get { return (Scale * Rotation) * Matrix4.CreateTranslation( Position ) ; }
}
public void addChild(WorldObject wo){
@@ -55,4 +50,21 @@ namespace org.niclasundharald.engine
public class ObjectGroup : WorldObject {
}
+
+ public class DumpObject : WorldObject {
+
+ Model3D model3d;
+
+ public Model3D Model3D {
+ get { return this.model3d; }
+ set { this.model3d = value; }
+ }
+
+ public override Model3D getModel3D()
+ {
+ return model3d;
+ }
+
+ }
+
}
diff --git a/org.niclasundharald.engine/contrib/ImageSharp.dll b/org.niclasundharald.engine/contrib/ImageSharp.dll
new file mode 100644
index 0000000..95397d5
Binary files /dev/null and b/org.niclasundharald.engine/contrib/ImageSharp.dll differ
diff --git a/org.niclasundharald.engine/exceptions/OutOfWorldException.cs b/org.niclasundharald.engine/exceptions/OutOfWorldException.cs
new file mode 100644
index 0000000..1388111
--- /dev/null
+++ b/org.niclasundharald.engine/exceptions/OutOfWorldException.cs
@@ -0,0 +1,10 @@
+using System;
+namespace org.niclasundharald.engine
+{
+ public class OutOfWorldException : Exception
+ {
+ public OutOfWorldException()
+ {
+ }
+ }
+}
diff --git a/org.niclasundharald.engine/graphics/GLCamera.cs b/org.niclasundharald.engine/graphics/GLCamera.cs
index a1e3beb..bb3ff44 100644
--- a/org.niclasundharald.engine/graphics/GLCamera.cs
+++ b/org.niclasundharald.engine/graphics/GLCamera.cs
@@ -45,7 +45,7 @@ namespace org.niclasundharald.engine.graphics
_mProjection = Matrix4.CreatePerspectiveFieldOfView(
fov,
width / height,
- 50.0f,
+ 1.0f,
100000.0f
);
}
diff --git a/org.niclasundharald.engine/graphics/GLScene.cs b/org.niclasundharald.engine/graphics/GLScene.cs
index 2ca17c6..2195929 100644
--- a/org.niclasundharald.engine/graphics/GLScene.cs
+++ b/org.niclasundharald.engine/graphics/GLScene.cs
@@ -39,10 +39,17 @@ namespace org.niclasundharald.engine.graphics
if (root != null){
draw( objectMatrix, root );
}
+
+ foreach (WorldObject child in Actor.activeActors){
+ draw( objectMatrix, child );
+ }
+
}
public void draw(Matrix4 baseMatrix,WorldObject wo){
- Matrix4 objectMatrix = baseMatrix * wo.Transformation;
+ Matrix4 objectMatrix = wo.Transformation * baseMatrix;
+
+ //Console.WriteLine("draw(,{0}",wo);
//Console.WriteLine("draw(): o={0}\noM=\n{1}",wo,objectMatrix);
shader.setup(objectMatrix, sceneOrientation);
diff --git a/org.niclasundharald.engine/graphics/LoadedModel.cs b/org.niclasundharald.engine/graphics/LoadedModel.cs
new file mode 100644
index 0000000..98190e8
--- /dev/null
+++ b/org.niclasundharald.engine/graphics/LoadedModel.cs
@@ -0,0 +1,142 @@
+using System;
+using System.IO;
+using System.Collections.Generic;
+using System.Globalization;
+
+using OpenTK;
+
+namespace org.niclasundharald.engine.graphics
+{
+ public class LoadedModel : Model3D
+ {
+ string sourceName;
+
+ public LoadedModel(string filename)
+ {
+ sourceName = filename;
+ load(new StreamReader(filename));
+ }
+ public LoadedModel(string filename,float scale)
+ {
+ sourceName = filename;
+ load(new StreamReader(filename),scale);
+ }
+
+ private void load(TextReader reader){
+ load(reader,1);
+ }
+ private void load(TextReader reader,float scale){
+ List vertexes,normals;
+ List colors;
+ List triangles;
+ string line;
+
+ float[] min = new float[3];
+ float[] max = new float[3];
+
+ vertexes = new List();
+ normals = new List();
+ colors = new List();
+ triangles = new List();
+
+ vertexes.Add(new Vector3());
+ normals.Add(new Vector3());
+
+ while ( (line = reader.ReadLine()) != null){
+ string[] fields = line.Split(new string[0],StringSplitOptions.RemoveEmptyEntries);
+
+ if (fields.Length > 0)
+ switch (fields[0]){
+ case "v":
+ float x,y,z;
+ x = (float)Double.Parse(fields[1],CultureInfo.InvariantCulture);
+ y = (float)Double.Parse(fields[2],CultureInfo.InvariantCulture);
+ z = (float)Double.Parse(fields[3],CultureInfo.InvariantCulture);
+
+ x *= scale;
+ y *= scale;
+ z *= scale;
+
+ vertexes.Add( new Vector3(x,y,z) );
+ min[0] = min[0] > x ? x : min[0];
+ min[1] = min[1] > y ? y : min[1];
+ min[2] = min[2] > z ? z : min[2];
+ max[0] = max[0] < x ? x : max[0];
+ max[1] = max[1] < y ? y : max[1];
+ max[2] = max[2] < z ? z : max[2];
+ break;
+ case "vn":
+ normals.Add( -(new Vector3(
+ float.Parse(fields[1],CultureInfo.InvariantCulture),
+ float.Parse(fields[2],CultureInfo.InvariantCulture),
+ float.Parse(fields[3],CultureInfo.InvariantCulture)
+ )
+ ));
+ break;
+ case "f":
+
+ surfaceindeces si0,si1,si2;
+
+ si0 = new surfaceindeces(fields[1]);
+ si1 = new surfaceindeces(fields[2]);
+ si2 = new surfaceindeces(fields[3]);
+
+ triangles.Add(new triangle(
+ vertexes[si0.vertex],
+ vertexes[si1.vertex],
+ vertexes[si2.vertex],
+ normals[si0.normal],
+ normals[si1.normal],
+ normals[si2.normal]));
+
+ break;
+ }
+ }
+
+ Console.WriteLine("Loaded {0}: {1} vertexes {2} normals",sourceName,vertexes.Count,normals.Count);
+ Console.WriteLine("Dimensions: {0}/{1}/{2} - {3}/{4}/{5}",min[0],min[1],min[2],max[0],max[1],max[2]);
+ vertexes.Clear();
+ normals.Clear();
+
+ foreach (triangle t in triangles){
+ vertexes.Add( t.a );
+ vertexes.Add( t.b );
+ vertexes.Add( t.c );
+ normals.Add( t.na );
+ normals.Add( t.nb );
+ normals.Add( t.nc );
+ }
+
+ // bind(vertexes.ToArray(),null,normals.ToArray());
+ bind(vertexes.ToArray(),null,normals.ToArray());
+
+ }
+
+ struct triangle{
+ public Vector3 a,b,c;
+ public Vector3 na,nb,nc;
+
+ public triangle(Vector3 a,Vector3 b,Vector3 c,Vector3 na,Vector3 nb,Vector3 nc){
+ this.a = a;
+ this.b = b;
+ this.c = c;
+ this.na = na;
+ this.nb = nb;
+ this.nc = nc;
+ }
+ }
+
+ struct surfaceindeces {
+
+ public int vertex,texture,normal;
+
+ public surfaceindeces(string token){
+ string[] l = token.Split('/');
+ vertex = l[0].Length == 0 ? 0 : int.Parse(l[0]);
+ texture = l[1].Length == 0 ? 0 : int.Parse(l[1]);
+ normal = l[2].Length == 0 ? 0 : int.Parse(l[2]);
+ }
+
+ }
+ }
+}
diff --git a/org.niclasundharald.engine/graphics/Model3D.cs b/org.niclasundharald.engine/graphics/Model3D.cs
index 2589f82..ff3fadd 100644
--- a/org.niclasundharald.engine/graphics/Model3D.cs
+++ b/org.niclasundharald.engine/graphics/Model3D.cs
@@ -14,6 +14,11 @@ namespace org.niclasundharald.engine.graphics {
protected int nTriangles;
+ Vector3[] vertexes;
+ Vector4[] colors;
+ Vector3[] normals;
+
+
protected Model3D(){
vao = GL.GenVertexArray();
nTriangles = 0;
@@ -55,6 +60,10 @@ namespace org.niclasundharald.engine.graphics {
GL.BindVertexArray(0);
}
+ protected void rebind(){
+
+ }
+
protected void bind(Vector3[] vertexes){
bind( vertexes, null, null, null );
}
@@ -68,58 +77,46 @@ namespace org.niclasundharald.engine.graphics {
}
protected void bind(Vector3[] vertexes,Vector4[] colors,Vector3[] normals,Vector2[] uvs){
- float[] fv = new float[vertexes.Length * 3];
+/* float[] fv = new float[vertexes.Length * 3];
for (int n=0;n knownModels;
List searchPaths;
- public ModelManager()
+ protected ModelManager()
{
knownModels = new Dictionary();
searchPaths = new List();
@@ -23,17 +25,18 @@ namespace org.niclasundharald.engine.graphics
}
- public Model3D loadModel(String mName){
+ public Model3D loadModel(String mName,float scale){
string fullName = FileHelper.findFile(String.Format("{0}.obj",mName),searchPaths.ToArray());
if (fullName != null){
-
+ Console.WriteLine("Model found: {0}",fullName);
+ return Model3D.loadObjFile(fullName,scale);
}
return null;
}
public Model3D findModel(String mName){
if (!knownModels.ContainsKey(mName)){
- return loadModel(mName);
+ return loadModel(mName,1);
} else {
return knownModels[mName];
}
diff --git a/NHEngine/SquaredMap.cs b/org.niclasundharald.engine/graphics/SquaredMap.cs
similarity index 83%
rename from NHEngine/SquaredMap.cs
rename to org.niclasundharald.engine/graphics/SquaredMap.cs
index 5ce387a..5ac68f4 100644
--- a/NHEngine/SquaredMap.cs
+++ b/org.niclasundharald.engine/graphics/SquaredMap.cs
@@ -10,13 +10,15 @@ using OpenTK.Graphics.OpenGL4;
using OpenTK;
using org.niclasundharald.engine;
-using org.niclasundharald.engine.graphics;
-namespace nhengine
+namespace org.niclasundharald.engine.graphics
{
public class SquaredMap : WorldObject
{
- private static float edge = 64;
+ public static SquaredMap activeMap;
+
+ private static float edge = 5;
+ private static float maxHeight = 128.0f;
private int width,
height;
@@ -27,6 +29,8 @@ namespace nhengine
public SquaredMap(int width,int height)
{
+ activeMap = this;
+
this.width = width;
this.height = height;
@@ -44,6 +48,8 @@ namespace nhengine
public SquaredMap(Image heightMap)
{
+ activeMap = this;
+
this.width = heightMap.Width-1;
this.height = heightMap.Height-1;
@@ -63,7 +69,7 @@ namespace nhengine
for (int x = 0; x <= width; x++)
{
float h = (float)rand.NextDouble();
- heightMap[x + (y * width)] = (float)(256 * (h * h));
+ heightMap[x + (y * width)] = (float)(maxHeight * (h * h));
}
}
}
@@ -77,7 +83,7 @@ namespace nhengine
for (int x = 0; x <= width; x++)
{
Rgba32 pixel = pixels[ x + (y * (width + 1))];
- float h = (pixel.R + pixel.G + pixel.B) / 3;
+ float h = (pixel.R + pixel.G + pixel.B) * maxHeight / 768;
heightMap[x + (y * (width + 1))] = (float)(h);
}
}
@@ -151,13 +157,38 @@ namespace nhengine
}
this.model = new MapModel3D( vertexes );
-
-
- this.Position = new Vector3(-(width)*edge,-(height)*edge,0);
-
}
+
+ private int indHeightMap(int x,int y){
+ return x + ((width + 1) * y);
+ }
+
+ public Vector3 ground(Vector2 _xy){
+ Vector2 xy = _xy / edge;
+
+ int i1 = indHeightMap((int)xy.X,(int)xy.Y);
+ int i2 = indHeightMap((int)xy.X,(int)xy.Y+1);
+
+ if ((xy.X < 0)||(xy.Y<0)||(xy.X>=width)||(xy.Y>=height)){
+ throw new OutOfWorldException();
+ }
+
+ float h = heightMap[i1] +
+ heightMap[i1 + 1] +
+ heightMap[i2] +
+ heightMap[i2 + 1];
+
+ h /= 4;
+
+ Vector3 v3 = new Vector3(_xy.X,_xy.Y,h);
+ Console.WriteLine("Grounding: {0}",v3);
+
+ return v3;
+ }
+
}
+
class MapModel3D : Model3D {
int nDraw;
diff --git a/org.niclasundharald.engine/graphics/Texture.cs b/org.niclasundharald.engine/graphics/Texture.cs
new file mode 100644
index 0000000..a13511b
--- /dev/null
+++ b/org.niclasundharald.engine/graphics/Texture.cs
@@ -0,0 +1,30 @@
+using System;
+using System.IO;
+
+using OpenTK;
+using OpenTK.Graphics.OpenGL;
+
+using ImageSharp;
+
+namespace org.niclasundharald.engine
+{
+ public class Texture
+ {
+ int tid;
+
+ public Texture(string filename)
+ {
+ init();
+ load(filename);
+ }
+
+ private void init(){
+ this.tid = GL.GenTexture();
+ }
+
+ private void load(string filename){
+
+ }
+
+ }
+}
diff --git a/org.niclasundharald.engine/graphics/primitives/Cube.cs b/org.niclasundharald.engine/graphics/primitives/Cube.cs
index 4c8ca97..754bc82 100644
--- a/org.niclasundharald.engine/graphics/primitives/Cube.cs
+++ b/org.niclasundharald.engine/graphics/primitives/Cube.cs
@@ -8,7 +8,8 @@ namespace org.niclasundharald.engine.graphics.primitives
{
public Cube(Vector3 position, float width)
{
- Transformation = Matrix4.CreateScale(width) * Matrix4.CreateTranslation( position );
+ Scale = Matrix4.CreateScale(width);
+ Position = position;
}
public override Model3D getModel3D()
@@ -63,8 +64,8 @@ namespace org.niclasundharald.engine.graphics.primitives
Model3D.setTriangle(vertexes, 4, e, a, d);
Model3D.setTriangle(vertexes, 5, d, h, e);
- Model3D.setTriangle(vertexes, 6, g, f, b);
- Model3D.setTriangle(vertexes, 7, b, c, g);
+ Model3D.setTriangle(vertexes, 6, b, f, g);
+ Model3D.setTriangle(vertexes, 7, g, c, b);
Model3D.setTriangle(vertexes, 8, a, e, f);
Model3D.setTriangle(vertexes, 9, f, b, a);
diff --git a/org.niclasundharald.engine/org.niclasundharald.engine.csproj b/org.niclasundharald.engine/org.niclasundharald.engine.csproj
index 795c016..1882432 100644
--- a/org.niclasundharald.engine/org.niclasundharald.engine.csproj
+++ b/org.niclasundharald.engine/org.niclasundharald.engine.csproj
@@ -34,6 +34,15 @@
..\packages\OpenTK.GLControl.1.1.2349.61993\lib\NET40\OpenTK.GLControl.dll
+
+ contrib\ImageSharp.dll
+
+
+
+
+
+ ..\packages\System.Buffers.4.3.0\lib\netstandard1.1\System.Buffers.dll
+
@@ -51,6 +60,14 @@
+
+
+
+
+
+
+
+
@@ -60,6 +77,10 @@
+
+
+
+
\ No newline at end of file
diff --git a/org.niclasundharald.engine/packages.config b/org.niclasundharald.engine/packages.config
index 9667546..6cea577 100644
--- a/org.niclasundharald.engine/packages.config
+++ b/org.niclasundharald.engine/packages.config
@@ -2,4 +2,7 @@
+
+
+
\ No newline at end of file