Compare commits
2 Commits
dfe7c4d2e4
...
5450cf7f5e
Author | SHA1 | Date |
---|---|---|
grant squires | 5450cf7f5e | |
grant squires | ea66b7c1f4 |
10
src/glfww.c
10
src/glfww.c
|
@ -6,8 +6,7 @@
|
|||
#include <math.h>
|
||||
#include "glfww.h"
|
||||
int w,h;
|
||||
#define ab_to_vp(x,y,w,h,x1,y1) float x = 2 * ((float)x1/w) -1;\
|
||||
float y = 2 * ((float)y1/h) -1;
|
||||
|
||||
GLFWwindow* glfw_init(){
|
||||
GLFWwindow* window;
|
||||
|
||||
|
@ -44,6 +43,13 @@ GLFWwindow* glfw_init(){
|
|||
}
|
||||
void refresh_size(GLFWwindow*wi){
|
||||
glfwGetFramebufferSize(wi,&w,&h);
|
||||
//printf("%i,%i\n",w,h);
|
||||
}
|
||||
int get_w(){
|
||||
return w;
|
||||
}
|
||||
int get_h(){
|
||||
return h;
|
||||
}
|
||||
#define glfw_load(w) glfwSwapBuffers(w);
|
||||
void glfw_loop(GLFWwindow*window){
|
||||
|
|
|
@ -1,17 +1,21 @@
|
|||
#include <stdio.h>
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <GL/gl.h>
|
||||
#include "util.h"
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
#ifndef __glfww_
|
||||
#define __glfww_
|
||||
|
||||
#define win_clean() glfwTerminate();
|
||||
#define ab_to_vp(x,y,w,h,x1,y1) float x = 2 * ((float)x1/w) -1;\
|
||||
float y = 2 * ((float)y1/h) -1;
|
||||
GLFWwindow* glfw_init();
|
||||
#define glfw_load(w) glfwSwapBuffers(w);
|
||||
void glfw_loop(GLFWwindow*window);
|
||||
int get_h();
|
||||
int get_w();
|
||||
void glfw_pixel_partial(GLFWwindow*wi,int x, int y);
|
||||
void glfw_clear(GLFWwindow*w);
|
||||
void refresh_size(GLFWwindow*);
|
||||
|
|
111
src/point.c
111
src/point.c
|
@ -45,6 +45,7 @@ void mul_matr(double a[][ma],double b[][ma], double res[][ma]){
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
void perspective_proj(GLFWwindow* b,cord* c, int len,double ctx,double cty,double ctz,double cx, double cy, double cz){
|
||||
//double cx = -100;
|
||||
//double cy = 0;
|
||||
|
@ -53,6 +54,13 @@ void perspective_proj(GLFWwindow* b,cord* c, int len,double ctx,double cty,doubl
|
|||
//double cty = 0;
|
||||
//double ctz = 0;
|
||||
//cz=100-cz;
|
||||
glColor3f(1.0f,0.0f,0.0f);
|
||||
|
||||
GLfloat* pixels = malloc(sizeof(*pixels)*len*800*500*2);
|
||||
|
||||
|
||||
//glfwSwapBuffers(b);
|
||||
//return;
|
||||
double coy = cos(cty);
|
||||
double siz = sin(ctz);
|
||||
double coz = cos(ctz);
|
||||
|
@ -66,7 +74,10 @@ void perspective_proj(GLFWwindow* b,cord* c, int len,double ctx,double cty,doubl
|
|||
refresh_size(b);
|
||||
glColor3f(1.0f,0.0f,0.0f);
|
||||
double ez = 1/tan(fov/2);
|
||||
glBegin(GL_POINTS);
|
||||
//glBegin(GL_POINTS);
|
||||
GLuint fb = 0;
|
||||
//glGenFramebuffers(1,&fb);
|
||||
|
||||
for(int i = 0; i!=len; i++){
|
||||
double ax = c[i].x;
|
||||
double ay = c[i].y;
|
||||
|
@ -83,11 +94,28 @@ void perspective_proj(GLFWwindow* b,cord* c, int len,double ctx,double cty,doubl
|
|||
double by = ez/dz*dy+dy;
|
||||
//printf("%f %f | %f %f %f\n",bx,by,ctx,cty,ctz);
|
||||
//int aaa = round((150-dz)/2);
|
||||
if(dz>=0)
|
||||
glfw_circle_partial(b,nearbyint(bx),nearbyint(by),/*(0>=aaa?1:*/1/*)*/);
|
||||
if(dz>=0){
|
||||
ab_to_vp(xa,ya,get_w(),get_h(),bx,by);
|
||||
//return;
|
||||
//printf("%i:%f %f | %f %f\n",i*2,xa,ya,bx,by);
|
||||
//return;
|
||||
pixels[i*2] = xa;
|
||||
pixels[i*2+1] = ya;
|
||||
} else {
|
||||
pixels[i*2] = -20;
|
||||
pixels[i*2+1]= -20;
|
||||
}
|
||||
//glfw_circle_partial(b,nearbyint(bx),nearbyint(by),/*(0>=aaa?1:*/1/*)*/);
|
||||
//glfw_pixel_partial(b,round(bx),round(by));
|
||||
}
|
||||
glEnd();
|
||||
//return;
|
||||
glPointSize(2.0f);
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
glVertexPointer(2,GL_FLOAT,0,pixels);
|
||||
glDrawArrays(GL_POINTS,0,len);
|
||||
glDisableClientState(GL_VERTEX_ARRAY);
|
||||
free(pixels);
|
||||
//glEnd();
|
||||
}
|
||||
cord* basier3d(double*xx,double*yy,double*zz,int n){
|
||||
cord* pa = malloc(sizeof(*pa)*(3000));
|
||||
|
@ -129,11 +157,13 @@ cord* basier3d(double*xx,double*yy,double*zz,int n){
|
|||
return pa;
|
||||
}
|
||||
void join_cords(cord* a, cord* b, int a_len, int b_len){
|
||||
printf("%lu\n",sizeof(*a)*(a_len+b_len+2));
|
||||
a = realloc(a,sizeof(*a)*(a_len+b_len+2));
|
||||
for(int i = 0; i<=a_len+b_len; i++){
|
||||
a[a_len+i] = b[i];
|
||||
}
|
||||
}
|
||||
|
||||
int main(){
|
||||
double xx[5] = {5.0,5.0,5.0};
|
||||
double yy[5] = {5.0,100.0,200.0};
|
||||
|
@ -175,37 +205,72 @@ int main(){
|
|||
double zz8[5] = {150.0,150.0,150.0};
|
||||
cord* h = basier3d(xx8,yy8,zz8,3);
|
||||
join_cords(a,b,100,100);
|
||||
free(b);
|
||||
join_cords(a,c,200,100);
|
||||
free(c);
|
||||
join_cords(a,d,300,100);
|
||||
free(d);
|
||||
join_cords(a,e,400,100);
|
||||
free(e);
|
||||
join_cords(a,f,500,100);
|
||||
free(f);
|
||||
join_cords(a,g,600,100);
|
||||
free(g);
|
||||
join_cords(a,h,700,100);
|
||||
free(h);
|
||||
int max_r = 630;
|
||||
double half_max_r = (double)max_r/2/2;
|
||||
GLFWwindow* w = glfw_init();
|
||||
for(double rr = 0.01;rr<=20;rr+=0.01){
|
||||
double p1 = 0;
|
||||
double p2 = rr;
|
||||
//glfwSetKeyCallback(w,key_press);
|
||||
double pl_x = 0;
|
||||
double pl_y = 0;
|
||||
double plr_x = 0;
|
||||
double plr_y = 0;
|
||||
for(double rr = 0.01;rr!=0;rr+=0.01){
|
||||
double p1 = plr_x*0.01;
|
||||
double p2 = plr_y*0.01;
|
||||
double p3 = 0;
|
||||
double p4 = -100;
|
||||
double p5 = 0;
|
||||
double p6 = rr*100*0;
|
||||
double p4 = pl_y;
|
||||
double p5 = -pl_y;
|
||||
double p6 = pl_x;
|
||||
perspective_proj(w,a,800,p1,p2,p3,p4,p5,p6);
|
||||
//perspective_proj(w,b,100,p1,p2,p3,p4,p5,p6);
|
||||
//perspective_proj(w,c,100,p1,p2,p3,p4,p5,p6);
|
||||
//perspective_proj(w,d,100,p1,p2,p3,p4,p5,p6);
|
||||
//perspective_proj(w,e,100,p1,p2,p3,p4,p5,p6);
|
||||
//perspective_proj(w,f,100,p1,p2,p3,p4,p5,p6);
|
||||
//perspective_proj(w,g,100,p1,p2,p3,p4,p5,p6);
|
||||
//perspective_proj(w,h,100,p1,p2,p3,p4,p5,p6);
|
||||
|
||||
glfw_load(w);
|
||||
usleep(500);
|
||||
glfw_clear(w);
|
||||
|
||||
usleep(10000);
|
||||
glfwPollEvents();
|
||||
if(glfwGetKey(w,GLFW_KEY_I))
|
||||
plr_x++;
|
||||
if(glfwGetKey(w,GLFW_KEY_K))
|
||||
plr_x--;
|
||||
if(glfwGetKey(w,GLFW_KEY_J))
|
||||
plr_y--;
|
||||
if(glfwGetKey(w,GLFW_KEY_L))
|
||||
plr_y++;
|
||||
plr_x = fmod(plr_x,max_r);
|
||||
plr_y = fmod(plr_y,max_r);
|
||||
if(glfwGetKey(w,GLFW_KEY_W)){
|
||||
pl_x+=cosf(plr_y*0.01);
|
||||
pl_y+=sinf(plr_y*0.01);
|
||||
}
|
||||
if(glfwGetKey(w,GLFW_KEY_S)){
|
||||
pl_x-=cosf(plr_y*0.01);
|
||||
pl_y-=sinf(plr_y*0.01);
|
||||
}
|
||||
if(glfwGetKey(w,GLFW_KEY_A)){
|
||||
pl_x-=cosf((half_max_r+plr_y)*0.01);
|
||||
pl_y-=sinf((half_max_r+plr_y)*0.01);
|
||||
}
|
||||
if(glfwGetKey(w,GLFW_KEY_D)){
|
||||
pl_x+=cosf((half_max_r+plr_y)*0.01);
|
||||
pl_y+=sinf((half_max_r+plr_y)*0.01);
|
||||
}
|
||||
//printf("%f %f %f\n",plr_y,cosf(plr_y*0.01),sinf(plr_y*0.01));
|
||||
glfw_clear(w);
|
||||
|
||||
if(glfwWindowShouldClose(w))break;
|
||||
}
|
||||
free(a);
|
||||
free(b);
|
||||
free(c);
|
||||
free(d);
|
||||
free(a);
|
||||
glfwDestroyWindow(w);
|
||||
win_clean();
|
||||
return 0;
|
||||
|
|
Loading…
Reference in New Issue