#include"windows.h"
#include "glos.h"
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glaux.h>
#include"stdio.h"
#define PI 3.141593
struct sl
{
float s1;
float s2;
float s3;} sls;
GLint inp[40][40]={0};
GLint temp[80][3]={0};
struct sl comsl(struct sl ss1,struct sl ss2,struct sl ss3);
void myinit(void);
void draw_triangle(void);
void CALLBACK display(void);
void CALLBACK myReshape(GLsizei w, GLsizei h);
struct sl comsl(struct sl ss1,struct sl ss2,struct sl ss3)
{
struct sl srr;
    float x1,x2,x3,y1,y2,y3;
x1=ss1.s1-ss2.s1;
x2=ss1.s2-ss2.s2;
x3=ss1.s3-ss2.s3;
y1=ss3.s1-ss3.s1;
y2=ss3.s2-ss3.s2;
y3=ss3.s3-ss3.s3;
srr.s1=(x2*y3-x3*y2);///sqrt(srr.s1*srr.s1+srr.s2*srr.s2+srr.s3*srr.s3);
srr.s2=(x1*y3-x3*y1);///sqrt(srr.s1*srr.s1+srr.s2*srr.s2+srr.s3*srr.s3);
srr.s3=(x1*y2-x2*y1);///sqrt(srr.s1*srr.s1+srr.s2*srr.s2+srr.s3*srr.s3); return srr;}
void draw_triangle(void)
{
struct sl ts1,ts2,ts3;
int i,j,k;
for(k=0;k<39;k++)
{
for(i=k;i<k+2;i++)
for(j=0;j<40;j++)
{
if(i%2==0)
{
temp[40*0+2*j][2]=inp[i][j];
temp[2*j][0]=5*j-100;
temp[2*j][1]=5*i-100;
}
else 
{
temp[40*0+2*j+1][2]=inp[i][j];
temp[2*j+1][0]=5*j-100;
temp[2*j+1][1]=5*i-100;
}

}

glBegin(GL_TRIANGLE_STRIP);

for(i=0;i<80;i++)
{

          /*
    if(temp[i][2]>=1150)
glColor3f(0.9,0.8,0.5);
else if(temp[i][2]>=990&&temp[i][2]<1150)
glColor3f(0.7,0.6,0.5);
else if(temp[i][2]>=950&&temp[i][2]<990)
glColor3f(0.6,0.5,0.5);
else if(temp[i][2]>=900&&temp[i][2]<950)
glColor3f(0.3,0.7,0.3);
else if(temp[i][2]>=850&&temp[i][2]<900)
glColor3f(0.3,0.7,0.3);
else if(temp[i][2]>=800&&temp[i][2]<850)
glColor3f(0.3,0.7,0.3);
else if(temp[i][2]>=750&&temp[i][2]<800)
glColor3f(0.3,1,0.8);
else if(temp[i][2]>=700&&temp[i][2]<750)
glColor3f(0.3,0.7,0.8);
else glColor3f(0.3,0.4,0.8);
*/
if(i<77)
{
ts1.s1=temp[i][0];
ts1.s2=temp[i][1];
ts1.s3=temp[i][2];            ts2.s1=temp[i+1][0];
ts2.s2=temp[i+1][1];
ts2.s3=temp[i+1][2]; ts3.s1=temp[i+2][0];
ts3.s2=temp[i+2][1];
ts3.s3=temp[i+2][2];     glNormal3f(comsl(ts1,ts2,ts3).s1,comsl(ts1,ts2,ts3).s2,comsl(ts1,ts2,ts3).s3);
}
glVertex3f(temp[i][0],temp[i][1],temp[i][2]/10);
}
    
glEnd();
    //glColor3f(1,1,1);

glBegin(GL_TRIANGLES);

//glVertex3f(-100,-100,1100);
//glVertex3f(100,-100,800);
//glVertex3f(100,100,22);


glEnd();

    
}
}
void CALLBACK display(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);glLoadIdentity();
gluLookAt(0,0,1900,0,0,0,0,1,0);//0,0,300
glColor3f(1,0,0);draw_triangle();
//auxSolidTeapot(210);glFlush();}
void myinit (void)
{

FILE *fp;
int i,j;


GLfloat mat_diffuse[] = { 0.7, 0.7, 0.7, 1.0 };
    GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 };
    GLfloat mat_shininess[] = { 100.0 };
    GLfloat s_d[]={111,111,1000};
GLfloat la[]={1,0,0,1};
GLfloat ma[]={0.8,0.8,0.8};
    glClearColor (0.0, 0.0, 0.0, 1.0);
glMaterialfv(GL_FRONT,GL_EMISSION,ma);
    glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
    glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
    glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);
    glLightfv(GL_LIGHT0,GL_SPOT_DIRECTION,s_d); 
