English 中文(简体)
Is there a 3D equivalant to clamp in XNA?
原标题:
  • 时间:2009-11-15 22:40:09
  •  标签:
  • c#
  • xna

I m building a 3D game but i only plan on using a 2D perspective thus not taking the z axis into the equasion, i want to be able to limit the movement of one of my models so it doesn t move out of the unmoving field of view,

when i was designing 2D it was simple just use clamp, but i cant seem to figurebout how to do this in 3d

any help would be much appreciated

Regards

问题回答

Just use Vector3.Clamp(Vector3 value1, Vector3 min, Vector3 max) and use the constructor on Vector3 that takes a Vector2 and an int (for z value).

If you simply want to do the same thing as a 2D clamp would - Vector3.Clamp set the Y (usually UP ) component of the two bounding vectors you pass to be 0.

I m slightly confused on the question however, it seems that maybe what you are after is a form of collision detection with the view frustum This article may help with that if your model can fit into a bounding sphere relativity nicely.

You will need to for test collision vs all the planes which define the view space. If its a perspective camera your using, you ll need to get the Frustum Planes, otherwise if its an orthographic camera they are the planes that make the bounding box of the view space (a cuboid which is orientated the same way as the camera).

So you want in pseudocode:

if (object.position+movementVec is in view of camera)
   object.position+=movementVec;




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签