DigitalHax Posted March 18, 2012 Share Posted March 18, 2012 Hello. I was wondering how I would create something similar to the turret in half life 2. Specifically the aiming side. I want to have so when I move the mouse on the screen, it sets the a model to point to where I am pointing - including the distance so if I point really far, it will set the right angle. This is a bit of a tricky one, but I hope someone here understands me. Thanks in advance. Quote Win7 64bit, Leadwerks SDK 2.5, Visual Studio 2012, 3DWS, 3ds Max, Photoshop CS5. Life is too short to remove USB safely. Link to comment Share on other sites More sharing options...
Pixel Perfect Posted March 18, 2012 Share Posted March 18, 2012 Take a look at the function CameraProject. This projects the specified screen coordinates into world coordinates. Once you have that the rest should be fairly straight forward. Quote Intel Core i5 2.66 GHz, Asus P7P55D, 8Gb DDR3 RAM, GTX460 1Gb DDR5, Windows 7 (x64), LE Editor, GMax, 3DWS, UU3D Pro, Texture Maker Pro, Shader Map Pro. Development language: C/C++ Link to comment Share on other sites More sharing options...
DigitalHax Posted March 18, 2012 Author Share Posted March 18, 2012 Will that include distance or depth? Quote Win7 64bit, Leadwerks SDK 2.5, Visual Studio 2012, 3DWS, 3ds Max, Photoshop CS5. Life is too short to remove USB safely. Link to comment Share on other sites More sharing options...
Pixel Perfect Posted March 18, 2012 Share Posted March 18, 2012 Try the examples, they appear to use a depth buffer but I've never actually used it. Failing that you could alternatively use CameraPick. I use that in my Editor for placing items in the world based on the mouse position on the screen: gotSurface = CameraPick(&pickStruct, camera,Vec3(MouseX(),MouseY(), 1000),0,0,NULL); you can extract the position from the pickStruct. If nothing is returned you can assume it exceeds the raycast distance and assume a default far distance value. Quote Intel Core i5 2.66 GHz, Asus P7P55D, 8Gb DDR3 RAM, GTX460 1Gb DDR5, Windows 7 (x64), LE Editor, GMax, 3DWS, UU3D Pro, Texture Maker Pro, Shader Map Pro. Development language: C/C++ Link to comment Share on other sites More sharing options...
DigitalHax Posted March 19, 2012 Author Share Posted March 19, 2012 I seem to be encountering some compile problems... [error C2440: 'initializing' : cannot convert from 'int' to 'LE::TPick' No constructor could take the source type, or constructor overload resolution was ambiguous] this is my basic code, TPick pickS; gotSurface = CameraPick(&pickS, camera,Vec3(MouseX(),MouseY(), 1000),0,0,NULL); What is going wrong? Quote Win7 64bit, Leadwerks SDK 2.5, Visual Studio 2012, 3DWS, 3ds Max, Photoshop CS5. Life is too short to remove USB safely. Link to comment Share on other sites More sharing options...
Road Kill Kenny Posted March 19, 2012 Share Posted March 19, 2012 Have you defined 'gotSurface' ... if so what did you define it as? Quote STS - Scarlet Thread Studios AKA: Engineer Ken Fact: Game Development is hard... very bloody hard.. If you are not prepared to accept that.. Please give up now! Link to comment Share on other sites More sharing options...
DigitalHax Posted March 19, 2012 Author Share Posted March 19, 2012 I tried both a TVec3 and a TPick... Both had errors Quote Win7 64bit, Leadwerks SDK 2.5, Visual Studio 2012, 3DWS, 3ds Max, Photoshop CS5. Life is too short to remove USB safely. Link to comment Share on other sites More sharing options...
Road Kill Kenny Posted March 19, 2012 Share Posted March 19, 2012 That's because it should be an 'int' because CameraPick() returns and integer. In fact you don't even need the gotSurface, just delete it. All it will store is a 1 or a 0. 1 if it hit and 0 if it didn't, nothing else. You only need it if you want to check later in your code if it hit something. The data of the position hit is stored in pickS.x, pickS.y, pickS.z as shown here http://www.leadwerks.com/wiki/index.php?title=Raycasting Quote STS - Scarlet Thread Studios AKA: Engineer Ken Fact: Game Development is hard... very bloody hard.. If you are not prepared to accept that.. Please give up now! Link to comment Share on other sites More sharing options...
Pixel Perfect Posted March 19, 2012 Share Posted March 19, 2012 That's correct, it should be an int. It is just used to check whether something was hit or not Quote Intel Core i5 2.66 GHz, Asus P7P55D, 8Gb DDR3 RAM, GTX460 1Gb DDR5, Windows 7 (x64), LE Editor, GMax, 3DWS, UU3D Pro, Texture Maker Pro, Shader Map Pro. Development language: C/C++ 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.