Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Using tangents
- #include<iostream>
- #include "graphics.h"
- //#include"DDALine.h"
- using namespace std;
- //float P0x = 100, P0y = 100, P1x = 150, P1y = 50, P2x = 250, P2y = 200, P3x = 350, P3y = 40, Px= 0, Py = 0, Pz = 0;
- //float P0x = 40, P0y = 250, P1x = 40, P1y = 200, P2x = 40, P2y = 150, P3x = 40, P3y = 100, Px= 0, Py = 0, Pz = 0;
- void calcP(float P0x, float P0y, float R0x, float R0y, float P1x, float P1y, float R1x, float R1y, float Px, float Py, float t){
- Px = (2 * t * t* t -3*t*t +1)*P0x + ( t*t*t - 2 *t*t +t)*R0x + (-2 * t*t*t + 3*t*t )*P1x +(t*t*t -t*t )*R1x;
- Py = (2 * t * t* t -3*t*t +1)*P0y + ( t*t*t - 2 *t*t +t)*R0y + (-2 * t*t*t + 3*t*t )*P1y +(t*t*t -t*t )*R1y;
- putpixel(Px, Py, WHITE);
- // Pz = (-4.5 * t * t* t + 9*t*t - 5.5 *t +1)*P0z + (13.5 * t*t*t - 22.5 *t*t +9*t)*P1z + (-13.5 * t*t*t + 18*t*t -4.5*t)*P2z +(4.5*t*t*t -4.5*t*t +t)*P3z;
- }
- int main(){
- int gd = DETECT, gm;
- initgraph(&gd, &gm, "C:\TC\BGI");
- float t = 0;
- float P0x = 71, P0y = 165, R0x = -12, R0y = 2, P1x = 210, P1y = 153, R1x = 108, R1y = 0, Px= 0, Py = 0, Pz = 0;
- while(t<1){
- calcP(P0x, P0y, R0x, R0y, P1x, P1y, R1x, R1y, Px, Py, t);
- t+=0.001;
- }
- /*
- t = 0;
- float P0x = 170, P0y = 250, P1x = 170, P1y = 200, P2x = 170, P2y = 150, P3x = 170, P3y = 100, Px= 0, Py = 0, Pz = 0;
- while(t<1){
- calcP(Px, Py, Pz, t);
- t+=0.001;
- putpixel(Px, Py, WHITE);
- }
- t = 0;
- P0x = 100, P0y = 165, P1x = 95, P1y = 180, P2x = 85, P2y = 180, P3x = 80, P3y = 165, Px= 0, Py = 0, Pz = 0;
- while(t<1){
- calcP(Px, Py, Pz, t);
- t+=0.001;
- putpixel(Px, Py, WHITE);
- }
- /*
- t = 0;
- P0x = 80, P0y = 165, P1x = 120, P1y = 165, P2x = 140, P2y = 165, P3x = 170, P3y = 165, Px= 0, Py = 0, Pz = 0;
- while(t<1){
- calcP(Px, Py, Pz, t);
- t+=0.001;
- putpixel(Px, Py, WHITE);
- }
- t = 0;
- P0x = 80, P0y = 165, P1x = 120, P1y = 165, P2x = 140, P2y = 165, P3x = 160, P3y = 165, Px= 0, Py = 0, Pz = 0;
- while(t<1){
- calcP(Px, Py, Pz, t);
- t+=0.001;
- putpixel(Px, Py, WHITE);
- }
- t = 0;
- P0x = 40, P0y = 100, P1x = 30, P1y = 70, P2x = 50, P2y = 45, P3x = 80, P3y = 50, Px= 0, Py = 0, Pz = 0;
- while(t<1){
- calcP(Px, Py, Pz, t);
- t+=0.001;
- putpixel(Px, Py, WHITE);
- }*/
- getch();
- closegraph();
- return 0;
- }
Add Comment
Please, Sign In to add comment