Jump to content
xisto Community
Sign in to follow this  

Help Me (perspective Projection) make a Mode7 projection

Recommended Posts

I made this code to test isometric projection:


#include <graphics.h>#include <stdlib.h>#include <stdio.h>#include <conio.h>#include <math.h>float matrix[4][4] ={{1, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 1, 0}, {0, 0, 0, 1}};void vertex( float x, float y, float z ){	float n[4],r[4]={0, 0, 0, 0};   n[0]=x; n[1]=y; n[2]=z; n[3]=1;   for(int i=0; i<4; i++)   	for(int j=0; j<4; j++)      	r[i]+=n[j]*matrix[j][i];   putpixel(r[0]+(getmaxx()/2),r[1]+(getmaxx()/2),YELLOW);}int main(void){   int gdriver = DETECT, gmode, errorcode;   initgraph(&gdriver, &gmode, "");   errorcode = graphresult();   if (errorcode != grOk) {      printf("Graphics error: %s\n", grapherrormsg(errorcode));      printf("Press any key to halt:");      getch();      exit(1);   }   int angle = 40;	do{      cleardevice();      //isometric projection      matrix[2][0] = -0.5 * sin( angle * M_PI / 180 );      matrix[2][1] = -0.5 * cos( angle * M_PI / 180 );      for(int i=-100; i< 100; i+=1)         for(int j=-100; j< 100; j+=1)               vertex(i,0,j);      angle+=10;      if(angle>=360) angle=0;   }while(!kbhit());	getch();   closegraph();   return 0;}

this code is for isometric projection, can anyone help me to turn it to perspective projection?

or maybe ones called that Mode7.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.