C++ Program to implement reflection in graphics

Reflection in computer graphics is used to emulate reflective objects like mirrors and shiny surfaces.
Reflection is accomplished in a ray trace renderer by following a ray from the eye to the mirror and then calculating where it bounces from, and continuing the process until no surface is found, or a non-reflective surface is found. Reflection on a shiny surface like wood or tile can add to the photorealistic effects of a 3D rendering.



Program

#include <iostream.h>
#include <conio.h>
#include <graphics.h>
#include <math.h>
void main()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"C:\\Tc\\BGI");
int a=getmaxx();
int b=getmaxy();
int y=b⁄2;
int x=a⁄2;
line(x,0,x,b);
line(0,y,a,y);
int x1=x+100;
int y1=y-100;
int x2=x+150;
int y2=y-150;
line(x2,y2,x1,y1); 
line(x2,y+150,x1,y+100);
line(x-100,y+100,x-200,y+100);
line(x-150,y+150,x-200,y+100);
        line(x-100,y+100,x-150,y+150); 
line(x-100,y-100,x-150,y-150);
line(x-150,y-150,x-200,y-100);
line(x-200,y-100,x-100,y-100);
getch();
closegraph();
}

1 comment:

  1. perfect......looking for this kind of program for too long.... thank you very much

    ReplyDelete