Laurens Posted December 27, 2009 Share Posted December 27, 2009 Hi! Do collisions have to be enabled in order for CameraPick to work? I keep getting an AccessViolationException when trying to pick the terrain. Thanks! Quote Link to comment Share on other sites More sharing options...
L B Posted December 27, 2009 Share Posted December 27, 2009 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)); } } } 1 Quote Link to comment Share on other sites More sharing options...
Laurens Posted December 27, 2009 Author Share Posted December 27, 2009 I took a look at the TPick struct in the Core class. I noticed that the members of the struct are in a different order than specified here: http://www.leadwerks.com/wiki/index.php?title=Raycasting. Since it's a sequential layout kind, could this be causing the issue? Cheers! Quote Link to comment Share on other sites More sharing options...
TylerH Posted December 31, 2009 Share Posted December 31, 2009 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. 1 Quote nVidia 530M Intel Core i7 - 2.3Ghz 8GB DDR3 RAM Windows 7 Ultimate (64x)----- Visual Studio 2010 Ultimate Google Chrome Creative Suite 5 FL Studio 10 Office 15 ----- Expert Professional Expert BMX Programmer ----- Link to comment Share on other sites More sharing options...
TylerH Posted January 7, 2010 Share Posted January 7, 2010 So did that work, or no? Quote nVidia 530M Intel Core i7 - 2.3Ghz 8GB DDR3 RAM Windows 7 Ultimate (64x)----- Visual Studio 2010 Ultimate Google Chrome Creative Suite 5 FL Studio 10 Office 15 ----- Expert Professional Expert BMX Programmer ----- Link to comment Share on other sites More sharing options...
Laurens Posted January 7, 2010 Author Share Posted January 7, 2010 Not sure if Ubu did any work on it, I havn't disassembled the new headers. I'll try it when I get home tonight. Quote Link to comment Share on other sites More sharing options...
L B Posted January 8, 2010 Share Posted January 8, 2010 Haven't yet. Will be fixed in 1.2. I'm really busy right now, for personal reasons. 1 Quote Link to comment Share on other sites More sharing options...
Laurens Posted January 8, 2010 Author Share Posted January 8, 2010 Don't pace yourself, it should stay fun Quote Link to comment Share on other sites More sharing options...
L B Posted January 8, 2010 Share Posted January 8, 2010 AccessViolationExceptions are the exact reason why people switch to C#: Avoid them. In this case, it just can't be fun. Quote Link to comment Share on other sites More sharing options...
Rekindled Phoenix Posted January 17, 2010 Share Posted January 17, 2010 Has the pick (struct) in the LE wrapper been updated? I haven't seen 1.2 released yet. Quote Link to comment Share on other sites More sharing options...
L B Posted January 17, 2010 Share Posted January 17, 2010 No it hasn't. Quote Link to comment Share on other sites More sharing options...
Rekindled Phoenix Posted January 27, 2010 Share Posted January 27, 2010 I'm really anticipating the fix for the picks in 1.2! Quote Link to comment Share on other sites More sharing options...
Rekindled Phoenix Posted March 6, 2010 Share Posted March 6, 2010 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. What'd you mean by this? I can't get Picks to work. Quote Link to comment Share on other sites More sharing options...
L B Posted March 8, 2010 Share Posted March 8, 2010 Tyler sent me a fix for the picks a couple of hours ago. I'll try to test it tomorrow. If it works, expect 1.2 soon. Quote Link to comment Share on other sites More sharing options...
Rekindled Phoenix Posted March 9, 2010 Share Posted March 9, 2010 OMG you have just made my day. Thank you Ubu and Tyler! I was getting so stressed about the Raycasting issue. My NPCs can't breathe without them. When you are done could you make an update to one of the pinned forum posts or note me? Quote Link to comment Share on other sites More sharing options...
TylerH Posted March 9, 2010 Share Posted March 9, 2010 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. Quote nVidia 530M Intel Core i7 - 2.3Ghz 8GB DDR3 RAM Windows 7 Ultimate (64x)----- Visual Studio 2010 Ultimate Google Chrome Creative Suite 5 FL Studio 10 Office 15 ----- Expert Professional Expert BMX Programmer ----- Link to comment Share on other sites More sharing options...
Recommended Posts
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.