Merge commit 'cfd74c9dde56307bdb090bb17b512935057ff5a0' into audio
commit
42b2a3640c
|
@ -82,6 +82,7 @@ namespace nhengine
|
|||
|
||||
DumpObject dobj = new DumpObject();
|
||||
dobj.Model3D = ModelManager.instance.loadModel("alfa147",0.0254f);
|
||||
Vector3 v3 = map.ground(new Vector2(24,24));
|
||||
dobj.Position = v3;
|
||||
|
||||
glWindow.Scene.RootObject.addChild( dobj );
|
||||
|
|
|
@ -27,12 +27,13 @@ namespace nhengine
|
|||
private Cube cube,
|
||||
c1, c2, c3;
|
||||
|
||||
private string titleMsg = "";
|
||||
|
||||
GLCamera sceneCamera;
|
||||
GLScene scene;
|
||||
|
||||
public OpenGLWindow()
|
||||
:base(800, 600,
|
||||
:base(600, 600,
|
||||
GraphicsMode.Default,
|
||||
"nhEngine",
|
||||
GameWindowFlags.Default,
|
||||
|
@ -59,14 +60,11 @@ namespace nhengine
|
|||
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,128.0f);
|
||||
lookAt = new Vector3(0,0,SquaredMap.maxHeight);
|
||||
lookDistance = 2048;
|
||||
arcUpDown = MathHelper.PiOver6;
|
||||
arcLeftRight = MathHelper.PiOver4;
|
||||
|
||||
// sceneCamera.Position = new Vector3(1000,-1000,1000);
|
||||
// sceneCamera.View = new Vector3(0f,1.0f,0.0f);
|
||||
sceneCamera.Top = new Vector3(0,0,1);
|
||||
sceneCamera.setFoV(MathHelper.PiOver4);
|
||||
|
||||
setupCamera();
|
||||
|
@ -95,7 +93,7 @@ namespace nhengine
|
|||
|
||||
SwapBuffers();
|
||||
|
||||
Title = string.Format("{0:F}/s {1:F}/s [{2:F}s]", RenderFrequency,UpdateFrequency,UpdatePeriod);
|
||||
Title = string.Format("{0:F}/s {1:F}/s [{2:F}s] {3}", RenderFrequency,UpdateFrequency,UpdatePeriod,titleMsg);
|
||||
}
|
||||
|
||||
protected override void OnUpdateFrame(FrameEventArgs e)
|
||||
|
@ -129,6 +127,7 @@ namespace nhengine
|
|||
Point delta = new Point(e.X - mouseCapturePosition.X, e.Y - mouseCapturePosition.Y);
|
||||
onMouseCapturedMove(delta);
|
||||
mouseCapturePosition = e.Position;
|
||||
} else {
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -141,6 +140,7 @@ namespace nhengine
|
|||
{
|
||||
switch (e.Button){
|
||||
case OpenTK.Input.MouseButton.Left:
|
||||
markMouse(e.X,e.Y);
|
||||
break;
|
||||
case OpenTK.Input.MouseButton.Right:
|
||||
captureMouse();
|
||||
|
@ -148,6 +148,23 @@ namespace nhengine
|
|||
}
|
||||
}
|
||||
|
||||
protected void markMouse(float x,float y){
|
||||
try {
|
||||
Vector3 P = sceneCamera.Position;
|
||||
Vector3 V = sceneCamera.pickRay(x,y);
|
||||
|
||||
Vector3 isect = SquaredMap.activeMap.intersect(P,V);
|
||||
Vector2 tile = SquaredMap.activeMap.toTile(isect.Xy);
|
||||
|
||||
SquaredMap.activeMap.highlight(tile);
|
||||
|
||||
|
||||
} catch (OutOfWorldException owe){
|
||||
Console.WriteLine(owe);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected override void OnMouseUp(OpenTK.Input.MouseButtonEventArgs e)
|
||||
{
|
||||
releaseMouse();
|
||||
|
@ -156,7 +173,7 @@ namespace nhengine
|
|||
protected override void OnMouseWheel(OpenTK.Input.MouseWheelEventArgs e)
|
||||
{
|
||||
lookDistance *= 1.0f - ( e.DeltaPrecise / 16 );
|
||||
MathHelper.Clamp( lookDistance, 512, 8192 );
|
||||
lookDistance = MathHelper.Clamp( lookDistance, 4, 8192 );
|
||||
setupCamera();
|
||||
}
|
||||
|
||||
|
@ -186,16 +203,34 @@ namespace nhengine
|
|||
walk(e.Shift ? -50.0f : -5.0f);
|
||||
break;
|
||||
case OpenTK.Input.Key.A:
|
||||
strafe(e.Shift ? -50.0f : -5.0f);
|
||||
strafe(e.Shift ? 50.0f : 5.0f);
|
||||
break;
|
||||
case OpenTK.Input.Key.D:
|
||||
strafe(e.Shift ? 50.0f : 5.0f);
|
||||
strafe(e.Shift ? -50.0f : -5.0f);
|
||||
break;
|
||||
|
||||
case OpenTK.Input.Key.Space:
|
||||
fireBallistic();
|
||||
break;
|
||||
|
||||
case OpenTK.Input.Key.Number1:
|
||||
lookAt = new Vector3(0,0,SquaredMap.maxHeight);
|
||||
arcLeftRight = 0;
|
||||
arcUpDown = MathHelper.PiOver2;
|
||||
setupCamera();
|
||||
break;
|
||||
case OpenTK.Input.Key.Number2:
|
||||
lookAt = new Vector3(0,0,SquaredMap.maxHeight);
|
||||
arcLeftRight = MathHelper.PiOver2;
|
||||
arcUpDown = MathHelper.PiOver2;
|
||||
setupCamera();
|
||||
break;
|
||||
case OpenTK.Input.Key.Number3:
|
||||
lookAt = new Vector3(0,0,SquaredMap.maxHeight);
|
||||
sceneCamera.View = new Vector3(1,1,-1);
|
||||
sceneCamera.Top = new Vector3(0,0,1);
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -205,7 +240,7 @@ namespace nhengine
|
|||
ba.fire();
|
||||
|
||||
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 = new Vector3(0,1,1);// + (Matrix4.CreateRotationZ(arcLeftRight) * Vector4.UnitY).Xyz;
|
||||
ba.Velocity.Normalize();
|
||||
ba.Velocity *= 50;
|
||||
}
|
||||
|
@ -214,7 +249,7 @@ namespace nhengine
|
|||
public void rotateUpDown(float arc)
|
||||
{
|
||||
arcUpDown += arc;
|
||||
arcUpDown = MathHelper.Clamp(arcUpDown,MathHelper.Pi / 8,MathHelper.PiOver2-0.00001f);
|
||||
arcUpDown = MathHelper.Clamp(arcUpDown,MathHelper.Pi / 16,MathHelper.PiOver2);
|
||||
setupCamera();
|
||||
}
|
||||
public void rotateLeftRight(float arc)
|
||||
|
@ -239,12 +274,17 @@ namespace nhengine
|
|||
}
|
||||
|
||||
private void setupCamera(){
|
||||
Vector3 view = (Matrix4.CreateRotationZ(arcLeftRight) * Matrix4.CreateRotationX(arcUpDown) * Vector4.UnitY).Xyz;
|
||||
Matrix4 mr = (Matrix4.CreateRotationZ(arcLeftRight) * Matrix4.CreateRotationX(arcUpDown));
|
||||
Vector3 view = (mr * Vector4.UnitY).Xyz;
|
||||
Vector3 top = (mr * Vector4.UnitZ).Xyz;
|
||||
|
||||
view.Normalize();
|
||||
top.Normalize();
|
||||
|
||||
Vector3 pos = lookAt - (view * lookDistance);
|
||||
|
||||
sceneCamera.View = view;
|
||||
sceneCamera.Top = top;
|
||||
sceneCamera.Position = pos;
|
||||
}
|
||||
|
||||
|
|
|
@ -2,70 +2,70 @@
|
|||
# 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
|
||||
v 0.000000 -4.000000 -0.250000
|
||||
v 0.000000 -2.000000 -0.250000
|
||||
v 0.048773 -4.000000 -0.245196
|
||||
v 0.048773 -2.000000 -0.245196
|
||||
v 0.095671 -4.000000 -0.230970
|
||||
v 0.095671 -2.000000 -0.230970
|
||||
v 0.138893 -4.000000 -0.207867
|
||||
v 0.138893 -2.000000 -0.207867
|
||||
v 0.176777 -4.000000 -0.176777
|
||||
v 0.176777 -2.000000 -0.176777
|
||||
v 0.207867 -4.000000 -0.138893
|
||||
v 0.207867 -2.000000 -0.138893
|
||||
v 0.230970 -4.000000 -0.095671
|
||||
v 0.230970 -2.000000 -0.095671
|
||||
v 0.245196 -4.000000 -0.048773
|
||||
v 0.245196 -2.000000 -0.048773
|
||||
v 0.250000 -4.000000 -0.000000
|
||||
v 0.250000 -2.000000 -0.000000
|
||||
v 0.245196 -4.000000 0.048773
|
||||
v 0.245196 -2.000000 0.048773
|
||||
v 0.230970 -4.000000 0.095671
|
||||
v 0.230970 -2.000000 0.095671
|
||||
v 0.207867 -4.000000 0.138893
|
||||
v 0.207867 -2.000000 0.138893
|
||||
v 0.176777 -4.000000 0.176777
|
||||
v 0.176777 -2.000000 0.176777
|
||||
v 0.138893 -4.000000 0.207867
|
||||
v 0.138893 -2.000000 0.207867
|
||||
v 0.095671 -4.000000 0.230970
|
||||
v 0.095671 -2.000000 0.230970
|
||||
v 0.048773 -4.000000 0.245196
|
||||
v 0.048773 -2.000000 0.245196
|
||||
v -0.000000 -4.000000 0.250000
|
||||
v -0.000000 -2.000000 0.250000
|
||||
v -0.048773 -4.000000 0.245196
|
||||
v -0.048773 -2.000000 0.245196
|
||||
v -0.095671 -4.000000 0.230970
|
||||
v -0.095671 -2.000000 0.230970
|
||||
v -0.138893 -4.000000 0.207867
|
||||
v -0.138893 -2.000000 0.207867
|
||||
v -0.176777 -4.000000 0.176777
|
||||
v -0.176777 -2.000000 0.176777
|
||||
v -0.207868 -4.000000 0.138892
|
||||
v -0.207868 -2.000000 0.138892
|
||||
v -0.230970 -4.000000 0.095671
|
||||
v -0.230970 -2.000000 0.095671
|
||||
v -0.245196 -4.000000 0.048772
|
||||
v -0.245196 -2.000000 0.048772
|
||||
v -0.250000 -4.000000 -0.000000
|
||||
v -0.250000 -2.000000 -0.000000
|
||||
v -0.245196 -4.000000 -0.048773
|
||||
v -0.245196 -2.000000 -0.048773
|
||||
v -0.230970 -4.000000 -0.095671
|
||||
v -0.230970 -2.000000 -0.095671
|
||||
v -0.207867 -4.000000 -0.138893
|
||||
v -0.207867 -2.000000 -0.138893
|
||||
v -0.176776 -4.000000 -0.176777
|
||||
v -0.176776 -2.000000 -0.176777
|
||||
v -0.138892 -4.000000 -0.207868
|
||||
v -0.138892 -2.000000 -0.207868
|
||||
v -0.095671 -4.000000 -0.230970
|
||||
v -0.095671 -2.000000 -0.230970
|
||||
v -0.048772 -4.000000 -0.245196
|
||||
v -0.048772 -2.000000 -0.245196
|
||||
vn 0.0980 0.0000 -0.9952
|
||||
vn 0.2903 0.0000 -0.9569
|
||||
vn 0.4714 0.0000 -0.8819
|
||||
|
@ -96,7 +96,7 @@ 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.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
|
||||
|
@ -137,39 +137,39 @@ 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
|
||||
v -0.000000 -2.060606 -0.250000
|
||||
v 0.048773 -2.060606 -0.245196
|
||||
v 0.095671 -2.060606 -0.230970
|
||||
v 0.138893 -2.060606 -0.207867
|
||||
v 0.176777 -2.060606 -0.176777
|
||||
v 0.207867 -2.060606 -0.138892
|
||||
v 0.230970 -2.060606 -0.095671
|
||||
v 0.245196 -2.060606 -0.048773
|
||||
v 0.250000 -2.060606 0.000000
|
||||
v -0.000000 -0.060606 0.000000
|
||||
v 0.245196 -2.060606 0.048773
|
||||
v 0.230970 -2.060606 0.095671
|
||||
v 0.207867 -2.060606 0.138893
|
||||
v 0.176777 -2.060606 0.176777
|
||||
v 0.138893 -2.060606 0.207867
|
||||
v 0.095671 -2.060606 0.230970
|
||||
v 0.048772 -2.060606 0.245196
|
||||
v -0.000000 -2.060606 0.250000
|
||||
v -0.048773 -2.060606 0.245196
|
||||
v -0.095671 -2.060606 0.230970
|
||||
v -0.138893 -2.060606 0.207867
|
||||
v -0.176777 -2.060606 0.176777
|
||||
v -0.207868 -2.060606 0.138892
|
||||
v -0.230970 -2.060606 0.095671
|
||||
v -0.245196 -2.060606 0.048772
|
||||
v -0.250000 -2.060606 -0.000000
|
||||
v -0.245196 -2.060606 -0.048773
|
||||
v -0.230970 -2.060606 -0.095671
|
||||
v -0.207867 -2.060606 -0.138893
|
||||
v -0.176776 -2.060606 -0.176777
|
||||
v -0.138892 -2.060606 -0.207868
|
||||
v -0.095671 -2.060606 -0.230970
|
||||
v -0.048772 -2.060606 -0.245196
|
||||
vn 0.0973 0.1234 -0.9876
|
||||
vn 0.2881 0.1234 -0.9496
|
||||
vn 0.4678 0.1234 -0.8752
|
||||
|
@ -202,7 +202,7 @@ 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
|
||||
vn 0.0000 -1.0000 -0.0000
|
||||
usemtl None
|
||||
s off
|
||||
f 65//35 74//35 66//35
|
||||
|
|
|
@ -107,6 +107,10 @@
|
|||
<Project>{3E812F66-D5F3-4599-8360-97F355B6CC1B}</Project>
|
||||
<Name>org.niclasundharald.engine</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\org.hwo.contracts\org.hwo.contracts.csproj">
|
||||
<Project>{56733EC1-7D97-48D0-AA4C-98EA624A5A21}</Project>
|
||||
<Name>org.hwo.contracts</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="sounds\" />
|
||||
|
|
10
nhengine.sln
10
nhengine.sln
|
@ -5,9 +5,9 @@ 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}"
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "nhengine.Audio", "..\nhengine.Audio\nhengine.Audio\nhengine.Audio.csproj", "{DEFC64FA-45BC-4DA2-A884-66AFA99D34B4}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ImageSharp", "ImageSharp\ImageSharp.csproj", "{4D1A7C04-2C4E-4C74-AD81-FE0DCA9C6DF0}"
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "org.hwo.contracts", "org.hwo.contracts\org.hwo.contracts.csproj", "{56733EC1-7D97-48D0-AA4C-98EA624A5A21}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "org.hwo.contracts", "org.hwo.contracts\org.hwo.contracts.csproj", "{56733EC1-7D97-48D0-AA4C-98EA624A5A21}"
|
||||
EndProject
|
||||
|
@ -19,12 +19,18 @@ Global
|
|||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
Debug|x86 = Debug|x86
|
||||
Release|x86 = Release|x86
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{42BCFEF7-3F24-469A-BD46-E0C9C2C20D21}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{42BCFEF7-3F24-469A-BD46-E0C9C2C20D21}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{42BCFEF7-3F24-469A-BD46-E0C9C2C20D21}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{42BCFEF7-3F24-469A-BD46-E0C9C2C20D21}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{42BCFEF7-3F24-469A-BD46-E0C9C2C20D21}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{42BCFEF7-3F24-469A-BD46-E0C9C2C20D21}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{42BCFEF7-3F24-469A-BD46-E0C9C2C20D21}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{42BCFEF7-3F24-469A-BD46-E0C9C2C20D21}.Release|x86.Build.0 = Release|Any CPU
|
||||
{3E812F66-D5F3-4599-8360-97F355B6CC1B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{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
|
||||
|
|
|
@ -0,0 +1,78 @@
|
|||
using System;
|
||||
using System.Threading;
|
||||
|
||||
namespace org.hwo.contracts
|
||||
{
|
||||
public delegate void operDelegate();
|
||||
public delegate T assignDelegate<T>();
|
||||
|
||||
public class Conditional<T>
|
||||
{
|
||||
T valSuccess,
|
||||
valFail;
|
||||
|
||||
bool success;
|
||||
|
||||
public Conditional(T valSuccess,T valFail)
|
||||
{
|
||||
this.valSuccess = valSuccess;
|
||||
this.valFail = valFail;
|
||||
this.success = true;
|
||||
}
|
||||
|
||||
public Conditional<T> requires(bool condition){
|
||||
if (success){
|
||||
success = condition;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public Conditional<T> sets<ST>(ref ST target,ST value){
|
||||
if (success){
|
||||
target = value;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public Conditional<T> does(operDelegate operation){
|
||||
if (this.success){
|
||||
operation();
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public Conditional<T> assigns<AT>(ref AT target,assignDelegate<AT> assigner){
|
||||
if (success){
|
||||
target = assigner();
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public bool isSuccess(){
|
||||
return this.success;
|
||||
}
|
||||
|
||||
public Conditional<T> throws<E>(string message) where E: Exception{
|
||||
if (!success){
|
||||
E ex = (E)typeof(E).GetConstructor(new Type[]{typeof(string)}).Invoke(new object[]{message});
|
||||
throw ex;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public Conditional<T> throws<E>() where E: Exception{
|
||||
if (!success){
|
||||
E ex = (E)typeof(E).GetConstructor(new Type[]{}).Invoke(new object[]{});
|
||||
throw ex;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class BooleanConditional : Conditional<bool>{
|
||||
public BooleanConditional()
|
||||
:base(true,false){
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
// Information about this assembly is defined by the following attributes.
|
||||
// Change them to the values specific to your project.
|
||||
|
||||
[assembly: AssemblyTitle("org.hwo.contracts")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("")]
|
||||
[assembly: AssemblyCopyright("${AuthorCopyright}")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
|
||||
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
|
||||
// and "{Major}.{Minor}.{Build}.*" will update just the revision.
|
||||
|
||||
[assembly: AssemblyVersion("1.0.*")]
|
||||
|
||||
// The following attributes are used to specify the signing key for the assembly,
|
||||
// if desired. See the Mono documentation for more information about signing.
|
||||
|
||||
//[assembly: AssemblyDelaySign(false)]
|
||||
//[assembly: AssemblyKeyFile("")]
|
|
@ -0,0 +1,37 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{56733EC1-7D97-48D0-AA4C-98EA624A5A21}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<RootNamespace>org.hwo.contracts</RootNamespace>
|
||||
<AssemblyName>org.hwo.contracts</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug</OutputPath>
|
||||
<DefineConstants>DEBUG;</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<ConsolePause>false</ConsolePause>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release</OutputPath>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<ConsolePause>false</ConsolePause>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Conditional.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
|
@ -56,6 +56,9 @@ namespace org.niclasundharald.engine
|
|||
public float Weight { get; set; }
|
||||
|
||||
public virtual void update(float timespan){
|
||||
if (soundPlaying()){
|
||||
syncSoundPosition();
|
||||
}
|
||||
}
|
||||
|
||||
public void setHeading(Vector3 heading,Vector3 top){
|
||||
|
@ -118,16 +121,14 @@ namespace org.niclasundharald.engine
|
|||
_player.play(aBuffers[sound], gain, loop);
|
||||
}
|
||||
|
||||
public void setPlayerPosition(Vector3 positon, Vector3 velocity)
|
||||
private void syncSoundPosition()
|
||||
{
|
||||
_player.setPosition(positon);
|
||||
_player.setVelocity(velocity);
|
||||
_player.setPosition(this.Position);
|
||||
_player.setVelocity(this.Velocity);
|
||||
}
|
||||
|
||||
public void updateSoundState()
|
||||
{
|
||||
isPlaying = _player.state();
|
||||
|
||||
public Boolean soundPlaying(){
|
||||
return _player.state();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
using System;
|
||||
|
||||
|
||||
namespace org.niclasundharald.engine
|
||||
{
|
||||
public static class ArrayHelper
|
||||
{
|
||||
public static void Fill<T>(this T[] array,T value){
|
||||
for (int n=0;n<array.Length;n++)
|
||||
array[n] = value;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -10,54 +10,58 @@ namespace org.niclasundharald.engine
|
|||
{
|
||||
public class BallisticActor : Actor
|
||||
{
|
||||
BallisticActorStates actorState;
|
||||
|
||||
public BallisticActor(int id)
|
||||
:base(id)
|
||||
{
|
||||
this.actorState = BallisticActorStates.FLYING;
|
||||
this.Model3D = ModelManager.instance.findModel("ballistisch");
|
||||
|
||||
for (int n=0;n < this.Model3D.vertexes.Length;n++){
|
||||
this.Model3D.colors[n] = new Vector4(1.0f,0.2f + (0.5f * this.Model3D.vertexes[n].Z / -4.0f),0,1.0f);
|
||||
}
|
||||
|
||||
this.Model3D.rebind();
|
||||
|
||||
setBuffers("HowFire", "HowHit");
|
||||
setDistanceAttenuation(2, 200, 800);
|
||||
}
|
||||
|
||||
byte hit = 0;
|
||||
|
||||
|
||||
public override void update(float timespan)
|
||||
{
|
||||
base.update(timespan);
|
||||
|
||||
|
||||
switch (actorState){
|
||||
case BallisticActorStates.FLYING:
|
||||
Velocity += (Physics.Gravitation * timespan);
|
||||
Position += Velocity * timespan;
|
||||
Scale = Matrix4.CreateScale(3.0f);
|
||||
|
||||
setHeading( Velocity, Physics.Gravitation);
|
||||
|
||||
Console.WriteLine("BallisticActor update: {0} / {1}",Position,Velocity);
|
||||
|
||||
updateSoundState();
|
||||
Console.WriteLine("Playing:" + isPlaying);
|
||||
|
||||
try{
|
||||
try
|
||||
{
|
||||
Vector3 ground = SquaredMap.activeMap.ground(Position.Xy);
|
||||
|
||||
if (Position.Z <= ground.Z){
|
||||
|
||||
if(hit != 1)
|
||||
{
|
||||
Console.WriteLine("BallisticActor hit ground!");
|
||||
actorState = BallisticActorStates.HIT;
|
||||
playSound("HowHit");
|
||||
updateSoundState();
|
||||
hit = 1;
|
||||
}
|
||||
} catch (OutOfWorldException owe){
|
||||
Console.WriteLine("BallisticActor disappeared at {0} [{1}]",Position,Velocity);
|
||||
actorState = BallisticActorStates.DISAPPEARED;
|
||||
}
|
||||
break;
|
||||
|
||||
if(!isPlaying)
|
||||
{
|
||||
case BallisticActorStates.HIT:
|
||||
case BallisticActorStates.DISAPPEARED:
|
||||
Model3D = null;
|
||||
|
||||
if (!soundPlaying()){
|
||||
destroy();
|
||||
}
|
||||
}
|
||||
} catch (OutOfWorldException e){
|
||||
|
||||
if(!isPlaying)
|
||||
destroy();
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
using System;
|
||||
namespace org.niclasundharald.engine
|
||||
{
|
||||
public enum BallisticActorStates
|
||||
{
|
||||
FLYING,
|
||||
HIT,
|
||||
DISAPPEARED
|
||||
}
|
||||
}
|
|
@ -0,0 +1,98 @@
|
|||
using System;
|
||||
using org.hwo.contracts;
|
||||
|
||||
using OpenTK;
|
||||
|
||||
namespace org.niclasundharald.engine
|
||||
{
|
||||
public static class Geometry
|
||||
{
|
||||
|
||||
/**
|
||||
* Intersect Plane and Ray:
|
||||
*
|
||||
* A + i * (B-A) + j * (C-A) = P + n * V
|
||||
* A-P + i * (B-A) + j * (C-A) = n * V
|
||||
* i * (B-A) + j * (C-A) - n * V = P-A
|
||||
*
|
||||
* =>
|
||||
*
|
||||
* -n * V + i * (B-A) + j * (C-A) = P-A
|
||||
*
|
||||
* out p : receives the cooefficients of the solved equation (n,i,j)
|
||||
*
|
||||
**/
|
||||
public static bool intersectPlainCoeff(Vector3 P,Vector3 V,Vector3 A,Vector3 B,Vector3 C,out Vector3 p){
|
||||
Vector3 BA,CA,PA;
|
||||
Vector3 coeff = new Vector3();
|
||||
p = coeff;
|
||||
|
||||
BA = B-A;
|
||||
CA = C-A;
|
||||
PA = P-A;
|
||||
/*
|
||||
Console.WriteLine("Interesction:");
|
||||
Console.WriteLine("Ray: {0} + i * {1}",P,V);
|
||||
Console.WriteLine("A: {0}",A);
|
||||
Console.WriteLine("B: {0}",B);
|
||||
Console.WriteLine("C: {0}",C);
|
||||
*/
|
||||
return new BooleanConditional()
|
||||
.requires(Linear.Solve4x3(V,BA,CA,PA,out coeff))
|
||||
.does(delegate { coeff.X = -coeff.X;})
|
||||
.sets(ref p,coeff)
|
||||
.isSuccess();
|
||||
}
|
||||
|
||||
public static bool intersectPlain(Vector3 P,Vector3 V,Vector3 A,Vector3 B,Vector3 C,out Vector3 p){
|
||||
Vector3 coeff = new Vector3();
|
||||
p = new Vector3();
|
||||
|
||||
return new BooleanConditional()
|
||||
.requires(intersectPlainCoeff(P,V,A,B,C,out coeff))
|
||||
.assigns(ref p, delegate { return A + (coeff.Y * (B-A)) + (coeff.Z * (C-A)); })
|
||||
.isSuccess();
|
||||
}
|
||||
|
||||
public static bool intersectPlainForward(Vector3 P,Vector3 V,Vector3 A,Vector3 B,Vector3 C,out Vector3 p){
|
||||
Vector3 coeff = new Vector3();
|
||||
p = new Vector3();
|
||||
|
||||
return new BooleanConditional()
|
||||
.requires(intersectPlainCoeff(P,V,A,B,C,out coeff))
|
||||
.requires(coeff.X > 0)
|
||||
.assigns(ref p, delegate { return P + (coeff.X * V); })
|
||||
.isSuccess();
|
||||
}
|
||||
|
||||
public static bool intersectPlainRect(Vector3 P,Vector3 V,Vector3 A,Vector3 B,Vector3 C,out Vector3 p){
|
||||
Vector3 coeff = new Vector3();
|
||||
p = new Vector3();
|
||||
|
||||
return new BooleanConditional()
|
||||
.requires(intersectPlainCoeff(P,V,A,B,C,out coeff))
|
||||
.requires(coeff.Y >= 0)
|
||||
.requires(coeff.Z >= 0)
|
||||
.requires(coeff.Y <= 1)
|
||||
.requires(coeff.Z <= 1)
|
||||
.assigns(ref p, delegate { return P + (coeff.X * V); })
|
||||
.isSuccess();
|
||||
}
|
||||
|
||||
public static bool intersectTriangle(Vector3 P,Vector3 V,Vector3 A,Vector3 B,Vector3 C,out Vector3 p){
|
||||
Vector3 coeff = new Vector3();
|
||||
p = new Vector3();
|
||||
|
||||
return new BooleanConditional()
|
||||
.requires(intersectPlainCoeff(P,V,A,B,C,out coeff))
|
||||
.requires(coeff.Y >= 0)
|
||||
.requires(coeff.Z >= 0)
|
||||
.requires(coeff.Y <= 1)
|
||||
.requires(coeff.Z <= 1)
|
||||
.requires(coeff.Y + coeff.Z <= 1)
|
||||
.assigns(ref p, delegate { return A + (coeff.Y * (B-A)) + (coeff.Z * (C-A)); })
|
||||
.isSuccess();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,68 @@
|
|||
using System;
|
||||
using OpenTK;
|
||||
|
||||
namespace org.niclasundharald.engine
|
||||
{
|
||||
public static class Linear
|
||||
{
|
||||
static public bool Solve4x3(Vector3 X,Vector3 Y,Vector3 Z,Vector3 W,out Vector3 c)
|
||||
{
|
||||
Vector4[] rows = new Vector4[3];
|
||||
rows[0] = new Vector4(X.X,Y.X,Z.X,W.X);
|
||||
rows[1] = new Vector4(X.Y,Y.Y,Z.Y,W.Y);
|
||||
rows[2] = new Vector4(X.Z,Y.Z,Z.Z,W.Z);
|
||||
c = new Vector3();
|
||||
|
||||
/*
|
||||
Console.WriteLine("Solver Unsolved:");
|
||||
Console.WriteLine("X: {0}",rows[0]);
|
||||
Console.WriteLine("Y: {0}",rows[1]);
|
||||
Console.WriteLine("Z: {0}",rows[2]);
|
||||
*/
|
||||
|
||||
if (rows[0].Z == 0){
|
||||
Vector4 t = rows[0];
|
||||
rows[0] = rows[2];
|
||||
rows[2] = t;
|
||||
}
|
||||
if (rows[0].Z == 0){
|
||||
Vector4 t = rows[0];
|
||||
rows[0] = rows[1];
|
||||
rows[1] = t;
|
||||
}
|
||||
|
||||
if (rows[0].Z == 0){
|
||||
return false;
|
||||
} else {
|
||||
rows[1] -= rows[0] * (rows[1].Z / rows[0].Z);
|
||||
rows[2] -= rows[0] * (rows[2].Z / rows[0].Z);
|
||||
}
|
||||
|
||||
if (rows[1].Y == 0){
|
||||
Vector4 t = rows[1];
|
||||
rows[1] = rows[2];
|
||||
rows[2] = t;
|
||||
}
|
||||
|
||||
if (rows[1].Y == 0){
|
||||
return false;
|
||||
} else {
|
||||
rows[2] -= rows[1] * (rows[2].Y / rows[1].Y);
|
||||
}
|
||||
|
||||
rows[2] /= rows[2].X;
|
||||
|
||||
c.X = rows[2].W;
|
||||
c.Y = (rows[1].W - (rows[1].X * c.X)) / rows[1].Y;
|
||||
c.Z = (rows[0].W - (rows[0].X * c.X) - (rows[0].Y * c.Y)) / rows[0].Z;
|
||||
/*
|
||||
Console.WriteLine("Solver Solved:");
|
||||
Console.WriteLine("X: {0}",rows[0]);
|
||||
Console.WriteLine("Y: {0}",rows[1]);
|
||||
Console.WriteLine("Z: {0}",rows[2]);
|
||||
Console.WriteLine("P: {0}",c);
|
||||
*/
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -11,6 +11,7 @@ namespace org.niclasundharald.engine.graphics
|
|||
{
|
||||
float fov;
|
||||
float width, height;
|
||||
float aspect;
|
||||
|
||||
Vector3 vPosition,
|
||||
vView,
|
||||
|
@ -23,6 +24,7 @@ namespace org.niclasundharald.engine.graphics
|
|||
fov = MathHelper.PiOver2;
|
||||
width = 100;
|
||||
height = 100;
|
||||
aspect = 1;
|
||||
|
||||
vPosition = new Vector3(0,0,1000);
|
||||
vView = new Vector3(0,0,-1);
|
||||
|
@ -45,9 +47,11 @@ namespace org.niclasundharald.engine.graphics
|
|||
}
|
||||
|
||||
private void buildProjection(){
|
||||
aspect = width / height;
|
||||
|
||||
_mProjection = Matrix4.CreatePerspectiveFieldOfView(
|
||||
fov,
|
||||
width / height,
|
||||
aspect,
|
||||
1.0f,
|
||||
100000.0f
|
||||
);
|
||||
|
@ -90,6 +94,46 @@ namespace org.niclasundharald.engine.graphics
|
|||
_mCamera = mTranslation * mRotation;
|
||||
}
|
||||
|
||||
public Vector3 pickRay(float x,float y){
|
||||
float y_arc,x_arc;
|
||||
|
||||
x_arc = (( (2*x) ) - width) * aspect;
|
||||
y_arc = height - ( (2*y) );
|
||||
|
||||
x_arc /= width;
|
||||
y_arc /= height;
|
||||
|
||||
Vector4 ray = new Vector4(x_arc,y_arc,1,1);
|
||||
|
||||
Console.WriteLine("Pick Ray: {0}",ray);
|
||||
Matrix4 mpi = _mProjection.Inverted();
|
||||
mpi.Transpose();
|
||||
ray = mpi * ray;
|
||||
ray.Normalize();
|
||||
Console.WriteLine("Pick Ray (PROJ): {0}",ray);
|
||||
|
||||
// ray.Z = -1;
|
||||
// ray.W = 0;
|
||||
|
||||
//Console.WriteLine("Pick Ray (CAM): {0}",ray);
|
||||
Matrix4 mci = _mCamera.Inverted();
|
||||
mci.Transpose();
|
||||
ray = mci * ray;
|
||||
|
||||
Console.WriteLine("Pick Ray (CAM): {0}",ray);
|
||||
|
||||
//Console.WriteLine("Pick Ray Angles: x:{0} / y:{1}",x_arc,y_arc);
|
||||
//ray = Matrix4.CreateRotationY(-y_arc) * Matrix4.CreateRotationX( x_arc ) * ray;
|
||||
|
||||
Vector3 pr = ray.Xyz.Normalized();
|
||||
if (pr.Z > 0){
|
||||
pr *= -1;
|
||||
}
|
||||
|
||||
Console.WriteLine("Pick Ray (World): {0}",pr);
|
||||
Console.WriteLine("--------------------------------------------------");
|
||||
return pr;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -52,10 +52,11 @@ namespace org.niclasundharald.engine.graphics
|
|||
|
||||
private string defVertexShaderSource = @"#version 330
|
||||
|
||||
in vec3 iv_position;
|
||||
in vec4 iv_color;
|
||||
in vec3 iv_normal;
|
||||
in vec2 iv_uv;
|
||||
layout(location = 0) in vec3 iv_position;
|
||||
layout(location = 1) in vec4 iv_color;
|
||||
layout(location = 2) in vec3 iv_normal;
|
||||
layout(location = 3) in vec4 iv_col2;
|
||||
layout(location = 4) in vec2 iv_uv;
|
||||
|
||||
uniform mat4 mObject;
|
||||
uniform mat4 mCamera;
|
||||
|
@ -87,7 +88,7 @@ void main()
|
|||
float sight = clamp( idist * idist * idist, 0.1, 1.0);
|
||||
|
||||
shading = clamp(0.3 + (cosTheta * 0.7), 0.1, 0.9) * sight;
|
||||
color = clamp( vec4( iv_color.xyz, fading ), 0, 1);
|
||||
color = clamp( vec4( iv_color.xyz, fading ) * iv_col2, 0, 1);
|
||||
coord = camray;
|
||||
}
|
||||
|
||||
|
|
|
@ -27,7 +27,6 @@ namespace org.niclasundharald.engine.graphics
|
|||
}
|
||||
private void load(TextReader reader,float scale){
|
||||
List<Vector3> vertexes,normals;
|
||||
List<Vector4> colors;
|
||||
List<triangle> triangles;
|
||||
string line;
|
||||
|
||||
|
@ -36,7 +35,6 @@ namespace org.niclasundharald.engine.graphics
|
|||
|
||||
vertexes = new List<Vector3>();
|
||||
normals = new List<Vector3>();
|
||||
colors = new List<Vector4>();
|
||||
triangles = new List<triangle>();
|
||||
|
||||
vertexes.Add(new Vector3());
|
||||
|
@ -66,7 +64,7 @@ namespace org.niclasundharald.engine.graphics
|
|||
max[2] = max[2] < z ? z : max[2];
|
||||
break;
|
||||
case "vn":
|
||||
normals.Add( -(new Vector3(
|
||||
normals.Add( (new Vector3(
|
||||
float.Parse(fields[1],CultureInfo.InvariantCulture),
|
||||
float.Parse(fields[2],CultureInfo.InvariantCulture),
|
||||
float.Parse(fields[3],CultureInfo.InvariantCulture)
|
||||
|
@ -102,13 +100,15 @@ namespace org.niclasundharald.engine.graphics
|
|||
vertexes.Add( t.a );
|
||||
vertexes.Add( t.b );
|
||||
vertexes.Add( t.c );
|
||||
normals.Add( t.na );
|
||||
normals.Add( t.nb );
|
||||
normals.Add( t.nc );
|
||||
normals.Add( -t.na );
|
||||
normals.Add( -t.nb );
|
||||
normals.Add( -t.nc );
|
||||
}
|
||||
|
||||
// bind(vertexes.ToArray(),null,normals.ToArray());
|
||||
bind(vertexes.ToArray(),null,normals.ToArray());
|
||||
this.vertexes = vertexes.ToArray();
|
||||
this.normals = normals.ToArray();
|
||||
|
||||
bind();
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -3,6 +3,8 @@ using System;
|
|||
using OpenTK.Graphics.OpenGL;
|
||||
using OpenTK;
|
||||
|
||||
using org.niclasundharald.engine;
|
||||
|
||||
namespace org.niclasundharald.engine.graphics {
|
||||
|
||||
public class Model3D {
|
||||
|
@ -10,13 +12,17 @@ namespace org.niclasundharald.engine.graphics {
|
|||
protected int vao,
|
||||
vbo, // Vertex Buffer
|
||||
cbo, // Color Buffer
|
||||
cbo2, // Second Color Buffer
|
||||
nbo; // Normals Buffer
|
||||
|
||||
protected int nTriangles;
|
||||
|
||||
Vector3[] vertexes;
|
||||
Vector4[] colors;
|
||||
Vector3[] normals;
|
||||
public Vector3[] vertexes = null;
|
||||
public Vector4[] colors = null;
|
||||
public Vector4[] colors2 = null;
|
||||
public Vector3[] normals = null;
|
||||
|
||||
public Triangle[] triangles = new Triangle[0];
|
||||
|
||||
|
||||
protected Model3D(){
|
||||
|
@ -29,6 +35,7 @@ namespace org.niclasundharald.engine.graphics {
|
|||
protected void prepare(){
|
||||
vbo = GL.GenBuffer();
|
||||
cbo = GL.GenBuffer();
|
||||
cbo2 = GL.GenBuffer();
|
||||
nbo = GL.GenBuffer();
|
||||
|
||||
GL.BindVertexArray(vao);
|
||||
|
@ -57,68 +64,125 @@ namespace org.niclasundharald.engine.graphics {
|
|||
0,
|
||||
0);
|
||||
|
||||
GL.BindBuffer(BufferTarget.ArrayBuffer, cbo);
|
||||
GL.VertexAttribPointer(3,
|
||||
4,
|
||||
VertexAttribPointerType.Float,
|
||||
false,
|
||||
0,
|
||||
0);
|
||||
|
||||
GL.BindVertexArray(0);
|
||||
}
|
||||
|
||||
protected void rebind(){
|
||||
public void prepareBuffers(int nTriangles){
|
||||
this.vertexes = new Vector3[nTriangles * 3];
|
||||
this.normals = new Vector3[nTriangles * 3];
|
||||
this.colors = new Vector4[nTriangles * 3];
|
||||
this.colors2 = new Vector4[nTriangles * 3];
|
||||
|
||||
this.vertexes.Fill(new Vector3(0,0,0));
|
||||
this.colors.Fill(new Vector4(0.5f,0.5f,0.5f,1.0f));
|
||||
this.colors2.Fill(new Vector4(0.0f,2.0f,0.0f,1.0f));
|
||||
|
||||
this.nTriangles = nTriangles;
|
||||
rebind();
|
||||
}
|
||||
|
||||
protected void bind(Vector3[] vertexes){
|
||||
bind( vertexes, null, null, null );
|
||||
public void bind(){
|
||||
this.nTriangles = this.vertexes.Length / 3;
|
||||
if (this.vertexes == null){
|
||||
this.vertexes = new Vector3[nTriangles * 3];
|
||||
this.vertexes.Fill(new Vector3(0,0,0));
|
||||
}
|
||||
if (this.normals == null){
|
||||
this.normals = new Vector3[nTriangles * 3];
|
||||
}
|
||||
if (this.colors == null){
|
||||
this.colors = new Vector4[nTriangles * 3];
|
||||
this.colors.Fill(new Vector4(0.5f,0.5f,0.5f,1.0f));
|
||||
}
|
||||
if (this.colors2 == null){
|
||||
this.colors2 = new Vector4[nTriangles * 3];
|
||||
this.colors2.Fill(new Vector4(0.0f,2.0f,0.0f,1.0f));
|
||||
}
|
||||
rebind();
|
||||
}
|
||||
|
||||
protected void bind(Vector3[] vertexes,Vector4[] colors){
|
||||
bind( vertexes, colors, null, null );
|
||||
public void rebind(){
|
||||
bindVertexes();
|
||||
bindNormals();
|
||||
bindColors();
|
||||
bindColors2();
|
||||
}
|
||||
|
||||
protected void bind(Vector3[] vertexes,Vector4[] colors,Vector3[] normals){
|
||||
bind( vertexes, colors, normals, null );
|
||||
}
|
||||
|
||||
protected void bind(Vector3[] vertexes,Vector4[] colors,Vector3[] normals,Vector2[] uvs){
|
||||
/* float[] fv = new float[vertexes.Length * 3];
|
||||
|
||||
for (int n=0;n<vertexes.Length;n++){
|
||||
fv[(n * 3) ] = vertexes[n].X;
|
||||
fv[(n * 3) + 1] = vertexes[n].Y;
|
||||
fv[(n * 3) + 2] = vertexes[n].Z;
|
||||
}
|
||||
*/
|
||||
protected void bindVertexes(){
|
||||
GL.BindVertexArray(vao);
|
||||
|
||||
GL.BindBuffer(BufferTarget.ArrayBuffer, vbo);
|
||||
// GL.BufferData(BufferTarget.ArrayBuffer, 4 * fv.Length, fv, BufferUsageHint.StaticDraw);
|
||||
GL.BufferData(BufferTarget.ArrayBuffer, 12 * vertexes.Length, vertexes, BufferUsageHint.StaticDraw);
|
||||
|
||||
GL.EnableVertexAttribArray(0);
|
||||
|
||||
nTriangles = vertexes.Length / 3;
|
||||
if (this.triangles.Length != nTriangles){
|
||||
int nt = this.triangles.Length;
|
||||
|
||||
if (colors == null){
|
||||
colors = new Vector4[ vertexes.Length ];
|
||||
Array.Resize<Triangle>(ref this.triangles,nTriangles);
|
||||
|
||||
for (int n=0;n<colors.Length;n++){
|
||||
colors[n] = new Vector4(0.5f,0.9f,0.9f,1.0f);
|
||||
for (int n=nt;n<nTriangles;n++){
|
||||
this.triangles[n] = new Triangle(this,n);
|
||||
}
|
||||
}
|
||||
|
||||
GL.BindVertexArray(0);
|
||||
}
|
||||
|
||||
protected void bindNormals(){
|
||||
GL.BindVertexArray(vao);
|
||||
|
||||
GL.BindBuffer(BufferTarget.ArrayBuffer, nbo);
|
||||
GL.BufferData(BufferTarget.ArrayBuffer, 12 * normals.Length, normals, BufferUsageHint.StaticDraw);
|
||||
|
||||
GL.EnableVertexAttribArray(2);
|
||||
|
||||
GL.BindVertexArray(0);
|
||||
}
|
||||
|
||||
protected void bindColors(){
|
||||
GL.BindVertexArray(vao);
|
||||
|
||||
GL.BindBuffer(BufferTarget.ArrayBuffer, cbo);
|
||||
GL.BufferData(BufferTarget.ArrayBuffer, 16 * colors.Length, colors, BufferUsageHint.StaticDraw);
|
||||
|
||||
GL.EnableVertexAttribArray(1);
|
||||
|
||||
if (normals == null){
|
||||
normals = computeNormals(vertexes);
|
||||
GL.BindVertexArray(0);
|
||||
}
|
||||
/*
|
||||
float[] fn = v3aToArray(normals);
|
||||
*/
|
||||
GL.BindBuffer(BufferTarget.ArrayBuffer, nbo);
|
||||
GL.BufferData(BufferTarget.ArrayBuffer, 12 * normals.Length, normals, BufferUsageHint.StaticDraw);
|
||||
|
||||
GL.EnableVertexAttribArray(2);
|
||||
protected void bindColors2(){
|
||||
GL.BindVertexArray(vao);
|
||||
|
||||
GL.BindBuffer(BufferTarget.ArrayBuffer, cbo2);
|
||||
GL.BufferData(BufferTarget.ArrayBuffer, 16 * colors2.Length, colors2, BufferUsageHint.StaticDraw);
|
||||
|
||||
GL.EnableVertexAttribArray(3);
|
||||
|
||||
GL.BindVertexArray(0);
|
||||
}
|
||||
|
||||
protected void bind(Vector3[] vertexes,Vector4[] colors,Vector3[] normals,Vector2[] uvs){
|
||||
if (vertexes != null){
|
||||
this.vertexes = vertexes;
|
||||
}
|
||||
if (colors != null){
|
||||
this.colors = colors;
|
||||
}
|
||||
if (normals != null){
|
||||
this.normals = normals;
|
||||
}
|
||||
bindVertexes();
|
||||
bindColors();
|
||||
bindNormals();
|
||||
}
|
||||
|
||||
public virtual void draw(){
|
||||
|
@ -135,39 +199,23 @@ namespace org.niclasundharald.engine.graphics {
|
|||
vertexes[(3 * n)+2] = c;
|
||||
}
|
||||
|
||||
public static Vector3[] computeNormals(Vector3[] vertexes){
|
||||
Vector3[] normals = new Vector3[ vertexes.Length ];
|
||||
public void computeNormals(){
|
||||
if ((normals == null)||(normals.Length != vertexes.Length)){
|
||||
normals = new Vector3[vertexes.Length];
|
||||
}
|
||||
|
||||
for (int n=0;n<vertexes.Length-2;n+=3){
|
||||
Vector3 normal = Vector3.Cross( vertexes[n+1] - vertexes[n], vertexes[n+2] - vertexes[n] );
|
||||
Vector3 normal = Vector3.Cross( vertexes[n+2] - vertexes[n], vertexes[n+1] - vertexes[n] );
|
||||
normal.Normalize();
|
||||
/*
|
||||
Console.WriteLine("Normal Length: {0} Normal: {1}",normal.Length, normal);
|
||||
|
||||
if (normal.Length != 1){
|
||||
Console.WriteLine("!!! Broken Normal !!!");
|
||||
Console.WriteLine("Triangle: {0} {1} {2}",vertexes[n],vertexes[n+1],vertexes[n+2]);
|
||||
|
||||
}
|
||||
*/
|
||||
normals[(n) ] = normal;
|
||||
normals[(n) + 1] = normal;
|
||||
normals[(n) + 2] = normal;
|
||||
}
|
||||
|
||||
return normals;
|
||||
}
|
||||
|
||||
public static float[] v3aToArray(Vector3[] v3a){
|
||||
float[] a = new float[ v3a.Length * 3];
|
||||
|
||||
for (int n=0;n<v3a.Length;n++){
|
||||
a[ (3 * n) ] = v3a[n].X;
|
||||
a[ (3 * n) + 1] = v3a[n].Y;
|
||||
a[ (3 * n) + 2] = v3a[n].Z;
|
||||
}
|
||||
|
||||
return a;
|
||||
public Triangle[] Triangles {
|
||||
get { return this.triangles; }
|
||||
}
|
||||
|
||||
|
||||
|
@ -175,5 +223,89 @@ namespace org.niclasundharald.engine.graphics {
|
|||
return new LoadedModel(filename,scale);
|
||||
}
|
||||
|
||||
|
||||
public class Triangle{
|
||||
Model3D model;
|
||||
int n;
|
||||
|
||||
public Triangle(Model3D model,int n){
|
||||
this.model = model;
|
||||
this.n = n;
|
||||
}
|
||||
|
||||
public void vertexes(ref Vector3 a,ref Vector3 b,ref Vector3 c){
|
||||
a = model.vertexes[(3*n)];
|
||||
b = model.vertexes[(3*n)+1];
|
||||
c = model.vertexes[(3*n)+2];
|
||||
}
|
||||
public void vertexes(Vector3 a,Vector3 b,Vector3 c){
|
||||
model.vertexes[(3*n)] = a;
|
||||
model.vertexes[(3*n)+1] = b;
|
||||
model.vertexes[(3*n)+2] = c;
|
||||
}
|
||||
|
||||
public void vertex(int a,ref Vector3 v){
|
||||
v = model.vertexes[(3*n) + a];
|
||||
}
|
||||
public void normal(int a,ref Vector3 n){
|
||||
n = model.vertexes[(3*this.n) + a];
|
||||
}
|
||||
public void color(int a,ref Vector4 c){
|
||||
c = model.colors[(3*n)+a];
|
||||
}
|
||||
|
||||
public Vector3 VertexA {
|
||||
get { return model.vertexes[(3*n)]; }
|
||||
set { model.vertexes[(3*n)] = value; }
|
||||
}
|
||||
public Vector3 VertexB {
|
||||
get { return model.vertexes[(3*n)+1]; }
|
||||
set { model.vertexes[(3*n)+1] = value; }
|
||||
}
|
||||
public Vector3 VertexC {
|
||||
get { return model.vertexes[(3*n)+2]; }
|
||||
set { model.vertexes[(3*n)+2] = value; }
|
||||
}
|
||||
|
||||
public Vector4 ColorA {
|
||||
get { return model.colors[(3*n)]; }
|
||||
set { model.colors[(3*n)] = value; }
|
||||
}
|
||||
|
||||
public Vector4 ColorB {
|
||||
get { return model.colors[(3*n)+1]; }
|
||||
set { model.colors[(3*n)+1] = value; }
|
||||
}
|
||||
|
||||
public Vector4 ColorC {
|
||||
get { return model.colors[(3*n)+2]; }
|
||||
set { model.colors[(3*n)+2] = value; }
|
||||
}
|
||||
|
||||
public Vector4 Color2A {
|
||||
get { return model.colors2[(3*n)]; }
|
||||
set { model.colors2[(3*n)] = value; }
|
||||
}
|
||||
|
||||
public Vector4 Color2B {
|
||||
get { return model.colors2[(3*n)+1]; }
|
||||
set { model.colors2[(3*n)+1] = value; }
|
||||
}
|
||||
|
||||
public Vector4 Color2C {
|
||||
get { return model.colors2[(3*n)+2]; }
|
||||
set { model.colors2[(3*n)+2] = value; }
|
||||
}
|
||||
|
||||
public void updateNormals(){
|
||||
Vector3 normal = Vector3.Cross( model.vertexes[(3*n)+1] - model.vertexes[(3*n)], model.vertexes[(3*n)+2] - model.vertexes[(3*n)] );
|
||||
normal.Normalize();
|
||||
model.normals[(3*n)] = normal;
|
||||
model.normals[(3*n)+1] = normal;
|
||||
model.normals[(3*n)+2] = normal;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -2,13 +2,14 @@
|
|||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
|
||||
|
||||
using ImageSharp;
|
||||
using ImageSharp.PixelFormats;
|
||||
|
||||
using OpenTK.Graphics.OpenGL4;
|
||||
using OpenTK;
|
||||
|
||||
using org.hwo.contracts;
|
||||
|
||||
using org.niclasundharald.engine;
|
||||
|
||||
namespace org.niclasundharald.engine.graphics
|
||||
|
@ -17,13 +18,13 @@ namespace org.niclasundharald.engine.graphics
|
|||
{
|
||||
public static SquaredMap activeMap;
|
||||
|
||||
private static float edge = 5;
|
||||
private static float maxHeight = 128.0f;
|
||||
public static float edge = 5;
|
||||
public static readonly float maxHeight = 128.0f;
|
||||
|
||||
private int width,
|
||||
height;
|
||||
|
||||
private float[] heightMap;
|
||||
public Vector3[] corners;
|
||||
|
||||
private MapModel3D model;
|
||||
|
||||
|
@ -34,11 +35,7 @@ namespace org.niclasundharald.engine.graphics
|
|||
this.width = width;
|
||||
this.height = height;
|
||||
|
||||
this.heightMap = new float[ (width + 1) * (height + 1) ];
|
||||
|
||||
generateHeightMap();
|
||||
|
||||
computeModel();
|
||||
generateBaseMap();
|
||||
}
|
||||
|
||||
public override Model3D getModel3D()
|
||||
|
@ -53,209 +50,278 @@ namespace org.niclasundharald.engine.graphics
|
|||
this.width = heightMap.Width-1;
|
||||
this.height = heightMap.Height-1;
|
||||
|
||||
this.heightMap = new float[ (width + 1) * (height + 1) ];
|
||||
generateBaseMap();
|
||||
loadHeightMap( heightMap );
|
||||
|
||||
loadHeightMap(heightMap);
|
||||
|
||||
computeModel();
|
||||
model.rebind();
|
||||
}
|
||||
|
||||
|
||||
public void generateHeightMap(){
|
||||
Random rand = new Random();
|
||||
protected void generateBaseMap(){
|
||||
this.model = new MapModel3D(this,width,height);
|
||||
|
||||
this.corners = new Vector3[8];
|
||||
this.corners[0] = new Vector3();
|
||||
this.corners[1] = new Vector3(width * edge,0,0);
|
||||
this.corners[2] = new Vector3(width * edge,height * edge,0);
|
||||
this.corners[3] = new Vector3(0,height * edge,0);
|
||||
this.corners[4] = new Vector3(0,0,maxHeight);
|
||||
this.corners[5] = new Vector3(width * edge,0,maxHeight);
|
||||
this.corners[6] = new Vector3(width * edge,height * edge,maxHeight);
|
||||
this.corners[7] = new Vector3(0,height * edge,maxHeight);
|
||||
|
||||
for (int y=0;y<height;y++){
|
||||
for (int x=0;x<width;x++){
|
||||
int bi = 4 * (x + (y * width));
|
||||
float cx = (edge * x) + (edge / 2);
|
||||
float cy = (edge * y) + (edge / 2);
|
||||
Vector3 a = new Vector3(),b = new Vector3(),c = new Vector3();
|
||||
|
||||
a.X = (edge * (x+1));
|
||||
a.Y = (edge * y);
|
||||
b.X = (edge * x);
|
||||
b.Y = (edge * y);
|
||||
c.X = cx;
|
||||
c.Y = cy;
|
||||
model.triangles[bi].vertexes(c,b,a);
|
||||
|
||||
a.X = (edge * (x+1));
|
||||
a.Y = (edge * (y+1));
|
||||
b.X = (edge * (x+1));
|
||||
b.Y = (edge * y);
|
||||
c.X = cx;
|
||||
c.Y = cy;
|
||||
model.triangles[bi+1].vertexes(c,b,a);
|
||||
|
||||
a.X = (edge * x);
|
||||
a.Y = (edge * (y+1));
|
||||
b.X = (edge * (x+1));
|
||||
b.Y = (edge * (y+1));
|
||||
c.X = cx;
|
||||
c.Y = cy;
|
||||
model.triangles[bi+2].vertexes(c,b,a);
|
||||
|
||||
a.X = (edge * x);
|
||||
a.Y = (edge * y);
|
||||
b.X = (edge * x);
|
||||
b.Y = (edge * (y+1));
|
||||
c.X = cx;
|
||||
c.Y = cy;
|
||||
model.triangles[bi+3].vertexes(c,b,a);
|
||||
|
||||
for (int y = 0; y <= height; y++)
|
||||
{
|
||||
for (int x = 0; x <= width; x++)
|
||||
{
|
||||
float h = (float)rand.NextDouble();
|
||||
heightMap[x + (y * width)] = (float)(maxHeight * (h * h));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void loadHeightMap(Image _heightMap){
|
||||
|
||||
Rgba32[] pixels = _heightMap.Pixels;
|
||||
|
||||
for (int y = 0; y <= height; y++)
|
||||
{
|
||||
for (int x = 0; x <= width; x++)
|
||||
{
|
||||
Rgba32 pixel = pixels[ x + (y * (width + 1))];
|
||||
float h = (pixel.R + pixel.G + pixel.B) * maxHeight / 768;
|
||||
heightMap[x + (y * (width + 1))] = (float)(h);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void computeModel(){
|
||||
float left,
|
||||
right,
|
||||
bottom,
|
||||
top,
|
||||
vcenter,
|
||||
hcenter;
|
||||
|
||||
Vector3[] vertexes = new Vector3[ 12 * width * height ];
|
||||
|
||||
Console.WriteLine("Creating geometry");
|
||||
|
||||
for (int x = 0; x < width; x++)
|
||||
{
|
||||
for (int y = 0; y < height; y++)
|
||||
{
|
||||
int i = x + ((width + 1) * y);
|
||||
int j = x + ((width + 1) * (y + 1));
|
||||
|
||||
for (int x = 0; x < width; x++)
|
||||
{
|
||||
Rgba32[] pixel = new Rgba32[4];
|
||||
float[] h = new float[4];
|
||||
h[0] = heightMap[i];
|
||||
h[1] = heightMap[i+1];
|
||||
h[2] = heightMap[j];
|
||||
h[3] = heightMap[j+1];
|
||||
float ah = 0;
|
||||
|
||||
float ah = (h[0] + h[1] + h[2] + h[3]) / 4.0f;
|
||||
pixel[0] = pixels[ x + ((y+0) * (width + 1)) + 0 ];
|
||||
pixel[1] = pixels[ x + ((y+0) * (width + 1)) + 1 ];
|
||||
pixel[2] = pixels[ x + ((y+1) * (width + 1)) + 1 ];
|
||||
pixel[3] = pixels[ x + ((y+1) * (width + 1)) + 0 ];
|
||||
|
||||
left = edge * x;
|
||||
right = edge * (x + 1);
|
||||
bottom = edge * y;
|
||||
top = edge * (y + 1);
|
||||
vcenter = (top + bottom) / 2.0f;
|
||||
hcenter = (left + right) / 2.0f;
|
||||
for (int n=0;n<4;n++){
|
||||
h[n] = (pixel[n].R + pixel[n].G + pixel[n].B) * maxHeight / 768;
|
||||
ah += h[n]/4;
|
||||
}
|
||||
|
||||
int b = 4 * (x + (width * y));
|
||||
int bi = 12 * (x + (y * width));
|
||||
|
||||
model.vertexes[ bi++ ].Z = ah;
|
||||
model.vertexes[ bi++ ].Z = h[0];
|
||||
model.vertexes[ bi++ ].Z = h[1];
|
||||
model.vertexes[ bi++ ].Z = ah;
|
||||
model.vertexes[ bi++ ].Z = h[1];
|
||||
model.vertexes[ bi++ ].Z = h[2];
|
||||
model.vertexes[ bi++ ].Z = ah;
|
||||
model.vertexes[ bi++ ].Z = h[2];
|
||||
model.vertexes[ bi++ ].Z = h[3];
|
||||
model.vertexes[ bi++ ].Z = ah;
|
||||
model.vertexes[ bi++ ].Z = h[3];
|
||||
model.vertexes[ bi++ ].Z = h[0];
|
||||
|
||||
Model3D.setTriangle(
|
||||
vertexes,
|
||||
b,
|
||||
new Vector3(left, top, h[2]),
|
||||
new Vector3(right, top, h[3]),
|
||||
new Vector3(hcenter,vcenter,ah)
|
||||
);
|
||||
Model3D.setTriangle(
|
||||
vertexes,
|
||||
b + 1,
|
||||
new Vector3(right, top, h[3]),
|
||||
new Vector3(right, bottom, h[1]),
|
||||
new Vector3(hcenter, vcenter, ah)
|
||||
);
|
||||
Model3D.setTriangle(
|
||||
vertexes,
|
||||
b + 2,
|
||||
new Vector3(right, bottom, h[1]),
|
||||
new Vector3(left, bottom, h[0]),
|
||||
new Vector3(hcenter, vcenter, ah)
|
||||
);
|
||||
Model3D.setTriangle(
|
||||
vertexes,
|
||||
b + 3,
|
||||
new Vector3(left, bottom, h[0]),
|
||||
new Vector3(left, top, h[2]),
|
||||
new Vector3(hcenter, vcenter, ah)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
this.model = new MapModel3D( vertexes );
|
||||
model.computeNormals();
|
||||
model.colorMap();
|
||||
}
|
||||
|
||||
private int indHeightMap(int x,int y){
|
||||
return x + ((width + 1) * y);
|
||||
|
||||
private int tileIndex(int x,int y){
|
||||
return (x + (width * y)) * 4;
|
||||
}
|
||||
|
||||
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];
|
||||
int i1 = tileIndex((int)xy.X,(int)xy.Y);
|
||||
|
||||
h /= 4;
|
||||
for (int n=0;n<4;n++){
|
||||
Vector3 A,B,C,P,V;
|
||||
Vector3 p = new Vector3();
|
||||
|
||||
Vector3 v3 = new Vector3(_xy.X,_xy.Y,h);
|
||||
Console.WriteLine("Grounding: {0}",v3);
|
||||
A = model.triangles[i1+n].VertexA;
|
||||
B = model.triangles[i1+n].VertexB;
|
||||
C = model.triangles[i1+n].VertexC;
|
||||
|
||||
return v3;
|
||||
P = new Vector3(_xy);
|
||||
V = Vector3.UnitZ;
|
||||
|
||||
if (Geometry.intersectTriangle(P,V,A,B,C,out p)){
|
||||
Console.WriteLine("Grounded to: {0}",p);
|
||||
return p;
|
||||
} else {
|
||||
Console.WriteLine("No Ground at triangle {0}",n);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
throw new OutOfWorldException();
|
||||
}
|
||||
|
||||
public Vector2 toTileBorderless(Vector2 world){
|
||||
Vector2 tile = world / edge;
|
||||
return tile;
|
||||
}
|
||||
|
||||
public Vector2 toTile(Vector2 world){
|
||||
Vector2 tile = new Vector2();
|
||||
|
||||
new BooleanConditional()
|
||||
.does(delegate { tile = world / edge; })
|
||||
.requires(tile.X >= 0)
|
||||
.requires(tile.Y >= 0)
|
||||
.requires(tile.X < width)
|
||||
.requires(tile.Y < height)
|
||||
.throws<OutOfWorldException>();
|
||||
|
||||
return tile;
|
||||
}
|
||||
|
||||
public Vector2 intersectTile(Vector3 P,Vector3 V){
|
||||
return toTile( intersect(P,V).Xy );
|
||||
}
|
||||
|
||||
public Vector3 intersect(Vector3 P,Vector3 V){
|
||||
Vector3
|
||||
A = new Vector3(), // Lower plane intersection
|
||||
B = new Vector3(); // Upper plane intersection
|
||||
|
||||
Console.WriteLine("P: {0} V: {1}",P,V);
|
||||
|
||||
if (!Geometry.intersectPlain(P,V,corners[0],corners[1],corners[3],out A)){
|
||||
throw new OutOfWorldException();
|
||||
}
|
||||
|
||||
if (!Geometry.intersectPlain(P,V,corners[4],corners[5],corners[7],out B)){
|
||||
throw new OutOfWorldException();
|
||||
}
|
||||
|
||||
Console.WriteLine("Lower Plane Intersection (LIN): {0}",A);
|
||||
A = P + ( V * ( -P.Z / V.Z) );
|
||||
Console.WriteLine("Lower Plane Intersection: {0}",A);
|
||||
|
||||
Console.WriteLine("Higher Plane Intersection (LIN): {0}",B);
|
||||
B = P + ( V * ( (SquaredMap.maxHeight-P.Z) / V.Z) );
|
||||
Console.WriteLine("Higher Plane Intersection: {0}",B);
|
||||
|
||||
Vector2 a,b,min,max;
|
||||
|
||||
a = toTileBorderless(A.Xy);
|
||||
b = toTileBorderless(B.Xy);
|
||||
|
||||
min = Vector2.ComponentMax(Vector2.ComponentMin(a,b)-new Vector2(1,1),new Vector2());
|
||||
max = Vector2.ComponentMin(Vector2.ComponentMax(a,b)+new Vector2(1,1),new Vector2(width,height));
|
||||
|
||||
Console.WriteLine("Checking Intersections: {0} -> {1}",min,max);
|
||||
|
||||
for (int nx = (int)min.X; nx < max.X; nx++){
|
||||
for (int ny = (int)min.Y; ny < max.Y; ny++){
|
||||
Vector3 isect = new Vector3();
|
||||
//Console.WriteLine("Check Intersection: {0}/{1}",nx,ny);
|
||||
|
||||
for (int n=0;n<4;n++){
|
||||
try {
|
||||
Model3D.Triangle t = model.triangles[tileIndex(nx,ny)];
|
||||
if (Geometry.intersectTriangle(
|
||||
P,
|
||||
V,
|
||||
t.VertexA,
|
||||
t.VertexB,
|
||||
t.VertexC,
|
||||
out isect
|
||||
)){
|
||||
return isect;
|
||||
}
|
||||
|
||||
} catch (OutOfWorldException owe){
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
throw new OutOfWorldException();
|
||||
}
|
||||
|
||||
public void highlight(Vector2 tile){
|
||||
new BooleanConditional()
|
||||
.requires(tile.X >= 0)
|
||||
.requires(tile.Y >= 0)
|
||||
.requires(tile.X < width)
|
||||
.requires(tile.Y < height)
|
||||
.does(delegate {
|
||||
|
||||
for (int n=0;n<4;n++){
|
||||
Model3D.Triangle t = model.triangles[tileIndex((int)tile.X,(int)tile.Y)+n];
|
||||
t.ColorA *= 2;
|
||||
t.ColorB *= 2;
|
||||
t.ColorC *= 2;
|
||||
}
|
||||
|
||||
model.rebind();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
class MapModel3D : Model3D {
|
||||
int nDraw;
|
||||
|
||||
public MapModel3D(Vector3[] vertexes){
|
||||
SquaredMap map;
|
||||
|
||||
Vector4[] colors = new Vector4[ vertexes.Length ];
|
||||
|
||||
for (int n=0; n< vertexes.Length; n++){
|
||||
|
||||
if (vertexes[n].Z >= 256 ){
|
||||
Console.WriteLine("Max. Height : {0}",vertexes[n].Z / 256);
|
||||
public MapModel3D(SquaredMap map,int width,int height){
|
||||
this.map = map;
|
||||
prepareBuffers(width * height * 4);
|
||||
colorMap();
|
||||
}
|
||||
|
||||
public void colorMap(){
|
||||
for (int n=0; n < vertexes.Length; n++){
|
||||
colors[n] = new Vector4(
|
||||
0.50f + (0.2f * vertexes[n].Z / 256),
|
||||
0.25f + (0.50f * vertexes[n].Z / 256),
|
||||
0.10f + (0.80f * vertexes[n].Z / 256),
|
||||
0.50f + (0.2f * vertexes[n].Z / SquaredMap.maxHeight),
|
||||
0.25f + (0.50f * vertexes[n].Z / SquaredMap.maxHeight),
|
||||
0.10f + (0.80f * vertexes[n].Z / SquaredMap.maxHeight),
|
||||
1.0f
|
||||
);
|
||||
}
|
||||
|
||||
Vector3[] normals = Model3D.computeNormals(vertexes);
|
||||
|
||||
Dictionary<Vector3,List<Vector3>> dNormals = new Dictionary<Vector3, List<Vector3>>();
|
||||
|
||||
foreach (Vector3 v in vertexes){
|
||||
if (!dNormals.ContainsKey(v)){
|
||||
dNormals.Add(v,new List<Vector3>());
|
||||
}
|
||||
}
|
||||
|
||||
for (int n=0;n<vertexes.Length;n++){
|
||||
dNormals[ vertexes[n] ].Add(normals[n]);
|
||||
}
|
||||
|
||||
foreach (Vector3 v in dNormals.Keys){
|
||||
Vector3 s = new Vector3();
|
||||
foreach (Vector3 n in dNormals[v]){
|
||||
s += n;
|
||||
}
|
||||
s /= dNormals[v].Count;
|
||||
dNormals[v].Clear();
|
||||
dNormals[v].Add(s);
|
||||
}
|
||||
|
||||
for (int n=0;n<vertexes.Length;n++){
|
||||
normals[n] = dNormals[ vertexes[n] ][0];
|
||||
}
|
||||
|
||||
bind(vertexes, colors, normals);
|
||||
}
|
||||
|
||||
public override void draw()
|
||||
{
|
||||
nDraw+= nTriangles >> 8;
|
||||
if (nDraw > nTriangles){
|
||||
nDraw = 0;
|
||||
}
|
||||
|
||||
nDraw = nTriangles;
|
||||
|
||||
GL.BindVertexArray(this.vao);
|
||||
GL.DrawArrays(PrimitiveType.Triangles, 0, nDraw * 3);
|
||||
GL.BindVertexArray(0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ namespace org.niclasundharald.engine.graphics.primitives
|
|||
|
||||
class CubeModel : Model3D {
|
||||
|
||||
public static Vector4[] colors = new Vector4[]{
|
||||
public static Vector4[] ccolors = new Vector4[]{
|
||||
new Vector4(1.0f,0.0f,0.0f,1.0f),
|
||||
new Vector4(1.0f,0.0f,0.0f,1.0f),
|
||||
new Vector4(1.0f,0.0f,0.0f,1.0f),
|
||||
|
@ -55,30 +55,30 @@ namespace org.niclasundharald.engine.graphics.primitives
|
|||
g = dx + dy + dz;
|
||||
h = - dx + dy + dz;
|
||||
|
||||
Vector3[] vertexes = new Vector3[36];
|
||||
prepareBuffers(12);
|
||||
|
||||
Model3D.setTriangle(vertexes, 0, a, b, c);
|
||||
Model3D.setTriangle(vertexes, 1, c, d, a);
|
||||
Model3D.setTriangle(vertexes, 2, f, e, h);
|
||||
Model3D.setTriangle(vertexes, 3, h, g, f);
|
||||
Model3D.setTriangle(vertexes, 0, c, b, a);
|
||||
Model3D.setTriangle(vertexes, 1, a, d, c);
|
||||
Model3D.setTriangle(vertexes, 2, h, e, f);
|
||||
Model3D.setTriangle(vertexes, 3, f, g, h);
|
||||
|
||||
Model3D.setTriangle(vertexes, 4, e, a, d);
|
||||
Model3D.setTriangle(vertexes, 5, d, h, e);
|
||||
Model3D.setTriangle(vertexes, 6, b, f, g);
|
||||
Model3D.setTriangle(vertexes, 7, g, c, b);
|
||||
Model3D.setTriangle(vertexes, 4, d, a, e);
|
||||
Model3D.setTriangle(vertexes, 5, e, h, d);
|
||||
Model3D.setTriangle(vertexes, 6, g, f, b);
|
||||
Model3D.setTriangle(vertexes, 7, b, c, g);
|
||||
|
||||
Model3D.setTriangle(vertexes, 8, a, e, f);
|
||||
Model3D.setTriangle(vertexes, 9, f, b, a);
|
||||
Model3D.setTriangle(vertexes, 10, g, h, d);
|
||||
Model3D.setTriangle(vertexes, 11, d, c, g);
|
||||
|
||||
Vector4[] colors = new Vector4[ vertexes.Length ];
|
||||
Model3D.setTriangle(vertexes, 8, f, e, a);
|
||||
Model3D.setTriangle(vertexes, 9, a, b, f);
|
||||
Model3D.setTriangle(vertexes, 10, d, h, g);
|
||||
Model3D.setTriangle(vertexes, 11, g, c, d);
|
||||
|
||||
for (int n=0;n<colors.Length;n++){
|
||||
colors[n] = CubeModel.colors[ n / 3 ];
|
||||
this.colors[n] = CubeModel.ccolors[ n / 3 ];
|
||||
}
|
||||
|
||||
bind( vertexes, colors );
|
||||
computeNormals();
|
||||
|
||||
rebind();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -72,6 +72,10 @@
|
|||
<Compile Include="audio\AudioDelegate.cs" />
|
||||
<Compile Include="audio\nhBuffers.cs" />
|
||||
<Compile Include="audio\nhListener.cs" />
|
||||
<Compile Include="ArrayHelper.cs" />
|
||||
<Compile Include="Geometry.cs" />
|
||||
<Compile Include="Linear.cs" />
|
||||
<Compile Include="BallisticActorStates.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="OpenTK.dll.config" />
|
||||
|
@ -159,5 +163,11 @@
|
|||
</ProjectReference>
|
||||
<Folder Include="audio\" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\org.hwo.contracts\org.hwo.contracts.csproj">
|
||||
<Project>{56733EC1-7D97-48D0-AA4C-98EA624A5A21}</Project>
|
||||
<Name>org.hwo.contracts</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
||||
|
|
Loading…
Reference in New Issue