WIP
parent
03d36fc7e2
commit
504e703f34
|
@ -36,19 +36,26 @@ namespace bnhdemo
|
|||
primaryCamera = new GLCamera();
|
||||
Engine.SceneWindows[0].PrimaryViewport.SceneOrientation = primaryCamera;
|
||||
|
||||
primaryCamera.Position = new Vector3(-10,-10,256);
|
||||
primaryCamera.lookAt(new Vector3(125,125,128));
|
||||
primaryCamera.Position = new Vector3(600,550,200);
|
||||
primaryCamera.lookAt(new Vector3(125,125,192));
|
||||
primaryCamera.Top = new Vector3(0,0,1);
|
||||
primaryCamera.setFoV(MathHelper.PiOver2);
|
||||
primaryCamera.setFoV(MathHelper.PiOver4);
|
||||
|
||||
ballisticViewport = new Viewport();
|
||||
ballisticViewport.Left = 0.7f;
|
||||
ballisticViewport.Width = 0.3f;
|
||||
ballisticViewport.Width = 0.2f;
|
||||
ballisticViewport.Height = 0.2f;
|
||||
ballisticViewport.Top = 0.0f;
|
||||
ballisticViewport.Height = 0.3f;
|
||||
ballisticViewport.Right = 1.0f;
|
||||
|
||||
ballisticViewport.Visible = false;
|
||||
ballisticViewport.BackgroundColor = new Vector3(0.3f,0.3f,0.9f);
|
||||
ballisticViewport.Scene = Engine.SceneWindows[0].Scene;
|
||||
|
||||
trackingCamera = new GLCamera();
|
||||
trackingCamera.Top = Vector3.UnitZ;
|
||||
trackingCamera.setFoV(MathHelper.PiOver4);
|
||||
|
||||
ballisticViewport.SceneOrientation = trackingCamera;
|
||||
|
||||
Engine.SceneWindows[0].addViewport(ballisticViewport);
|
||||
|
||||
|
@ -63,40 +70,67 @@ namespace bnhdemo
|
|||
SceneWindow sw = Engine.createSceneWindow();
|
||||
sw.Visible = true;
|
||||
sw.Scene = new Scene(Engine.SceneWindows[0].Scene);
|
||||
GLCamera cam = new GLCamera();
|
||||
|
||||
cam.Position = new Vector3(800,800,384);
|
||||
cam.View = new Vector3(-1,-1,-1);
|
||||
cam.Top = Vector3.UnitZ;
|
||||
sw.PrimaryViewport.SceneOrientation = trackingCamera;
|
||||
|
||||
CameraRotator cr = new CameraRotator(cam);
|
||||
break;
|
||||
|
||||
sw.PrimaryViewport.SceneOrientation = cam;
|
||||
ballisticViewport.SceneOrientation = cam;
|
||||
|
||||
trackingCamera = cam;
|
||||
break;
|
||||
case 'p':
|
||||
Engine.UpdatesPaused = !Engine.UpdatesPaused;
|
||||
break;
|
||||
|
||||
case ' ':
|
||||
Console.WriteLine("Fire Ballistic...");
|
||||
BallisticActor ba = new BallisticActor(0);
|
||||
ba.Position.Value = map.ground(new Vector2(10,10));
|
||||
ba.Velocity.Value = new Vector3(1,1,1).Normalized();
|
||||
ba.Velocity.Value *= 100.0f;
|
||||
ba.Velocity.Value *= 98.0f;
|
||||
ba.fire();
|
||||
|
||||
trackedActor = ba;
|
||||
ballisticViewport.Visible = true;
|
||||
break;
|
||||
|
||||
break;
|
||||
case ',':
|
||||
if (Engine.TimeScale > 0){
|
||||
Engine.TimeScale -= 0.05f;
|
||||
}
|
||||
break;
|
||||
case '.':
|
||||
if (Engine.TimeScale < 5.0f){
|
||||
Engine.TimeScale += 0.05f;
|
||||
}
|
||||
break;
|
||||
case 'w':
|
||||
primaryCamera.Position += new Vector3( primaryCamera.View.Xy.Normalized());
|
||||
break;
|
||||
case 's':
|
||||
primaryCamera.Position -= new Vector3( primaryCamera.View.Xy.Normalized());
|
||||
break;
|
||||
case 'a':
|
||||
primaryCamera.Position -= Vector3.Cross( new Vector3( primaryCamera.View.Xy.Normalized()), Vector3.UnitZ);
|
||||
break;
|
||||
case 'd':
|
||||
primaryCamera.Position += Vector3.Cross( new Vector3( primaryCamera.View.Xy.Normalized()), Vector3.UnitZ);
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
Engine.AfterUpdate += delegate {
|
||||
if ((trackedActor != null)&&(trackingCamera != null)){
|
||||
if (trackedActor.IsActive){
|
||||
trackingCamera.lookAt(trackedActor.Position.Value);
|
||||
Vector3 nv = trackedActor.Velocity.BufferedValue.Normalized();
|
||||
trackingCamera.Position = trackedActor.Position.BufferedValue - (nv * 5) + (Vector3.UnitZ * 2);;
|
||||
trackingCamera.View = trackedActor.Velocity.BufferedValue;
|
||||
|
||||
primaryCamera.lookAt(trackedActor.Position.BufferedValue);
|
||||
|
||||
if ((trackedActor.Velocity.BufferedValue.Z > 0) && (trackedActor.Velocity.Value.Z < 0)){
|
||||
Engine.UpdatesPaused = true;
|
||||
}
|
||||
} else {
|
||||
trackedActor = null;
|
||||
ballisticViewport.Visible = false;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -10,6 +10,7 @@ namespace org.budnhead.core
|
|||
{
|
||||
public class Actor : WorldObject
|
||||
{
|
||||
private static List<Actor> newActors = new List<Actor>();
|
||||
internal static List<Actor> activeActors = new List<Actor>();
|
||||
private static List<Actor> finishedActors = new List<Actor>();
|
||||
|
||||
|
@ -19,11 +20,25 @@ namespace org.budnhead.core
|
|||
a.update(elapsed);
|
||||
}
|
||||
|
||||
// Remove finished Actors
|
||||
foreach (Actor a in finishedActors.ToArray()){
|
||||
activeActors.Remove(a);
|
||||
lock(newActors)
|
||||
{
|
||||
// Add new Actors
|
||||
foreach (Actor a in newActors.ToArray())
|
||||
{
|
||||
activeActors.Add(a);
|
||||
}
|
||||
newActors.Clear();
|
||||
}
|
||||
|
||||
lock (finishedActors)
|
||||
{
|
||||
// Remove finished Actors
|
||||
foreach (Actor a in finishedActors.ToArray())
|
||||
{
|
||||
activeActors.Remove(a);
|
||||
}
|
||||
finishedActors.Clear();
|
||||
}
|
||||
finishedActors.Clear();
|
||||
}
|
||||
|
||||
private int id;
|
||||
|
@ -32,15 +47,20 @@ namespace org.budnhead.core
|
|||
{
|
||||
Console.WriteLine("New Actor: {0} / {1}",id,this);
|
||||
this.id = id;
|
||||
activeActors.Add(this);
|
||||
|
||||
lock (activeActors)
|
||||
{
|
||||
newActors.Add(this);
|
||||
}
|
||||
//_player = new nhPlayer();
|
||||
//activePlayers.Add(_player);
|
||||
|
||||
}
|
||||
|
||||
public void destroy(){
|
||||
finishedActors.Add(this);
|
||||
lock (finishedActors)
|
||||
{
|
||||
finishedActors.Add(this);
|
||||
}
|
||||
//_player.deletePlayer();
|
||||
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ namespace org.budnhead.core
|
|||
this.Model3D = ResourceLibrary.getResource<LoadedModel>("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.colors[n] = new Vector4(1.0f,0.4f + (0.5f * this.Model3D.vertexes[n].Z / -4.0f),0,1.0f);
|
||||
}
|
||||
|
||||
this.Model3D.rebind();
|
||||
|
@ -39,7 +39,7 @@ namespace org.budnhead.core
|
|||
Velocity.Value += (Physics.Gravitation * timespan);
|
||||
Position.Value += Velocity.Value * timespan;
|
||||
|
||||
setHeading( Velocity.Value, Physics.Gravitation);
|
||||
setHeading( Velocity.Value, -Physics.Gravitation);
|
||||
|
||||
try
|
||||
{
|
||||
|
|
|
@ -14,6 +14,7 @@ namespace org.budnhead
|
|||
{
|
||||
static List<IBufferedValue> bufferedValues = new List<IBufferedValue>();
|
||||
static public void cycle(){
|
||||
Console.WriteLine(String.Format("cycling buffered values [{0}]",bufferedValues.Count));
|
||||
foreach (IBufferedValue bvi in bufferedValues){
|
||||
bvi.buffer();
|
||||
}
|
||||
|
@ -22,12 +23,12 @@ namespace org.budnhead
|
|||
T value,bufferedValue;
|
||||
|
||||
public BufferedValueInstance(){
|
||||
bufferedValues.Add(this);
|
||||
BufferedValueInstance<object>.bufferedValues.Add(this);
|
||||
}
|
||||
|
||||
public BufferedValueInstance(T initialValue){
|
||||
Value = initialValue;
|
||||
bufferedValues.Add(this);
|
||||
BufferedValueInstance<object>.bufferedValues.Add(this);
|
||||
}
|
||||
|
||||
public T Value {
|
||||
|
@ -40,7 +41,7 @@ namespace org.budnhead
|
|||
}
|
||||
|
||||
public void Dispose(){
|
||||
bufferedValues.Remove(this);
|
||||
BufferedValueInstance<object>.bufferedValues.Remove(this);
|
||||
}
|
||||
|
||||
public void buffer(){
|
||||
|
|
|
@ -41,6 +41,9 @@ namespace org.budnhead.core
|
|||
private static Object syncGraphicsStartup = new object();
|
||||
|
||||
private static float targetUpdatePeriod = 100;
|
||||
private static bool updatesPaused;
|
||||
|
||||
public static float TimeScale { get; set; } = 1.0f;
|
||||
|
||||
public static SceneWindow[] SceneWindows {
|
||||
get { lock (sceneWindows) { return sceneWindows.ToArray(); } }
|
||||
|
@ -60,6 +63,11 @@ namespace org.budnhead.core
|
|||
get { lock(engineLock) { return !Engine.exiting; } }
|
||||
}
|
||||
|
||||
public static bool UpdatesPaused {
|
||||
get { return updatesPaused; }
|
||||
set { updatesPaused = value; }
|
||||
}
|
||||
|
||||
public static void Shutdown(){
|
||||
lock (engineLock){
|
||||
exiting = true;
|
||||
|
@ -158,7 +166,9 @@ namespace org.budnhead.core
|
|||
long ticks = Stopwatch.GetTimestamp();
|
||||
elapsed = tickTimeSpan * (ticks - lastWorldUpdateTick);
|
||||
|
||||
updateWorld(elapsed);
|
||||
if (!updatesPaused){
|
||||
updateWorld(elapsed * TimeScale);
|
||||
}
|
||||
|
||||
update_needs = tickTimeSpanMS * (Stopwatch.GetTimestamp() - ticks);
|
||||
|
||||
|
|
|
@ -55,15 +55,19 @@ void main()
|
|||
norm = normalize( ( mObjectCameraIT * vec4( iv_normal , 1 ) ).xyz );
|
||||
vec3 camray = (mObjectCamera * vec4( iv_position , 1 )).xyz;
|
||||
vec3 ncamray = normalize( camray );
|
||||
|
||||
float cosTheta = abs( clamp(dot( norm , ncamray ), -1, 1) );
|
||||
float distance = length(camray);
|
||||
float idist = 25000 / distance;
|
||||
float sight = clamp( idist * idist * idist, 0.1, 1.0);
|
||||
float idistance = clamp( 10000 / (distance), 0, 1);
|
||||
|
||||
shading = clamp(0.3 + (cosTheta * 0.7), 0.1, 0.9) * sight;
|
||||
|
||||
/*
|
||||
float cosTheta = abs( clamp(dot( norm , ncamray ), -1, 1) );
|
||||
|
||||
shading = clamp(0.3 + (cosTheta * 0.7), 0, 1) * sight;
|
||||
color = clamp( vec4( iv_color.xyz, fading ) * iv_col2, 0, 1);
|
||||
coord = camray;
|
||||
*/
|
||||
shading = 1.0;
|
||||
color = iv_color;
|
||||
coord = ncamray;
|
||||
}
|
||||
|
||||
";
|
||||
|
@ -81,13 +85,15 @@ out vec4 _color;
|
|||
|
||||
void main()
|
||||
{
|
||||
float cosTheta = dot( -coord, norm );
|
||||
float cosTheta = dot( coord, norm );
|
||||
|
||||
if (cosTheta >= 0){
|
||||
if (cosTheta < 0){
|
||||
discard;
|
||||
};
|
||||
|
||||
_color = vec4( color.xyz * shading, color.w );
|
||||
float shade = 0.2 + (0.8 * cosTheta);
|
||||
|
||||
_color = clamp( vec4( color.xyz * shade, color.w ), 0, 1);
|
||||
//_color = vec4( (vec3( 1,1,1 ) + norm)/2 , 1 );
|
||||
}
|
||||
|
||||
|
|
|
@ -52,7 +52,7 @@ namespace org.budnhead.graphics
|
|||
_mProjection = Matrix4.CreatePerspectiveFieldOfView(
|
||||
fov,
|
||||
aspect,
|
||||
5.0f,
|
||||
1.0f,
|
||||
50000.0f
|
||||
);
|
||||
}
|
||||
|
|
|
@ -104,9 +104,9 @@ namespace org.budnhead.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 );
|
||||
}
|
||||
|
||||
this.vertexes = vertexes.ToArray();
|
||||
|
|
|
@ -63,7 +63,7 @@ namespace org.budnhead.graphics {
|
|||
0,
|
||||
0);
|
||||
|
||||
GL.BindBuffer(BufferTarget.ArrayBuffer, cbo);
|
||||
GL.BindBuffer(BufferTarget.ArrayBuffer, cbo2);
|
||||
GL.VertexAttribPointer(3,
|
||||
4,
|
||||
VertexAttribPointerType.Float,
|
||||
|
@ -82,7 +82,7 @@ namespace org.budnhead.graphics {
|
|||
|
||||
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.colors2.Fill(new Vector4(1.0f,1.0f,1.0f,1.0f));
|
||||
|
||||
this.nTriangles = nTriangles;
|
||||
rebind();
|
||||
|
@ -103,7 +103,7 @@ namespace org.budnhead.graphics {
|
|||
}
|
||||
if (this.colors2 == null){
|
||||
this.colors2 = new Vector4[nTriangles * 3];
|
||||
this.colors2.Fill(new Vector4(0.0f,2.0f,0.0f,1.0f));
|
||||
this.colors2.Fill(new Vector4(0.0f,0.0f,0.0f,1.0f));
|
||||
}
|
||||
rebind();
|
||||
}
|
||||
|
|
|
@ -53,7 +53,7 @@ namespace org.budnhead.graphics
|
|||
}
|
||||
|
||||
public void draw(Viewport viewport,Matrix4 baseMatrix,WorldObject wo){
|
||||
Matrix4 objectMatrix = wo.Transformation * baseMatrix;
|
||||
Matrix4 objectMatrix = wo.BufferedTransformation * baseMatrix;
|
||||
|
||||
//Console.WriteLine("draw(,{0}",wo);
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@ namespace org.budnhead.graphics
|
|||
List<Viewport> viewports = new List<Viewport>();
|
||||
|
||||
internal SceneWindow()
|
||||
:base(600, 600,
|
||||
:base((DisplayDevice.Default.Width >> 4) * 14, (DisplayDevice.Default.Height>>4) * 14 ,
|
||||
GraphicsMode.Default,
|
||||
"nhEngine",
|
||||
GameWindowFlags.Default,
|
||||
|
@ -33,7 +33,13 @@ namespace org.budnhead.graphics
|
|||
Engine.sceneWindows.Add(this);
|
||||
}
|
||||
|
||||
GL.ClearColor(0.0f,0.3f,0.7f,1.0f);
|
||||
GL.ClearColor(0.1f,0.3f,0.6f,1.0f);
|
||||
GL.Enable(EnableCap.DepthTest);
|
||||
GL.Enable(EnableCap.Normalize);
|
||||
GL.Enable(EnableCap.ScissorTest);
|
||||
GL.Enable(EnableCap.AlphaTest);
|
||||
GL.Enable(EnableCap.Blend);
|
||||
GL.BlendFunc(BlendingFactorSrc.SrcAlpha,BlendingFactorDest.OneMinusSrcAlpha);
|
||||
}
|
||||
|
||||
public Viewport PrimaryViewport {
|
||||
|
@ -46,12 +52,6 @@ namespace org.budnhead.graphics
|
|||
|
||||
public override void Dispose()
|
||||
{
|
||||
lock (Engine.sceneWindows){
|
||||
Engine.sceneWindows.Remove(this);
|
||||
if (Engine.sceneWindows.Count == 0){
|
||||
Engine.Shutdown();
|
||||
}
|
||||
}
|
||||
base.Dispose();
|
||||
}
|
||||
|
||||
|
@ -90,8 +90,19 @@ namespace org.budnhead.graphics
|
|||
|
||||
protected override void OnClosed(EventArgs e)
|
||||
{
|
||||
base.OnClosed(e);
|
||||
Dispose();
|
||||
lock (Engine.sceneWindows)
|
||||
{
|
||||
Engine.sceneWindows.Remove(this);
|
||||
|
||||
if (Engine.sceneWindows.Count == 0)
|
||||
{
|
||||
Engine.Shutdown();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnClosing(System.ComponentModel.CancelEventArgs e)
|
||||
{
|
||||
}
|
||||
|
||||
public void paint(){
|
||||
|
@ -108,7 +119,7 @@ namespace org.budnhead.graphics
|
|||
public void paintViewports(){
|
||||
Engine.ConsumerEnter();
|
||||
|
||||
GL.Clear(ClearBufferMask.ColorBufferBit);
|
||||
//GL.Clear(ClearBufferMask.ColorBufferBit);
|
||||
|
||||
foreach (Viewport viewport in this.viewports){
|
||||
viewport.paint();
|
||||
|
|
|
@ -98,7 +98,8 @@ namespace org.budnhead.graphics
|
|||
GL.BindAttribLocation(this.id, 0, "iv_position");
|
||||
GL.BindAttribLocation(this.id, 1, "iv_color");
|
||||
GL.BindAttribLocation(this.id, 2, "iv_normal");
|
||||
GL.BindAttribLocation(this.id, 3, "iv_uv");
|
||||
GL.BindAttribLocation(this.id, 3, "iv_col2");
|
||||
GL.BindAttribLocation(this.id, 4, "iv_uv");
|
||||
|
||||
GL.LinkProgram(this.id);
|
||||
Console.WriteLine("Shader Program Result: {0}", GL.GetProgramInfoLog(this.id));
|
||||
|
|
|
@ -20,6 +20,20 @@ namespace org.budnhead.graphics
|
|||
public float Width { get; set; }
|
||||
public float Height { get; set; }
|
||||
|
||||
public float Right {
|
||||
get { return this.Left + this.Width; }
|
||||
set { this.Left = value - this.Width; }
|
||||
}
|
||||
|
||||
public float Bottom {
|
||||
get { return this.Top + this.Height; }
|
||||
set { this.Top = value - this.Height; }
|
||||
}
|
||||
|
||||
public bool Visible { get; set; }
|
||||
|
||||
public Vector3 BackgroundColor { get; set; } = new Vector3(0.3f,0.3f,0.3f);
|
||||
|
||||
public Viewport()
|
||||
{
|
||||
sceneOrientation = new GLSceneOrientation();
|
||||
|
@ -27,6 +41,7 @@ namespace org.budnhead.graphics
|
|||
Top = 0.0f;
|
||||
Width = 1.0f;
|
||||
Height = 1.0f;
|
||||
Visible = true;
|
||||
}
|
||||
|
||||
internal SceneWindow Parent { get; set; }
|
||||
|
@ -42,22 +57,28 @@ namespace org.budnhead.graphics
|
|||
}
|
||||
|
||||
public void paint(){
|
||||
Console.WriteLine("Viewport.paint()");
|
||||
if (!Visible)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (Parent != null){
|
||||
Rectangle cr = Parent.ClientRectangle;
|
||||
Rectangle vpr = new Rectangle(
|
||||
(int)(cr.Left + (cr.Width * Left)),
|
||||
(int)(cr.Top + (cr.Height * Top)),
|
||||
(int)(cr.Top + (cr.Height * (1.0f - Top - Height))),
|
||||
(int)(cr.Width * Width),
|
||||
(int)(cr.Height * Height)
|
||||
);
|
||||
|
||||
Console.WriteLine(String.Format("Viewport: {0}",vpr));
|
||||
Console.WriteLine(String.Format("viewPort: {0} {1}",cr,vpr));
|
||||
|
||||
GL.Viewport( vpr );
|
||||
sceneOrientation.setViewport( cr.Width, cr.Height );
|
||||
GL.Scissor( vpr.X, vpr.Y, vpr.Width, vpr.Height );
|
||||
sceneOrientation.setViewport( vpr.Width, vpr.Height );
|
||||
|
||||
GL.Clear(ClearBufferMask.DepthBufferBit);
|
||||
GL.ClearColor( BackgroundColor.X, BackgroundColor.Y, BackgroundColor.Z, 0.1f);
|
||||
GL.Clear(ClearBufferMask.DepthBufferBit | ClearBufferMask.ColorBufferBit);
|
||||
|
||||
if (Scene != null){
|
||||
Scene.draw(this);
|
||||
|
|
Loading…
Reference in New Issue