glLightModelfv(GL_AMBIENT,la);
    glEnable(GL_LIGHTING);
    glEnable(GL_LIGHT0);
//glEnable(GL_LIGHT1);
    glDepthFunc(GL_LESS);
    glEnable(GL_DEPTH_TEST);
glEnable(GL_LEQUAL);
    glEnable(GL_AUTO_NORMAL);
    glEnable(GL_NORMALIZE);

fp=fopen("dopen","r+");
if(fp==NULL)
return ;
for(i=0;i<40;i++)
for(j=0;j<40;j++)
{
fscanf(fp,"%d",&inp[i][j]);
}
fclose(fp);
glShadeModel (GL_SMOOTH);
}
void CALLBACK myReshape(GLsizei w, GLsizei h)
{
glViewport(0, 0, w, h);glMatrixMode(GL_PROJECTION);
glLoadIdentity();//if(w <= h)
// glOrtho(-200.0,200.0,-200.0*(GLfloat)h/(GLfloat)w, 200.0*(GLfloat)h/(GLfloat)w,-2000.0,2000.0); 
//else
// glOrtho(-200.0*(GLfloat)w/(GLfloat)h, 200.0*(GLfloat)w/(GLfloat)h, -200.0, 200.0,-2000.0,2000.0); 
//gluPerspective(180*2*atan(0.75)/PI,1,3,300);
gluPerspective(30,h/w,1,4000);//1000
glMatrixMode(GL_MODELVIEW);
 }
void main(void)
{
auxInitDisplayMode (AUX_SINGLE | AUX_RGBA);
auxInitPosition (0, 0, 700, 700);
auxInitWindow ("Geometric Transformations");
myinit ();
auxReshapeFunc (myReshape);
auxMainLoop(display);
}
/////////////////
我做此程序的目的是做一个地形模拟的东西,做法是画三角形,但是我没有画出来,请大家看看有什么不对的啊,用到的地形模拟数据如下

