Author Topic: Checking in a triangle.  (Read 2333 times)

I drew a diagram:

It's not very good :D


2d triangle (X and Y only), 3d pyramid, 3d square pyramid or cone?

I forgot about the z axis, I think a cone would best suit the job.

I hope you're talking about angles and not angels.

Here's just something I thought of (it's like a scanner):
(I haven't tested it and wouldn't be surprised if it didn't work)
(And it's more of a cylinder than a cone)
Code: [Select]
function SceneObject::scanCone(%obj, %dist, %mask) {
   // %dist is how far away the obj can see
   // Mask is the type-mask you're searching for

   %rad = %dist / 2;
   %maxHeight = %dist * mSin(50);
   %vec = VectorScale(%obj.getForwardVector(), %rad);
   %pos = VectorAdd(%obj.getPosition(), %vec);

   for(%i = 0; %i < %maxHeight; %i++) {
      %pos = VectorAdd(%pos, "0 0 1");
      %obj.setAimLocation(%pos); // For a cool effect?

      InitContainerRadiusSearch(%pos, %rad, %mask);
      while( (%targ=ContainerRadiusSearchNext()) != 0 ) {
         // Found %targ... do whatever you want to it...?
      }
   }
}
« Last Edit: January 07, 2008, 05:37:31 PM by exidyne »

It'd be better do a series of box searches where the width and height of the box change based on the distance of the starting point of the search from the player.  The length of the box would stay the same.

I'm not sure what a box search is.  I'm only aware of (2D) radius searches and (1D) ray-casts.
« Last Edit: January 07, 2008, 05:26:33 PM by exidyne »

How do I check if it's searching in a cone?

How do I check if it's searching in a cone?

Code: [Select]
function SceneObject::scanCone(%obj, %dist, %mask) {
   // %dist is how far away the obj can see
   // Mask is the type-mask you're searching for

   %rad = %dist / 2;
   %maxHeight = %dist * mSin(50);
   %vec = VectorScale(%obj.getForwardVector(), %rad);
   %pos = VectorAdd(%obj.getPosition(), %vec);

   for(%i = 0; %i < %maxHeight; %i++) {
      %pos = VectorAdd(%pos, "0 0 1");
      %obj.setAimLocation(%pos); // For a cool effect?

      InitContainerRadiusSearch(%pos, %rad, %mask);
      while( (%targ=ContainerRadiusSearchNext()) != 0 ) {
         // Found %targ... do whatever you want to it...?
      }
   }
}

How do I check if it's searching in a cone though? Does the setAimLocation bit make me look in a cone?

I'm not sure what you're asking, but the setAimLocation part is something that I just added that makes the player look in the direction it's scanning (so in-game it's like the player is actually scanning with its eyes).

I assumed you wanted it to scan in front of a player, like a player's line of sight.

Also, by cone did you mean like an upright pyramid but with a circle at the bottom?
« Last Edit: January 07, 2008, 05:40:46 PM by exidyne »

How do you check that the area it's looking in forms a cone?

@ exidyne

Code: [Select]
initContainerBoxSearch(%pos,%box,%mask);
Works just like the radius search, only the search area is a cuboid instead of a sphere.

By cone I ment a cone with the point coming from a gun's muzzle point.

k nvm

I ment ... from a gun's muzzle point.
You might want to mention that in your first post

... only the search area is a cuboid instead of a sphere.
I don't think you can search a sphere
Unless you did like a thousand stacked radius searches with different radii
« Last Edit: January 07, 2008, 06:02:49 PM by exidyne »

By cone I ment a cone with the point coming from a gun's muzzle point.

Your best bet is probably to shoot projectiles from the starting point with a circular shape and see if they hit anything.