Commits

Amin67v  committed 84e8548

minor fixes

  • Participants
  • Parent commits 2eb247c

Comments (0)

Files changed (5)

File DarkMotion/MainForm.cs

 			stateMachineViewInit();
 			stateEditPanelInit();
 			rebindAll();
+
 			initPreview();
 		}
 
 
 			scn = new Scene("testscene1");
 			eng.ActiveScene = scn;
-			Camera cam = new Camera();
+			Camera cam = new Camera(new Vec3(10,10,10),new Vec3(0,0,0));
 			eng.ActiveCamera = cam;
 			pnlPreview_Resize(null, null);
+			pnlPreview.Resize += pnlPreview_Resize;
 			Application.Idle += Application_Idle;
 			eng.Run();
 		}
 
 		void releasePreview()
 		{
-			scn.Dispose();
+			eng.ActiveCamera.Dispose();
+			eng.ActiveScene.Dispose();
 			eng.Dispose();
 			Core.Release();
 		}

File Examples/Program.cs

 
 			Scene scn = new Scene("test");
 			eng.ActiveScene = scn;
-			Camera cam = new Camera(new Vec4(0f, 1f, -5f, 1f), new Vec4(0f, 1f, 1f, 1f));
+			Camera cam = new Camera();
 
 			eng.ActiveCamera = cam;
 

File SharpHammer/Camera.cs

 
 namespace SharpHammer
 {
-	public class Camera
+	public class Camera : DisposableBase
 	{
-		internal cam _cam;
+		internal IntPtr _cam;
 
 		public Camera()
-			: this(new Vec3(0, 10, -10), new Vec3(0, 0, 0), (float)Math.PI * .3f)
-		{
-		}
+			: this(new Vec3(0, 10, -10), new Vec3(0, 0, 0))
+		{ }
+
+		public Camera(Vec3 pos, Vec3 target) :
+			this(pos, target, (float)Math.PI * .3f)
+		{ }
 
 		public Camera(Vec3 pos, Vec3 target, float fov)
 		{
-			_cam = new cam();
+			_cam = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(cam)));
+
 			Vec4 cpos = new Vec4(pos, 1);
 			Vec4 ctarget = new Vec4(target, 1);
-			NativeCalls.cam_init(ref _cam, ref cpos, ref ctarget, 0.1f, 1000f, fov);
+			NativeCalls.cam_init(_cam, ref cpos, ref ctarget, 0.1f, 1000f, fov);
 		}
 
+		protected override void OnDisposeUnmanaged()
+		{
+			Marshal.FreeHGlobal(_cam);
+		}
 	}
 
 	[StructLayout(LayoutKind.Sequential)]

File SharpHammer/NativeCalls.cs

 		public static extern UInt32 scn_getactive();
 
 		[DllImport(_engineDll, CallingConvention = CallingConvention.Cdecl)]
-		public static extern void scn_setcam(ref cam cam);
+		public static extern void scn_setcam(IntPtr cam);
 		#endregion
 
 		#region camera
 		[DllImport(_engineDll, CallingConvention = CallingConvention.Cdecl)]
-		public static extern void cam_init(ref cam cam,
+		public static extern void cam_init(IntPtr cam,
 			[In] ref Vec4 pos, [In] ref Vec4 lookat, float fnear, float ffar, float fov);
 
 		[DllImport(_engineDll, CallingConvention = CallingConvention.Cdecl)]
-		public static extern void cam_update(ref cam cam);
+		public static extern void cam_update(IntPtr cam);
 
 		[DllImport(_engineDll, CallingConvention = CallingConvention.Cdecl)]
 		public static extern void cam_fps_update(IntPtr cfps, Int32 dx, Int32 dy, float dt);
 		public static extern void cam_fps_init(IntPtr cfps, ref Vec4 pos, ref Vec4 lookat,float fnear, float ffar, float fov);
 
 		[DllImport(_engineDll, CallingConvention = CallingConvention.Cdecl)]
-		public static extern void cam_set_viewsize(ref cam cam, float width, float height);
+		public static extern void cam_set_viewsize(IntPtr cam, float width, float height);
 		#endregion
 
 		#region input

File SharpHammer/engine.cs

 
 		public void SetViewSize(int w, int h)
 		{
-			NativeCalls.cam_set_viewsize(ref ActiveCamera._cam, (float)w, (float)h);
+			NativeCalls.cam_set_viewsize(ActiveCamera._cam, (float)w, (float)h);
 			NativeCalls.app_resize_window(IntPtr.Zero, (UInt32)w, (UInt32)h);
 		}
 
 			set
 			{
 				_activeCamera = value;
-				NativeCalls.scn_setcam(ref _activeCamera._cam);
+				NativeCalls.scn_setcam(_activeCamera._cam);
 			}
 		}