解决方案 »

  1.   


       610   647   651   694   790   782   817   817   798   845   895   966  1053  1190  1294  1197  1156  1000  1088  1116  1150  1199  1172  1100   942   800   800   737   914  1005  1071  1178  1299  1300  1286  1210  1018  1020   932   836
       600   699   702   697   795   852   859   900   895   904  1000  1022  1078  1123  1261  1299  1224  1098  1088  1106  1099  1204  1300  1102   893   892   947   732   737   915  1051  1140  1149  1200  1292  1361  1299  1200   992  1043
       624   705   722   746   799   900   900   900   930   961  1064  1110  1122  1159  1200  1300  1243  1181  1146  1205  1155  1212  1300  1125   927   999  1088   913   734   700   799   878   800  1103  1172  1231  1390  1316  1225  1227
       600   699   748   800   806   842   871   878   900   989  1116  1172  1200  1257  1299  1300  1300  1269  1298  1271  1277  1200  1300  1180  1076  1130  1166  1030   947   894   812   800   856   965   959   966  1201  1233  1312  1399
       652   721   787   799   800   750   792   813   890   956  1111  1204  1268  1300  1233  1231  1136  1221  1245  1299  1316  1332  1295  1348  1214  1273  1235  1166  1196  1026   884   800   800   800   900  1010  1095   990  1076  1260
       700   730   796   799   700   730   795   799   834   894  1051  1175  1262  1299  1157  1091  1098   970  1084  1224  1315  1322  1321  1300  1209  1282  1300  1196  1276  1156  1072   919   816   799   799   872   879   895   971  1088
       707   797   790   800   695   736   800   818   901   966  1101  1165  1210  1206  1109   939   908   870   985  1123  1221  1079  1125  1122  1059  1125  1296  1307  1344  1328  1300  1002   800   800   800   799   900  1000  1122  1221
       700   691   678   655   688   700   700   805   886  1016  1173  1200  1098  1021  1010   923   800   806   964  1100  1100   902   961   970   995  1104  1216  1298  1399  1353  1207   993  1019   934   855   800   922  1119  1199  1200
       600   599   617   674   700   775   790   841   906   999  1191  1130  1106   908   956   862   753   706   728   727   763   790   799   928   990  1034  1070  1147  1220  1303  1291  1236  1174  1198  1219  1018   800   936  1027  1049
       602   637   671   692   699   798   885   915   981  1017  1006   954   969   999   734   730   700   772   876   919   949   941   800   830   896   900   900  1044  1111  1314  1381  1318  1277  1300  1214  1001   881   800   800   829
       600   660   696   752   802   855   918   980  1000   944   820   788   847   765   700   700   699   768   901   994  1138  1180  1048  1009   950   900  1005  1100  1234  1361  1324  1273  1292  1356  1278  1198  1119   924   959   852
       676   697   697   700   789   844   897   900   891   747   650   617   702   700   813   857   765   699   811   889   990  1181  1200  1200  1203  1207  1299  1253  1281  1335  1226  1104  1100  1300  1310  1282  1045  1104  1143  1035
       714   712   730   759   798   808   763   724   669   600   643   808   798   740  1002  1022   966   717   750   813   912  1028  1081  1017  1078  1212  1179  1146  1299  1203  1134  1047  1206  1213  1204  1290  1185  1279  1204  1000
       762   766   804   823   872   805   600   600   607   697   903  1000   943   913  1014  1100  1058   816   700   713   834   936   987   857  1017  1002   987  1115  1206  1180   990  1026  1111  1100  1080  1240  1299  1292  1100  1128
       800   798   799   839   882   745   600   710   795   867   975  1111  1100  1004  1046  1116  1049   969   811   721   700   700   699   806   759   857  1010  1109  1196  1170  1007   936   946   916   992  1098  1226  1300  1302  1304
       783   799   800   731   734   602   653   757   831   920  1090  1200  1223  1186  1159  1200  1100   986   858   983   819   771   795   700   700   847   930   984  1140  1018   948   840   962  1052  1072  1100  1181  1264  1400  1332
       736   777   800   661   600   657   754   789   796   800   992  1089  1197  1315  1313  1200  1167  1098  1096  1015   874   960  1000   917   826   699   700   907   916   800   800   919  1076  1135  1215  1323  1410  1442  1474  1466
       700   723   733   700   600   740   826   891   924  1007  1104  1201  1294  1326  1400  1305  1300  1231  1200  1056   969  1108  1155  1106   911   794   703   742   800   820   918   995  1025  1160  1355  1416  1470  1507  1548  1524
       699   601   600   600   600   739   832   895   979  1043  1149  1208  1246  1214  1298  1180  1228  1289  1296  1098  1146  1222  1253  1204  1118   933   700   912   995   994  1000  1190  1289  1400  1299  1283  1386  1479  1416  1500
      

  2.   


       610   600   599   608   653   777   842   918  1003  1023  1123  1200  1018  1199  1086  1066  1200  1300  1300  1222  1289  1300  1300  1275  1126   864   700   714   819   800   872  1180  1064  1143  1041   996  1106  1199  1254  1451
       599   600   600   629   709   800   825   883   934   900  1047   974  1011  1165   981  1033  1204  1160  1248  1223  1247  1300  1289  1099   995   932   789   789   801   805   800   816   800   900   933  1047  1357  1399  1386  1379
       600   599   600   600   620   696   735   764   793   869   858   905   982   972   895  1017  1017  1000  1102  1049  1133  1206  1246  1313  1352  1170  1140  1173  1038   800   799  1002  1103  1199  1239  1287  1319  1294  1278  1299
       600   600   619   616   621   663   692   700   728   779   776   885   855   844   841   887   899  1000   996   994  1018  1112  1184  1400  1430  1417  1329  1232   978   850   800   940  1068  1188  1325  1400  1200  1086  1125  1198
       599   599   641   717   776   779   791   735   701   706   699   700   792   805   800   800   839   892   900  1026  1030   999  1100  1275  1359  1447  1505  1194  1110   967   889   867  1064  1203  1224  1311  1084   991   982  1000
       600   621   679   734   805   906   923   904   883   905   918   909   883  1000   838   903   914   907  1092  1184  1231  1166  1090  1153  1309  1472  1599  1419  1246  1071  1085   800   804   926   964  1063   932   899   991  1104
       623   707   800   802   827   914   992  1004  1003  1019  1021  1026  1022  1057   924   941  1024  1076  1226  1305  1388  1300  1310  1100  1194  1290  1400  1529  1308  1302  1308   933   865   799   800   861   906   992  1083  1176
       616   704   800   782   822   911   973   994  1012  1084  1100  1104  1107  1125  1060  1012  1019  1148  1302  1375  1410  1438  1420  1214  1289  1220  1290  1598  1538  1484  1361  1109  1141  1030   923   799   972  1105  1199  1245
       600   600   649   724   798   861   891   888   957  1013  1081  1105  1144  1200  1126  1125  1159  1114  1200  1297  1387  1446  1436  1300  1459  1482  1342  1511  1577  1600  1418  1300  1292  1209  1064   856   888   997  1097  1097
       599   600   599   628   662   746   730   827   902   889  1017  1026  1042  1050   995  1105  1104  1158  1200  1244  1321  1373  1400  1488  1496  1548  1530  1399  1537  1599  1464  1229  1091  1123  1059   905   900   986  1082  1163
       631   606   600   599   600   600   600   724   780   700   835   810   907   936   899   999   989  1097  1147  1283  1303  1313  1322  1485  1548  1609  1600  1500  1499  1434  1294  1146  1000   999   987   993   900   919  1167  1302
       695   747   734   697   713   700   600   600   606   600   679   761   816   754   740   813   890   823  1045  1149  1100  1016  1081  1206  1352  1488  1503  1439  1495  1497  1297  1116  1131  1075  1122  1211   993   900   916  1115
       700   781   799   800   794   818   804   687   600   600   600   613   600   603   774   802   800   800   799   801   888   946  1079  1240  1331  1400  1400  1279  1417  1500  1326  1290  1236  1269  1327  1309  1150   965   900   900
       608   696   763   805   858   903   884   815   686   638   695   700   600   722   926  1049  1112  1000   959   968   902   896   951  1111  1215  1266  1218  1199  1334  1500  1491  1420  1397  1400  1395  1325  1281  1107   958   899
       600   677   696   765   836   925   956   901   752   781   801   700   600   796  1015  1133  1222  1300  1152  1150  1120  1034   978   999  1056  1100  1100  1202  1300  1384  1462  1401  1400  1399  1401  1399  1407  1221  1078   984
       662   686   727   779   841   958  1027   980   893   950   900   648   610   785   996  1111  1190  1270  1392  1287  1300  1300  1179  1216  1202  1209  1219  1191  1200  1290  1399  1387  1400  1431  1460  1444  1498  1345  1213  1136
       702   698   793   873   927  1029  1110  1197  1196  1005   700   705   600   804  1001  1066  1107  1123  1047   939  1078  1181  1246  1131  1090  1217  1099  1163  1131  1152  1191  1294  1374  1418  1464  1488  1497  1483  1404  1277
       756   700   746   869   931  1065  1161  1200  1200  1055   985   888   637   600   727   813   852   977   803   914  1060  1092  1200  1006  1017  1090   975   987  1030  1091  1178  1295  1407  1400  1383  1372  1381  1405  1378  1319
       890   895   891   818   807  1005  1095  1188  1174  1099  1001   843   696   730   600   608   712   735   825   929   997  1061  1108   881   928   959   880   947  1038  1120  1200  1445  1450  1296  1263  1202  1197  1304  1192  1135
       952   899  1037  1087  1032   900   998  1145  1119  1000   953   965   887   974   791   600   600   600   808   856   953  1027  1040   799   800   800   837  1043  1040  1111  1249  1470  1500  1409  1295  1295  1186  1161  1248  1065
       999   998  1077  1200  1200   900  1075  1200  1200  1100  1136  1116  1000  1114   993   886   776   600   670   753   902   894   797   765   800   800   886  1018   995  1020  1149  1356  1425  1413  1399  1399  1301  1100  1200  1017
    ///////////////
      

  3.   

    怎么 没人看啊
    都快告诉我怎么做阿‘
      

  4.   

    大哥,我已经把改好的程序贴出来了,你倒是看啊!
      

  5.   

    恩,老大,我看到了,不好意思啊,,没有看到你的回答,只看到了你的文字回答,我现在把程序考下来,