Ambiera Forum

Discussions, Help and Support.

Ambiera Forum > CopperCube > Help with CopperCube
Create Polygon With Texture

Zoo
Guest
Quote
2017-11-29 20:29:12

@Niko

I have 2D Flat polygon coordinates. The number of coordinates varies and I will need to assign it a color or a texture, or both.

How do I create this polygon in Coppercube with Javascript and give the polygon a fixed height in order to make it 3D.


Zoo
Guest
Quote
2017-11-29 20:30:32

I just need some sample code for this in order to get started


Zoo
Guest
Quote
2017-11-29 21:07:07

Basically I need to loop through these coordinates that I am pulling out of a database.

All that stuff is fine...

I just need sample code for a 5 point polygon of irregular shape....where the points could be anything.

Given that the points are 2D... Which means that it will be something like this

234.345, 545.5544, 0

There will always be a 0 on the end which I will make a fixed number. Then I just add a texture and a color

My programming skills are good, but my maths skills are terrible and I dont understand the triangle tutorial very well because I don't understand the jargon for 3D meshes.

So some sample code should fix that.


erik
Registered User
Quote
2017-11-30 08:08:40

That's actually a pretty difficult task. Google a bit for "polygon triangulation ": this is really tricky, and not easy at all. You would have to write some complicated algorithm to do this for you.

Creating single triangles is easy, but filling a random shape to be made out of triangles is not. If you just want to create a triangle in CopperCube, it works like this: The 3D engine has a set of 3D positions, like these 3:

(10, 5, 6)
(23, 34, 4)
(3, 7, 8)

(I just entered some random numbers, but this is what you do in CopperCube using ccbAddMeshBufferVertex())
Now, you can link those to form a triangle, using indices into this array of 3D points. Which basically connects the 3 points together, forming a triangle:

0
1
2

It would also be possible to do this the other way round, then you would get a triangle facing into the opposite direction:

0
2
1

These indices are what you add using ccbAddMeshBufferIndex(). And that's basically it. Hope this made sense.


Create reply:


Posted by: (you are not logged in)


Enter the missing letter in: "Intern?tional" (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