Ambiera Forum

Discussions, Help and Support.

Ambiera Forum > CopperCube > Help with CopperCube
Draw Line - 3d

carlosmbr
Registered User
Quote
2023-02-09 18:41:02

I need to draw a line from one point to another does anyone have any alternatives?


just_in_case
Moderator
Quote
2023-02-10 13:08:05

IDK what's your exact requirement but maybe you can use the ccbDrawcoloredRectangle() command to draw a line, you can try converting 3D position into 2D position and use it with the drawrectangle command if you want to have the line in 3D space, but I am not sure if it will work as 3D or not, you can give it a try, or maybe you can just use a plane mesh with a scale similar to that of a line. Use geometry (polygon editing) api commands to change the position of vertices of the plane to draw lines.


pmax
Registered User
Quote
2023-02-10 14:28:54

@carlosmbr
here is the code to create a line in the editor there Coppercube but you do very little with it because it is invisible in the 'editor if it is not selected you can use it as a collider , in the game it is invisible.
var meshnode = editorGetSelectedSceneNode(); 
var bufferCount = ccbGetSceneNodeMeshBufferCount(meshnode);

if (bufferCount == 0)
alert('The selected node has no 3D geometry.');
else
{
// remove all mesh buffers holding geometry,
//because we want to replace its geometry with a totally new one
for (var i=0; i<bufferCount; ++i)
ccbRemoveMeshBuffer(meshnode, 0);

// add new buffer
ccbAddMeshBuffer(meshnode);

// disable dynamic lighting
ccbSetSceneNodeMaterialProperty(meshnode, 0, 'Lighting', false);

// add 5 vertices
ccbAddMeshBufferVertex(meshnode, 0, new vector3d(0,0,0));
ccbAddMeshBufferVertex(meshnode, 0, new vector3d(40,0,0));

// set their colors
ccbSetMeshBufferVertexColor(meshnode, 0, 0, 0x77400000);
ccbSetMeshBufferVertexColor(meshnode, 0, 1, 0x77400000);

// add indices
for (var i = 0; i < 4; i++)
{
ccbAddMeshBufferIndex(meshnode, 0, i);
ccbAddMeshBufferIndex(meshnode, 0, i + 1);
}

// update the bounding box of the node
ccbUpdateSceneNodeBoundingBox(meshnode);
}



carlosmbr
Registered User
Quote
2023-02-10 16:10:47

Thanks - @just_in_case, pmax. By answer.

funny i thought the same as just_in_case. but the destination is webgl and the texture animator that I downloaded does not work there.
I thought if you do that it won't work either. I'm trying to create a node following copper licht's tutorial. and put the points where I want it would be like the plane idea but I could move the vertex.


t
Guest
Quote
2023-03-02 11:38:09

why not use 2d line?
🔎︎



Guest
Guest
Quote
2023-03-02 12:23:07

@t, it still uses the same approach suggested by @just_in_case above.

You still need to get the 3D positions of objects, and still have to convert them to 2D positions. and then draw the 2D line that will act as a 3D line.
He also suggested that it can be done with polygon editing API, and @pmax has provided the code for it.

So it is totally the preference of the developer, how he wants to implement something. It would have been much better if you have provided the code to the OP instead of showing an image. This is not something that hasn't been already done by others in the community. So if you want to help then help it by providing solutions, rather then flexing with the images.


SamGrady
Guest
Quote
2023-03-02 20:19:26

If you need function for draw line (cuz coppercube hasn't own one) i created this one for own use (based on one of my previous answer about Pythagoras theorem), use it after transform 3d position into 2d. Not sure about perfomance


function line(x1,y1,x2,y2){
for(i = 0; i < fDst(x1,y1,x2,y2); ++i){
var x = x1 + Math.sin(fAng(x1,y1,x2,y2)/57.29)*i;
var y = y1 + Math.cos(fAng(x1,y1,x2,y2)/57.29)*i;
ccbDrawColoredRectangle(0x79ffffff,x-0.5,y-0.5,x+0.5,y+0.5);
}
}

function fAng(x1,y1,x2,y2){
if((y2 - y1) < 0) return (Math.atan((x2 - x1) / (y2 - y1)) + Math.PI) * 57.29;
else return Math.atan((x2 - x1) / (y2 - y1)) * 57.29;
}

function fDst(x1,y1,x2,y2){
return Math.sqrt(((x2 - x1)*(x2 - x1))+((y2 - y1)*(y2 - y1)));
}





carlosmbr
Registered User
Quote
2023-03-03 05:02:33

Thank you very much - I thought it was very good.


sakura
Registered User
Quote
2023-03-25 16:11:56

wrote:
Thank you very much - I thought it was very good.


You can try to use my function library to draw lines, it is implemented using differential method, so it works very well, with smooth edges and more efficient drawing.

I just ran a test and with 1000 draws my function took an average of 2417ms and the other draw function took an average of 2778ms.

The one on the right side of the picture is the result drawn by my function, which has significantly better edges.
🔎︎


You can find it here:
https://ambiera.com/forum.php?t=...


sven
Registered User
Quote
2023-03-26 13:33:25

For lines in 3D i use cylinder that i scale as needed and it looks and works very nicely -if you need huge amount of lines then this method can be too heavy.

I put cylinder to a PointA then i rotate it towards PointB then i calculate distance and scale it as needed.

Simple example+ action.
https://drive.google.com/file/d/...


Create reply:


Posted by: (you are not logged in)


Enter the missing letter in: "I?ternational" (you are not logged in)


Text:

 

  

Possible Codes


Feature Code
Link [url] www.example.com [/url]
Bold [b]bold text[/b]
Image [img]http://www.example.com/image.jpg[/img]
Quote [quote]quoted text[/quote]
Code [code]source code[/code]

Emoticons


   






Copyright© Ambiera e.U. all rights reserved.
Privacy Policy | Terms and Conditions | Imprint | Contact