Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "Firefly_3D.h"
- void FF_translate_point(Point_3D* point, Translation_vector translation)
- {
- point->x += translation.x;
- point->y += translation.y;
- point->z += translation.z;
- }
- void FF_rotation_point(Point_3D* point, Point_3D rotation_center, Rotation_vector rotation)
- {
- Point_3D tmp, tmp2;
- // rotation X
- tmp.x = point->x;
- tmp.y = cos(rotation.x) * (point->y - rotation_center.y) - sin(rotation.x) * (point->z - rotation_center.z) + rotation_center.y;
- tmp.z = sin(rotation.x) * (point->y - rotation_center.y) + cos(rotation.x) * (point->z - rotation_center.z) + rotation_center.z;
- // rotation Y
- tmp2.x = cos(rotation.y) * (tmp.x - rotation_center.x) + sin(rotation.y) * (tmp.z - rotation_center.z) + rotation_center.x;
- tmp2.y = tmp.y;
- tmp2.z = cos(rotation.y) * (tmp.z - rotation_center.z) - sin(rotation.y) * (tmp.x - rotation_center.x) + rotation_center.z;
- // rotation Z
- point->x = cos(rotation.z) * (tmp2.x - rotation_center.x) + sin(rotation.z) * (tmp2.y - rotation_center.y) + rotation_center.x;
- point->y = cos(rotation.z) * (tmp2.y - rotation_center.y) - sin(rotation.z) * (tmp2.x - rotation_center.x) + rotation_center.y;
- point->z = tmp2.z;
- }
- void FF_place_point_3D(Point_3D* point, int x, int y, int z, int color)
- {
- point->x = x;
- point->y = y;
- point->z = z;
- point->color = color;
- }
- Point_3D* FF_new_point_3D(int x, int y, int z, int color)
- {
- Point_3D point;
- FF_place_point_3D(&point, x, y, z, color);
- return &point;
- }
- void FF_alloc_line_3D(Line_3D* line, Point_3D* point_0, Point_3D* point_1, int color)
- {
- line->points[0] = point_0;
- line->points[1] = point_1;
- line->color = color;
- }
- void FF_alloc_face_3D(Face_3D* face, Line_3D* line_0, Line_3D* line_1, Line_3D* line_2, int color)
- {
- face->lines[0] = line_0;
- face->lines[1] = line_1;
- face->lines[2] = line_2;
- face->color = color;
- }
- void FF_draw_point_fixed_camera(Point_3D point, int focale)
- {
- ML_pixel
- (
- (focale * point.x) / (point.z) + (FIREFLY3D_SCREEN_WIDTH>>1),
- (focale * point.y) / (point.z) + (FIREFLY3D_SCREEN_HEIGHT>>1),
- point.color
- );
- }
- void FF_draw_line_fixed_camera(Line_3D line, int focale)
- {
- int i;
- ML_line
- (
- (focale * line.points[0]->x) / (line.points[0]->z) + (FIREFLY3D_SCREEN_WIDTH>>1),
- (focale * line.points[0]->y) / (line.points[0]->z) + (FIREFLY3D_SCREEN_HEIGHT>>1),
- (focale * line.points[1]->x) / (line.points[1]->z) + (FIREFLY3D_SCREEN_WIDTH>>1),
- (focale * line.points[1]->y) / (line.points[1]->z) + (FIREFLY3D_SCREEN_HEIGHT>>1),
- line.color
- );
- for(i=0; i<2; i++) if(line.color != line.points[i]->color) FF_draw_point_fixed_camera(*(line.points[i]), focale);
- }
- void FF_draw_face_fixed_camera(Face_3D face, int focale)
- {
- int x[3], y[3];
- int i;
- for(i=0; i<3; i++)
- {
- x[i] = (focale * face.lines[i]->points[0]->x) / (face.lines[i]->points[0]->z) + (FIREFLY3D_SCREEN_WIDTH>>1);
- y[i] = (focale * face.lines[i]->points[0]->y) / (face.lines[i]->points[0]->z) + (FIREFLY3D_SCREEN_HEIGHT>>1);
- }
- ML_filled_polygon(x, y, 3, face.color);
- for(i=0; i<3; i++) if(face.color != face.lines[i]->color) FF_draw_line_fixed_camera(*(face.lines[i]), focale);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement