Draw line
15 April 2017 03:26
Hello
I am trying to draw a simple line this is my code
But it's not drawing anything and it doesnt show me any errors so I don't know what am I doing wrong
if I place the code of the "Code Snippets" example it works but I don't need the curves I want to do a straight line for example from one Empty to another Empty.
I am trying to draw a simple line this is my code
//Get Empty's
var punto1 = m_scs.get_object_by_name("linea_cuarto1");
var punto2 = m_scs.get_object_by_name("linea_cuarto2");
//Get the second empty position in local space (I think)
var lugar2 = new Float32Array(m_trans.get_translation(punto2));
//Draw line
m_geom.draw_line(punto1, lugar2, false);
m_mat.set_line_params(punto1, {
color: new Float32Array([1.0, 0.0, 0.0, 1.0]),
width: 5
});
But it's not drawing anything and it doesnt show me any errors so I don't know what am I doing wrong
if I place the code of the "Code Snippets" example it works but I don't need the curves I want to do a straight line for example from one Empty to another Empty.
19 April 2017 07:52
25 April 2017 11:04
Hi Alberto, this method requires the given points to be in the format [X0,Y0,Z0,X1,Y1,Z1…] to draw the segments (X0,Y0,Z0)->(X1,Y1,Z1), (X1,Y1,Z1)->(X2,Y2,Z2) and so on.
So, when you do it like this:
you just create the array for only one point - the position of "punto2", so the method doesn't draw anything.
If you want to draw a simple line from punto1 to punto2 you should specify their positions in the punto1's local space. The first point is [0,0,0], because punto1 is the origin of its space, and the second can be calculated as follows (if punto1 has the zero rotation and the unit scale):
And the drawing call:
So, when you do it like this:
var lugar2 = new Float32Array(m_trans.get_translation(punto2));
you just create the array for only one point - the position of "punto2", so the method doesn't draw anything.
//Get the second empty position in local space (I think)It's in the world space, so you need to transform it.
If you want to draw a simple line from punto1 to punto2 you should specify their positions in the punto1's local space. The first point is [0,0,0], because punto1 is the origin of its space, and the second can be calculated as follows (if punto1 has the zero rotation and the unit scale):
var m_vec3 = require("vec3");
var pos1 = m_trans.get_translation(punto1);
var pos2 = m_trans.get_translation(punto2);
var pos_local = m_vec3.subtract(pos2, pos1, pos1);
And the drawing call:
var points = new Float32Array(6);
points.set(pos_local, 3);
m_geom.draw_line(punto1, points, false);