Ray casting through terrain mesh + Octree ( Mesh collision )

I’m currently in development of a terrain editor which i will use for my game. One thing that is partially stopping my development is that I don’t have collision detection implemented between mouse ray cast and the terrain mesh.

The terrain is consisted of triangles and can be lowered and raised.Also the x and y values of the mesh don’t change. Of course what i need to do is ray cast through my mouse positions and get intersected triangle. I would get the point on the triangle using Barycentric coordinates. Just I’m not quite sure how does octree come into play here. As far as I understand it it works like a 3d quadtree, splitting the box into smaller box that the ray intersects. But which box do i choose ? How do i know which box is the closest one to the terrain, if either raised or lowered terrain ? How many subdivisions would i have? I was thinking on having as much as i have tiles( basically the last level of subdivisions would correspond to a x^3 box).

Right now i’m just doing collision with the 0 Z-value plane, and it works okay, but if the terrain is a bit raised then this can give faulty results.

Other two methods that i found is to iterate through the mesh, which of course is insanely inefficient; the other is to project the terrain in reverse and then i guess do some checking with the mouse coordinates (think it’s called z-buffer checking or something).

If anyone has any other ideas i’m all ears. Just note that the algorithm should be an efficient one (of course this depends on the implementation) and accurate.

Thanks !

Theoretical question about Zobrist hashing and chances of collision with slight modification

I’m using zobrist hashing, but for certain positions I want to put them in the cache but make them unique. This is what I’m doing:

quint64 hash = position.zobristHash(); if (makeItUnique)     hash ^= reinterpret_cast<quint64>(this); 

Is there any reason to suppose that what I’m doing will increase the likelihood of hash collisions?

Rolling on collision

I’m having a small issue where if I collide with another object (let’s use a simple cube) with my player (this player is just a sphere), the ball will infinitely roll in the opposite direction and WILL NOT STOP. my code is as follows:

using UnityEngine;  public class PlayerController : MonoBehaviour {     private Rigidbody rb;     private float moveHorizontal;     private float moveVertical;      public float moveSpeed;         // Start is called before the first frame update     private void Awake()     {         rb = GetComponent<Rigidbody>();     }      // Update is called once per frame     void Update()     {         moveHorizontal = Input.GetAxis("Horizontal");         moveVertical = Input.GetAxis("Vertical");     }      private void FixedUpdate()     {         MovePlayer();             }      private void MovePlayer()     {         Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);         rb.AddForce(movement * moveSpeed);     } 

I even changed the ForceMode to ForceMode.Impulse so be able to see what it was doing a little easier, and it is in fact slowly rolling away infinitely with no way to stop it.

Both objects have a Rigidbody for them to be able to react to being hit. This is my first time messing with 3d. I tried to do something like this to make it not roll away on impact

private void OnCollisionExit(Collision collision)     {         if (collision.collider.gameObject.layer != LayerMask.NameToLayer("Ground"))         {             rb.velocity = Vector3.zero;         }     } 

But then if I want to jump on the cube (lets say the cube is an enemy and I’m jumping on it to kill it), then it acts very wonky each time it touches the edge of the cube and I haven’t made it on top (again, because the velocity is being set to zero). I am all out of ideas and would love some input here!

EDIT: I now realize that the ball will slowly roll forever even without collision and just simply moving. I am very lost !

Is there an algorithm to check if two spheres are in collision and whether they’re colliding on the x or the x axis?

I was wondering if there was a way to find out whether a spheres is intersecting another sphere on either its x or its z axis. For instance, Planet A is moving along the Z Axis towards Planet B a stationary object and when collision occurs I would like to get a reponse that tells me that they collided on the zAxis. I can find out if a collsion has occured using the code below however I’m not sure on how to impliment the directional aspect of this. Any help would be appreciated.

    enum ECol { x_Axis, z_Axis, none };      // Collision detection between two spheres      distanceX = sphere2XPosition - sphere1XPosition;     distanceZ = sphere2ZPosition - sphere1ZPosition;     distance = sqrt(distanceX * distanceX + distanceZ * distanceZ );      if (distance < (sphere1Radius + sphere2Radius))     { // Collision occurred } 

Does it matter if a brute force search for a password returns a collision and not the password?

Assume the following very basic hashing algorithm.

h(k) = k mod 17

Let’s say we create a password 12345 for a website that uses this very basic hashing algorithm. That would yield the hash of 3.

Say a brute force attacker comes by and starts guessing numbers starting at 1 they would only have to get to 3 before they got a hash collision and obviously 3 is not the original password.

Is the problem that the password hashing space (0-16) is much smaller than the space of the allowed password, or is there something else I’m overlooking?

Monogame Rectangle Collision Strange Behavior

So I’m making part of the original Legend of Zelda and I’m working on collisions. I want to get the this grey box to collide with the green box (and not be able to go into it). It works when I approach from the bottom, but when I approach from the left it doesn’t detect a collision until right after this point: enter image description here I used the hitbox rectangles as the destination rectangles for these sprites, so I know they have to be intersecting when they visually intersect, but they do not. I am using the Rectangle.Intersects method to detect the intersection, then Rectangle.Intersect to get the rectangle of the intersection. Here’s some of the code where rightTop is the green rectangle and collidable is grey:

public void CheckCollision(ICollidable collidable)     {         if (collidable.GetHitBox().X > maxX)         {             if (!rightOpen)             {                 collidable.SetPosition(maxX, collidable.GetHitBox().Y);                 collidable.BorderCollision();             }             else if (rightTop.Intersects(collidable.GetHitBox()))             {                 Rectangle intersection = Rectangle.Intersect(rightTop, collidable.GetHitBox());                if (intersection.Width > intersection.Height)                 {                     collidable.SetPosition(collidable.GetHitBox().X, rightTop.Bottom);                 }                 else if (intersection.Height > intersection.Width)                 {                     collidable.SetPosition(rightTop.Left-collidable.GetHitBox().Width, collidable.GetHitBox().Y);                 }                  else                 {                     collidable.SetPosition(rightTop.X, collidable.GetHitBox().Y);                 }             }          }      } 

Mutli-Path Collision Avoidance

I am trying to write a program and need an algorithm which can do the following: Given some finite number of particles (circles) each with the same radius, each particle must pass through x prescribed points to make a path in R2. The time elapsed for a particle to travel from any prescribed point to the next is constant for every particle regardless of distance. Create a set of continuous paths such that no particles collide (they can intersect) if such a set exists with the initial conditions of particle radius, # particles, and coordinates/# of prescribed points. Ideally, I would like to find the solution which minimizes total path length under the constraint that there are no collisions. Assume that the distance between the n’th prescribed point of different particles are at least the particle’s diameter apart so that there are no unfixable collisions.

How a chosen prefix collision is more useful than a standard collision concerning hashing functions?

Recently a paper has been released about SHA-1 chosen prefix collision.

They present what a chosen prefix collision is, but I don’t understand how is it more interesting than a standard collision ? They briefly mention x509 rogue certificate, but I still can’t get the point.

Can anyone explain to me how interesting it is compared to standard collisions ? Hopefully with an example a bit more detailed ?

Thanks in advance !