public void fillPoly3D(Poly3D p,int color) {
projectPoints(p.verteces,p.nverteces);
// project 3d points to 2d, xpoints[] and ypoints[]
int tempx;
int tempy;
if(ypoints[0] > ypoints[1]) { tempy=ypoints[0]; tempx=xpoints[0]; ypoints[0]=ypoints[1]; xpoints[0]=xpoints[1]; ypoints[1]=tempy; xpoints[1]=tempx; }
if(ypoints[0] > ypoints[2]) { tempy=ypoints[0]; tempx=xpoints[0]; ypoints[0]=ypoints[2]; xpoints[0]=xpoints[2]; ypoints[2]=tempy; xpoints[2]=tempx; }
if(ypoints[1] > ypoints[2]) { tempy=ypoints[1]; tempx=xpoints[1]; ypoints[1]=ypoints[2]; xpoints[1]=xpoints[2]; ypoints[2]=tempy; xpoints[2]=tempx; }
// ^ Sorts the points into height order (0 = top, 1 = mid, 2 = bot)
int polyHeight = ypoints[2] - ypoints[0];
if(polyHeight == 0) // Has zero height so can''t be visible
return;
int temp = ((ypoints[1] - ypoints[0]) << 16) / polyHeight;
int longest = temp * (xpoints[2] - xpoints[0]) + ((xpoints[0] - xpoints[1]) << 16);
if(ypoints[0] == ypoints[1]) ypoints[1]+=1;
// ^ for debugging a problem with the edges
if(longest<0) { // middle point is on the right
ledge_dx[0]=ledge_dx[1]=((xpoints[2]-xpoints[0])<<16) / polyHeight;
if(ypoints[1]!=ypoints[0])
redge_dx[0]=((xpoints[1]-xpoints[0])<<16) / (ypoints[1]-ypoints[0]);
if(ypoints[2]!=ypoints[1])
redge_dx[1]=((xpoints[2]-xpoints[1])<<16) / (ypoints[2]-ypoints[1]);
}
if(longest>0) { // middle point is on the left
redge_dx[0]=redge_dx[1]=((xpoints[2]-xpoints[0])<<16) / polyHeight;
if(ypoints[1]!=ypoints[0])
ledge_dx[0]=((xpoints[1]-xpoints[0])<<16) / (ypoints[1]-ypoints[0]);
if(ypoints[2]!=ypoints[1])
ledge_dx[1]=((xpoints[2]-xpoints[1])<<16) / (ypoints[2]-ypoints[1]);
}
int ledge_x=xpoints[0]<<16,redge_x=xpoints[0]<<16; // Top of polygon
int y=(ypoints[0]<0) ? 0 : ypoints[0]; // Start at the top
int ymax=(ypoints[2]>height) ? height : ypoints[2]; // bottom limit
int ledgedx=ledge_dx[0];
int redgedx=redge_dx[0];
int x;
int xmax;
int scany=ytable[y];
do {
x=(ledge_x>>16<0) ? 0 : ledge_x>>16;
xmax=(redge_x>>16>width) ? width : redge_x>>16;
scany+=width;
do {
pixels[ scany+x ]=color;
} while(++x
Before this I used an edge buffer to draw polygons, but the Fatmap tut says that is slow and should be avoided. But there has only been a few fps if anything added. Anyway thanks in advance for any comments and help,
-Paul
[java] Help on this code
Hi,
I need help on this java thing. Yes I know this is in tha java forum and there is another forum for this sort of thing, but I am writing it in java and I need to be aware of any performance increases I could get out of java. It is a function for flat shading polygons and it works perfectly, apart from the speed. It is based on the Fatmap tutorial by Mats Byggmastar, its on this site so people may be familiar with it. Anyways here it is:
Hey, razza.
I''m sorry to disappoint you, but I have no idea how to help you. I''m only writing this because your post has been up for a long time without a response, and I don''t want you to think that no one cares enough to help.
I know how it feels when no one responds to a post. There''s the initial, hopeful post itself. "Maybe someone can help me out," it the general attitude. Then there''s the first check, which reveals that no one has posted a response yet. The next day there are still no responses, and you stump about the house thinking "when all those computer
geeks hop on Gamedev during their lunchbreaks, I''ll get a response for sure." But you don''t, and that evening the dog begins to slink around in the shadows, afraid to come near you. The next day you have some time on your hands and decide that this would be a good time to sharpen up those dull steak knives. You''re so proud of the excellent job you did on the knives that you spend the next day carrying one around absently. The day after
that, a salesman comes to the door, but runs away as soon as you open it. There is something strange going on. You check the forum one last time, and finally see a response. At last the spell is broken. You drop the hatchet, grateful that the response came when it did.
I hope this helps. But I''m lost on the code.
Jonathon
I''m sorry to disappoint you, but I have no idea how to help you. I''m only writing this because your post has been up for a long time without a response, and I don''t want you to think that no one cares enough to help.
I know how it feels when no one responds to a post. There''s the initial, hopeful post itself. "Maybe someone can help me out," it the general attitude. Then there''s the first check, which reveals that no one has posted a response yet. The next day there are still no responses, and you stump about the house thinking "when all those computer
geeks hop on Gamedev during their lunchbreaks, I''ll get a response for sure." But you don''t, and that evening the dog begins to slink around in the shadows, afraid to come near you. The next day you have some time on your hands and decide that this would be a good time to sharpen up those dull steak knives. You''re so proud of the excellent job you did on the knives that you spend the next day carrying one around absently. The day after
that, a salesman comes to the door, but runs away as soon as you open it. There is something strange going on. You check the forum one last time, and finally see a response. At last the spell is broken. You drop the hatchet, grateful that the response came when it did.
I hope this helps. But I''m lost on the code.
Jonathon
quote:"Mathematics are one of the fundamentaries of educationalizing our youths." -George W. Bush
"When a nation is filled with strife, then do patriots flourish." - Lao Tzu
So you want a filled triangle method then?
I can give you the source to mine if you like.
:-)
I can give you the source to mine if you like.
:-)
Hey Jonathon,
You Rule Dude. An honest question going unanswered does suck. But I''m clueless on this too.
You Rule Dude. An honest question going unanswered does suck. But I''m clueless on this too.
Ajatar,
Hey, it''s that community spirit that makes Gamedev what it is, right? Well, alright, the resources are good too....
Jonathon
Hey, it''s that community spirit that makes Gamedev what it is, right? Well, alright, the resources are good too....
Jonathon
quote:"Mathematics are one of the fundamentaries of educationalizing our youths." -George W. Bush
"When a nation is filled with strife, then do patriots flourish." - Lao Tzu
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement