[SOLVED]intersectSegments not getting result

Anything libgdx related goes here!

[SOLVED]intersectSegments not getting result

Postby Redkin » Mon Jun 10, 2019 7:29 pm

When i use intersector.intersectSegments with a rect line on the middle of an oblique line it gets null result, why is that happen and how can i solve it thanks!

Image

Is important couse im making a 2d engine, if someone could help or giveme a better solution about it, please :cry:
Last edited by Redkin on Tue Jun 18, 2019 4:30 pm, edited 3 times in total.
Redkin
 
Posts: 82
Joined: Sat Apr 22, 2017 7:21 pm

Re: [NOT SOLVED]intersectSegments not getting result

Postby Redkin » Tue Jun 18, 2019 1:05 pm

I see it happens only if the line is on the middle of a box of tiled if the line is between two boxes doesnt happen, dunno why

Image
Redkin
 
Posts: 82
Joined: Sat Apr 22, 2017 7:21 pm

Re: [NOT SOLVED]intersectSegments not getting result

Postby evilentity » Tue Jun 18, 2019 2:08 pm

You are probably doing something funny. Hard to guess without working example.
Looking for a freelancer? PM me!
Check out libgdx discord server!
evilentity
 
Posts: 4786
Joined: Wed Aug 24, 2011 11:37 am

Re: [NOT SOLVED]intersectSegments not getting result

Postby Redkin » Tue Jun 18, 2019 2:28 pm

Hi evilentity this is the code, sorry:


Code: Select all
public Vector2 intersect2lines(Vector2 p1, Vector2 p2, Vector2 p3, Vector2 p4) {
      Vector2 intersection = new Vector2();
      if (Intersector.intersectSegments(p1, p2, p3, p4, intersection)) {
         return intersection;
      } else {
         return null;
      }
   }

Code: Select all
public void setChecker(Rectangle rectangle, LineBody line, String direccion) {
      
          if (direccion.equals("down")){

         line.x1 = rectangle.x + rectangle.width / 2;
         line.y1 = rectangle.y + rectangle.height / 2;
         line.x2 = rectangle.x + rectangle.width / 2;
         line.y2 = rectangle.y - 10;
      
      }
      
   }

Code: Select all
functions.setChecker(tmpRectangleBot, lineCheckerCenter, "down");

Code: Select all
intersectorCenter = functions.intersect2lines(lineCheckerCenter.getP1(),lineCheckerCenter.getP2(), lineBody.getP1(), lineBody.getP2());

Code: Select all
if (intersectorCenter != null && lineBody.y1!=lineBody.y2) {
                        rectangle.velocity.y = 0;
                        if (lineBody.y1 == lineBody.y2) {
                           rectangle.y = intersectorCenter.y + 0.01f;

                        } else if (lineBody.y1 != lineBody.y2 ) {
                           if (intersectorCenter.y < tmpRectangleBot.y + tmpRectangleBot.height / 2) {
                              rectangle.y = intersectorCenter.y + 0.01f;
                           }
                        }
                        break;
                     }
Redkin
 
Posts: 82
Joined: Sat Apr 22, 2017 7:21 pm

Re: [NOT SOLVED]intersectSegments not getting result

Postby Redkin » Tue Jun 18, 2019 4:29 pm

Solved, was not code problem was the tiled map i created the world with, that had points inside the lines, sorry and thanks
Redkin
 
Posts: 82
Joined: Sat Apr 22, 2017 7:21 pm


Return to Libgdx

Who is online

Users browsing this forum: No registered users and 1 guest