Jump to content

CameraPick


Laurens
 Share

Recommended Posts

Maybe Tyler could tell you a bit on this, but the raycasting is more than bugged in my version of the headers. I haven't experimented with it in LE or C/C++, so I didn't know how to translate it correctly. Here is my source for it. @Tyler, feel free to fix it:

 

using System;

namespace Leadwerks
{
public class Pick
{
	public Core.TPick Structure { get; private set; }

	public Vector3 Position
	{
		get
		{
			return new Vector3(Structure.x, Structure.y, Structure.z);
		}
	}

	public Vector3 Normal
	{
		get
		{
			return new Vector3(Structure.nx, Structure.ny, Structure.nz);
		}
	}

	public Entity Entity
	{
		get
		{
			return new Entity(Structure.entity);
		}
	}

	public Surface Surface
	{
		get
		{
			return new Surface(Structure.surface);
		}
	}
}

public static class Raycasting
{
	public static bool PointVisible(Vector3 origin, Vector3 end, float radius, int collisionType)
	{
		return Convert.ToBoolean(Core.PointVisible(origin.ToFloatArray(), end.ToFloatArray(), radius, collisionType, IntPtr.Zero));
	}

	public static bool EntityVisible(Entity origin, Entity end, float radius, int collisionType)
	{
		return Convert.ToBoolean(Core.EntityVisible(origin.Pointer, end.Pointer, radius, collisionType, IntPtr.Zero));
	}

	public static bool LinePick(Pick pick, Vector3 origin, Vector3 end, float radius, int collisionType)
	{
		return Convert.ToBoolean(Core.LinePick(pick.Structure, origin.ToFloatArray(), end.ToFloatArray(), radius, collisionType, IntPtr.Zero));
	}

	public static bool EntityPick(Pick pick, Entity entity, float range, float radius, int collisionType)
	{
		return Convert.ToBoolean(Core.EntityPick(pick.Structure, entity.Pointer, range, radius, collisionType, IntPtr.Zero));
	}

	public static bool CameraPick(Pick pick, Camera camera, Vector3 position, float radius, int collisionType)
	{
		return Convert.ToBoolean(Core.CameraPick(pick.Structure, camera.Pointer, position.ToFloatArray(), radius, collisionType, IntPtr.Zero));
	}
}
}

  • Upvote 1
Link to comment
Share on other sites

Not sure what is going on with your Pick.Structure property there?

 

You need to use an attribute tag on your declaration of Pick:

 

I assume you have a using System.Runtime.InteropServices; at the top of your file, which you should always have if dealing with stuff between the managed <-> unmanaged boundary, which you are.

 

[MarshalAs(UnmanagedType.Struct),StructLayout(LayoutKind.Sequential]

public class Pick

{

...

}

 

That *should* be what you need to do, though I am not 100% sure. It seems most likely like you are dealing with an issue with the packing of your structure's members in memory.

 

Since these are private forums, I hope I don't get in trouble with posting this little bit of engine.dll source:

Function CameraPick_:Int(pick:Byte Ptr,camera:TCamera,p:Float Ptr,radius:Float=0.0,collisionType:Int,pickfilter:Byte Ptr=Null) "win32"
GCEnter()
UserPickFilter=pickfilter
Local pick1:TPick
pick1=CameraPick(camera,Vec3(p[0],p[1],p[2]),radius,collisionType,dllpickfilter)
If pick1
	MemCopy pick,pick1,4*9
	Return 1
EndIf
EndFunction

 

If you notice the call to MemCopy, it is copying 4 bytes per element * 9 elements.

 

EDIT: Ah, I see Structure is the core TPick thing, in that case, put the attribute tag on the declaration of the Core.TPick class, not the Pick class. :(

  • Upvote 1

52t__nvidia.png nVidia 530M cpu.gif Intel Core i7 - 2.3Ghz 114229_30245_16_hardware_memory_ram_icon.png 8GB DDR3 RAM Windows7_Start.gif Windows 7 Ultimate (64x)

-----

IconVisualStudio16.png Visual Studio 2010 Ultimate google-Chrome.png Google Chrome PhotoshopLinkIndicator.png Creative Suite 5 icon28.gif FL Studio 10 MicrosoftOfficeLive.png Office 15

-----

csharp.png Expert cpp.png Professional lua_icon.png Expert BMX Programmer

-----

i-windows-live-messenger-2009.pngskype-icon16.pngaim_online.pnggmail.pngicon_48x48_prism-facebook.pngtunein-web.pngyahoo.giftwitter16.png

Link to comment
Share on other sites

  • 2 weeks later...
  • 2 weeks later...
  • 1 month later...

I can almost guarantee this fix will work.

 

If not, all the "out" keywords will just need changed to "ref" keywords and it is smooth sailing.

 

I had to consult my old Survival game I wrote in C# for Leadwerks 2.0, which had some LinePicks so the player could interact with entities and carry things around.

52t__nvidia.png nVidia 530M cpu.gif Intel Core i7 - 2.3Ghz 114229_30245_16_hardware_memory_ram_icon.png 8GB DDR3 RAM Windows7_Start.gif Windows 7 Ultimate (64x)

-----

IconVisualStudio16.png Visual Studio 2010 Ultimate google-Chrome.png Google Chrome PhotoshopLinkIndicator.png Creative Suite 5 icon28.gif FL Studio 10 MicrosoftOfficeLive.png Office 15

-----

csharp.png Expert cpp.png Professional lua_icon.png Expert BMX Programmer

-----

i-windows-live-messenger-2009.pngskype-icon16.pngaim_online.pnggmail.pngicon_48x48_prism-facebook.pngtunein-web.pngyahoo.giftwitter16.png

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...