 |
Cheat Engine The Official Site of Cheat Engine
|
| View previous topic :: View next topic |
| Author |
Message |
gogodr I post too much
Reputation: 125
Joined: 19 Dec 2006 Posts: 2041
|
Posted: Fri Nov 13, 2009 2:49 am Post subject: |
|
|
yep, after some hours I managed to understand it and apply it.
I pretty much recycled an example and fixed it to work with my solution.
this is pretty much it
| Code: |
private static bool RayIntersectsModel(Ray ray, GameObject gameobject)
{
foreach (ModelMesh mesh in gameobject.model.Meshes)
{
Matrix world = Matrix.CreateFromYawPitchRoll(
gameobject.rotation.Y,
gameobject.rotation.X,
gameobject.rotation.Z) *
Matrix.CreateScale(gameobject.scale) *
Matrix.CreateTranslation(gameobject.position);
BoundingSphere sphere =
TransformBoundingSphere(mesh.BoundingSphere, world);
if (sphere.Intersects(ray) != null)
{
return true;
}
}
return false;
}
private static BoundingSphere TransformBoundingSphere(BoundingSphere sphere,
Matrix transform)
{
BoundingSphere transformedSphere;
Vector3 scale3 = new Vector3(sphere.Radius, sphere.Radius, sphere.Radius);
scale3 = Vector3.TransformNormal(scale3, transform);
transformedSphere.Radius = Math.Max(scale3.X, Math.Max(scale3.Y, scale3.Z));
transformedSphere.Center = Vector3.Transform(sphere.Center, transform);
return transformedSphere;
}
public Ray CalculateCursorRay(Matrix projectionMatrix, Matrix viewMatrix)
{
Vector3 nearSource = new Vector3(cursorstate.X, cursorstate.Y, 0f);
Vector3 farSource = new Vector3(cursorstate.X, cursorstate.Y, 1f);
Vector3 nearPoint = GraphicsDevice.Viewport.Unproject(nearSource,
projectionMatrix, viewMatrix, Matrix.Identity);
Vector3 farPoint = GraphicsDevice.Viewport.Unproject(farSource,
projectionMatrix, viewMatrix, Matrix.Identity);
Vector3 direction = farPoint - nearPoint;
direction.Normalize();
return new Ray(nearPoint, direction);
}
|
|
|
| Back to top |
|
 |
Odecey Master Cheater
Reputation: 1
Joined: 19 Apr 2007 Posts: 259 Location: Scandinavia
|
Posted: Fri Nov 13, 2009 3:05 am Post subject: |
|
|
I'm surprised you didn't get an IndexOutOfRange exception with your previous code, considering alot of the indexes you tried to set are outside the bounds of the array.
_________________
Never confuse activity with productivity. You can be busy without a purpose, but what's the point?- Rick Warren |
|
| Back to top |
|
 |
gogodr I post too much
Reputation: 125
Joined: 19 Dec 2006 Posts: 2041
|
Posted: Fri Nov 13, 2009 3:09 am Post subject: |
|
|
| Odecey wrote: | | I'm surprised you didn't get an IndexOutOfRange exception with your previous code, considering alot of the indexes you tried to set are outside the bounds of the array. |
I did at first xP because I seted up the array with this limits [10,11]
then I realised that to use [10,y] or [x,11] I needed the limits at [11,12]
___________
the problem was fixed xP
I'll post updates of my code in the game development section, also a demo of the game as soon as I finish enough to make a semi playable demo.
right now I'm uploading a video on the current interface.
|
|
| Back to top |
|
 |
Fendaril Cheater
Reputation: 0
Joined: 08 Nov 2009 Posts: 27
|
Posted: Fri Nov 13, 2009 7:15 pm Post subject: |
|
|
For those of you saying "use a loop OMG" you didnt take into consideration that the vector3 constructor for each index of the array is created differently.......
Cell[9, 9].position = new Vector3(41f, 0.1f, -30.3f);
Cell[9, 10].position = new Vector3(56.75f, 0.1f, -40.3f);
Cell[9, 11].position = new Vector3(41f, 0.1f, -50.3f);
are not the same. Hence a loop is actually counter productive.
|
|
| Back to top |
|
 |
hcavolsdsadgadsg I'm a spammer
Reputation: 26
Joined: 11 Jun 2007 Posts: 5801
|
Posted: Fri Nov 13, 2009 8:52 pm Post subject: |
|
|
| Fendaril wrote: | For those of you saying "use a loop OMG" you didnt take into consideration that the vector3 constructor for each index of the array is created differently.......
Cell[9, 9].position = new Vector3(41f, 0.1f, -30.3f);
Cell[9, 10].position = new Vector3(56.75f, 0.1f, -40.3f);
Cell[9, 11].position = new Vector3(41f, 0.1f, -50.3f);
are not the same. Hence a loop is actually counter productive. |
i'm rolling my eyes irl
|
|
| Back to top |
|
 |
gogodr I post too much
Reputation: 125
Joined: 19 Dec 2006 Posts: 2041
|
Posted: Fri Nov 13, 2009 9:17 pm Post subject: |
|
|
| Fendaril wrote: | For those of you saying "use a loop OMG" you didnt take into consideration that the vector3 constructor for each index of the array is created differently.......
Cell[9, 9].position = new Vector3(41f, 0.1f, -30.3f);
Cell[9, 10].position = new Vector3(56.75f, 0.1f, -40.3f);
Cell[9, 11].position = new Vector3(41f, 0.1f, -50.3f);
are not the same. Hence a loop is actually counter productive. |
its not that hard to transform all that code in a Loop
there is a tendency but I got the values and code like that on a debug.. and making it a loop or not doesn't really affect the processing so I'm leaving it in the big code.
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
|
|