Lines and Points
Andor Salga | 17 March, 2009 | 11:20
We have spent quite a bit of effort writing code which loads and renders models. However, users may want to draw simpler things such as lines and points. One example of rendering points and lines would include the mocap demo. The demo renders a sphere for each marker, which is a bit of a waste, even if the spheres are low quality. Points can be rendered instead, potentially speeding up rendering times. Lines could also be used for this demo to further ease the understanding how the model is structured. Before adding this functionality, I ask for feedback on the following requirements.
Requirements for points
- Must be simple to use
- Must be able to specify position
- Must be able to specify point color
- Must be able to specify point size
Optional features for points
- Possibly allow attenuation factors for all points
Requirements for lines
- Must be able to specify start and end points
- Must be able to specify line color
- Must be able to specify line width
Optional features for lines
- Possibly allow user to specify different colors for each point in a line to create a gradient of color change in the line
- Possibly allow user to specify stippling
Concerns
It is possible users may want to set things like velocity and angular velocity for points and lines, but I don’t see it as very likely. For example, specifying start and end points for a line and allowing users to rotate it would increase the object’s complexity too much. Does it rotate about the start point, middle or end? Should the user be able to specify it? This can be provided in the future, but for now, we will keep the implementation and interface as simple as possible. Taking the earlier notes into account, how will the user want to draw point and lines? I provided a couple of scenarios how a user would specify these primitives:Interface 1 – Provide drawing functions
// user creates and manages an array of coordinates.
var arr = [0,0,0, 1,0,0, 2,0,0, 3,0,0];
// all points which will be drawn will have size = 5
c3dl.setPointSize(5);
// draw all following points red.
c3dl.setPointColor(1,0,0,1);
// this will draw 4 red points with size 5 along the x axis.
c3dl.drawPoints(arr);
Advantages
- It’s straightforward
- Encourages users to group point sizes together, reducing state changes.
Disadvantages
- Setting colors of individual points may be awkward
- To make the library call drawPoints, the user would have to specify a callback function, which is counter intuitive.
interface 2 – provide classes
var point = new c3dl.Point();
// set this points size to 5
point.setSize(5);
// set its color to red and fully opaque.
point.setColor([1,0,0,1]);
// place it at world origin
point.setPosition([0,0,0]);
// rendering is handled by the library
scn.addObjectToScene(point);
The Point class would also offer accessor functions to get its size, color and position. Also, if points are implemented using this method, visibility accessor and mutator functions would have to be provided.
var line = new c3dl.Line();
line.setStart([0,0,0]);
line.setEnd([10,0,0]);
line.setColor([0,1,0,1]);
line.setWidth(2);
scn.addObjectToScene(line);
Advantages
- Mostly just advantages of using objects
Disadvantages
- If a large number of points and lines are specified, this could slow things down, but this needs to be tested

HI dear developers. Can you tell me when you planned to
Mohsen Afshin | 20 April, 2009 | 5:46HI dear developers.
Can you tell me when you planned to add Point and Line features to C3dl?
I need these primitives so much in my project.
Please inform me about the time that this functionality will be added.
Thanks a lot for bringing 3D to Web.
This will be added very soon as we will need
Cathy Leung | 20 April, 2009 | 9:17This will be added very soon as we will need it for the motion capture project. Probably for version 1.1
Mohsen, Can you please tell us how you plan
Andor Salga | 21 April, 2009 | 9:15Mohsen,
Can you please tell us how you plan to use these primitives? It will give us a better understanding of how users will be using the library and allow us to tailor the code to a more general format.