Draw a line in LibGdx that passes for a certain point
-
In LibGdx there's a really easy way to draw shapes, currently I'm drawing lines like this: shapeRenderer.begin(ShapeType.Line); shapeRenderer.line(x1, y1, x2, y2); shapeRenderer.end(); There's a defined starting and final point, let's call them point 1 and point 2, respectively. I need to draw a line that starts in point 1, pass point 2 and continues in the same direction, like this: Any ideas how can this be done?
-
Answer:
Let's say you have two vectors representing your two points: Vector2 p1 = new Vector2(x1, y1); Vector2 p2 = new Vector2(x2, y2); Then what you want to do can be achieved by simply doing that: Vector2 p3 = new Vector2(p2).sub(p1).add(p2); shapeRenderer.line(p2.x, p2.y, p3.x, p3.y); You can change the distance between p2 and p3 by using the scl() method when computing p3: Vector2 p3 = new Vector2(p2).sub(p1).scl(0.5f).add(p2); For example if you use scl(1f) or don't use it at all like in the previous code snippet, distance between p2 and p3 will be the same as between p1 and p2. If you call scl(0.5f) length will be divided by 2, etc.
Cesar Orozco at Stack Overflow Visit the source
Related Q & A:
- How do I apply the overlay to draw a line in maps Android?Best solution by Stack Overflow
- What do a melting point and freezing point of a substance have in common?Best solution by answers.yahoo.com
- What's a rare mineral, that only occurs in a certain part of the world?Best solution by Yahoo! Answers
- What are the different passes of a compiler?Best solution by bayt.com
- How can i get backstage passes to a concert?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.