Jump to content

Aiming.


DigitalHax
 Share

Recommended Posts

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.

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

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.

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

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.

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

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?

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

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

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

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...