Hi i am trying to draw polygons in C# useing this
endx=startx+(oDBCore.Cos(i*angle)*leng);
Problem is the variables are floats, oDB2D.Line dosent like floats.If i cast endx to int and draw the sides they are differrent lengths and dont join up to make a polygon.When i did this in GDK dbLine didnt complain and all sides met up.
#include <vector>
#include "DarkGDK.h"
using namespace std;
class Poly
{
public:
float startx;
float starty;
float x,y;
float angle;
float length;
float vertacies;
float vertex[5][5];
Poly();
~Poly();
void initialize(float vert,float stx,float sty,float leng);
};
Poly::Poly()
{
}
Poly::~Poly()
{
}
void Poly::initialize(float vert,float stx,float sty,float leng)
{
vertacies=vert;
startx=stx;
starty=sty;
length=leng;
angle=360/vertacies;
vertex[0][0]=startx+(dbCos(0) * leng);
vertex[0][1]=starty+(dbSin(0) * leng);
for (int i=1;i<vertacies;i++){
vertex[i][0]=startx+(dbCos(i*angle) * leng);
vertex[i][1]=starty+(dbSin(i*angle) * leng);
}
}
void display(int obji,Poly object[])
{
for (int i=0;i<object[obji].vertacies;i++){
if (i==object[obji].vertacies-1){
dbLine(object[obji].vertex[i][0], object[obji].vertex[i][1], object[obji].vertex[0][0], object[obji].vertex[0][1]);
}
else{
dbLine(object[obji].vertex[i][0], object[obji].vertex[i][1], object[obji].vertex[i+1][0], object[obji].vertex[i+1][1]);
}
}
}
void DarkGDK(void)
{
dbSyncOn();
float vertacies=9;
float length=50;
float startx=100;
float starty=100;
int objectindex=0;
Poly *object;
object=new Poly[5];
object[0].initialize(vertacies,startx,starty,length);
while (LoopGDK())
{
dbCLS();
display(objectindex,object);
dbSync();
}
}
How do i get the accuracy back?
edit: got it working used Math.Floor(angle)