Compare commits
5 Commits
5f5c660190
...
53b351b078
Author | SHA1 | Date | |
---|---|---|---|
53b351b078 | |||
5542e4861c | |||
|
cd0b0ed0df | ||
8ac68e31e7 | |||
|
b4a7ec7cc3 |
118
LICENSE
Normal file
118
LICENSE
Normal file
@ -0,0 +1,118 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 2, June 1991
|
||||
|
||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
|
||||
Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Lesser General Public License instead.) You can apply it to your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it.
|
||||
|
||||
For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights.
|
||||
|
||||
We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software.
|
||||
|
||||
Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations.
|
||||
|
||||
Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all.
|
||||
|
||||
The precise terms and conditions for copying, distribution and modification follow.
|
||||
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you".
|
||||
|
||||
Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee.
|
||||
|
||||
2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions:
|
||||
|
||||
a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change.
|
||||
|
||||
b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License.
|
||||
|
||||
c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License.
|
||||
|
||||
3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following:
|
||||
|
||||
a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or,
|
||||
|
||||
b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or,
|
||||
|
||||
c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.)
|
||||
|
||||
The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable.
|
||||
|
||||
If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code.
|
||||
|
||||
4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance.
|
||||
|
||||
5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it.
|
||||
|
||||
6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License.
|
||||
|
||||
7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License.
|
||||
|
||||
8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License.
|
||||
|
||||
9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation.
|
||||
|
||||
10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
one line to give the program's name and an idea of what it does. Copyright (C) yyyy name of author
|
||||
|
||||
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program is interactive, make it output a short notice like this when it starts in an interactive mode:
|
||||
|
||||
Gnomovision version 69, Copyright (C) year name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names:
|
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker.
|
||||
|
||||
signature of Ty Coon, 1 April 1989 Ty Coon, President of Vice
|
||||
|
Before Width: | Height: | Size: 10 KiB After Width: | Height: | Size: 10 KiB |
BIN
assets/stone.png
Normal file
BIN
assets/stone.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.0 KiB |
@ -6,6 +6,7 @@
|
||||
#include <stdio.h>
|
||||
#include <GL/gl.h>
|
||||
#include <time.h>
|
||||
#include <stdlib.h>
|
||||
#include "camera.h"
|
||||
#include "noise.h"
|
||||
#include "chunk.h"
|
||||
@ -21,6 +22,14 @@ typedef unsigned int uint;
|
||||
#define CHUNK_MAX_Y 16
|
||||
#define CHUNK_MAX_Z 128
|
||||
|
||||
#define MAX_PARTICLE_GROUPS 10
|
||||
#define PARTICLES_PER_GROUP 50
|
||||
|
||||
typedef struct {
|
||||
vec3f pos[PARTICLES_PER_GROUP];
|
||||
unsigned int time;
|
||||
} ParticleGroup;
|
||||
|
||||
typedef struct {
|
||||
bool is_running;
|
||||
SDL_Window *window;
|
||||
@ -30,17 +39,20 @@ typedef struct {
|
||||
ChunkManager *cm;
|
||||
Type_surface *surfaces;
|
||||
unsigned int surface_count;
|
||||
ParticleGroup particles[MAX_PARTICLE_GROUPS];
|
||||
unsigned char particle_count;
|
||||
} App;
|
||||
|
||||
void app_generate_world(App *app, int a);
|
||||
|
||||
void app_load_textures(App *app);
|
||||
|
||||
GLuint app_get_texture(App *app, Block_type type);
|
||||
|
||||
int check_intersection_block(App *app, vec3i *retv, int *chunk_index);
|
||||
|
||||
void app_break_block(App *app);
|
||||
|
||||
void app_place_block(App *app);
|
||||
|
||||
bool app_check_collision(vec3f camera_pos, ChunkManager *cm);
|
||||
|
||||
void init_app(App *app, uint w, uint h);
|
||||
@ -55,4 +67,8 @@ void update_app(App* app);
|
||||
|
||||
float calc_frame_time(struct timespec *start, struct timespec *end);
|
||||
|
||||
void app_draw_particles(App *app, vec3i b);
|
||||
|
||||
void app_update_particles(App *app);
|
||||
|
||||
#endif
|
||||
|
@ -6,7 +6,7 @@
|
||||
#include <stdbool.h>
|
||||
#include "chunk.h"
|
||||
|
||||
#define GRAVITY 1
|
||||
#define GRAVITY 4
|
||||
/**
|
||||
* Camera, as a moving point with direction
|
||||
*/
|
||||
|
@ -46,8 +46,9 @@ void chunk_set_blocks_visibility(Chunk* chunk);
|
||||
void chunk_create_displayl(ChunkManager *cm, Chunk *chunk);
|
||||
void chunk_render(Chunk* chunk);
|
||||
void chunk_update(ChunkManager* cm, Chunk *chunk);
|
||||
void draw_cube(ChunkManager *cm, Block_type type, float x, float y, float z);
|
||||
void draw_cube(ChunkManager *cm, Block_type type, float x, float y, float z, float s);
|
||||
bool is_block(Block b);
|
||||
int chunk_get_current_chunk_index(ChunkManager *cm, vec3f pos);
|
||||
GLuint get_texture(ChunkManager *cm, Block_type type);
|
||||
|
||||
#endif
|
||||
|
@ -1,6 +1,5 @@
|
||||
#ifndef UTILS_H
|
||||
#define UTILS_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
@ -59,6 +58,8 @@ void vec3f_normalize(vec3f *v);
|
||||
|
||||
int irand_range(int min, int max);
|
||||
|
||||
float frand_range(float min, float max);
|
||||
|
||||
bool check_index(int x, int y, int z);
|
||||
|
||||
void print_vec3f(vec3f v, const char *str);
|
||||
|
186
src/app.c
186
src/app.c
@ -3,6 +3,7 @@
|
||||
|
||||
void init_app(App *app, uint w, uint h)
|
||||
{
|
||||
srand(time(NULL));
|
||||
int err;
|
||||
|
||||
err = SDL_Init(SDL_INIT_EVERYTHING);
|
||||
@ -42,6 +43,7 @@ void init_app(App *app, uint w, uint h)
|
||||
app_load_textures(app);
|
||||
app->cm->textures = app->surfaces;
|
||||
app->cm->texture_count = app->surface_count;
|
||||
app->particle_count = 0;
|
||||
|
||||
app_generate_world(app, 10);
|
||||
app->is_running = true;
|
||||
@ -49,15 +51,13 @@ void init_app(App *app, uint w, uint h)
|
||||
|
||||
void app_load_textures(App *app)
|
||||
{
|
||||
app->surfaces[0].type = BLOCKTYPE_GRASS;
|
||||
app->surfaces[1].type = BLOCKTYPE_DIRT;
|
||||
app->surfaces[2].type = BLOCKTYPE_STONE;
|
||||
app->surfaces[0].type = BLOCKTYPE_DIRT;
|
||||
app->surfaces[1].type = BLOCKTYPE_STONE;
|
||||
|
||||
app->surfaces[0].surface = IMG_Load("assets/block.png");
|
||||
app->surfaces[1].surface = IMG_Load("assets/block.png");
|
||||
app->surfaces[2].surface = IMG_Load("assets/block.png");
|
||||
app->surfaces[0].surface = IMG_Load("assets/dirt.png");
|
||||
app->surfaces[1].surface = IMG_Load("assets/stone.png");
|
||||
|
||||
for (int i = 0; i < app->surface_count-2; i++) {
|
||||
for (int i = 0; i < 1; i++) {
|
||||
if(app->surfaces[i].surface == NULL) {
|
||||
printf("error loading texture\n");
|
||||
exit(1);
|
||||
@ -82,18 +82,16 @@ void app_load_textures(App *app)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void update_app(App* app)
|
||||
{
|
||||
|
||||
update_camera(&(app->camera), app->frame_time/1000);
|
||||
app_update_particles(app);
|
||||
}
|
||||
|
||||
void init_opengl()
|
||||
{
|
||||
// https://gitlab.com/imre-piller/me-courses/ alapjan.
|
||||
/* glShadeModel(GL_SMOOTH);
|
||||
glShadeModel(GL_SMOOTH);
|
||||
|
||||
glEnable(GL_NORMALIZE);
|
||||
glEnable(GL_AUTO_NORMAL);
|
||||
@ -106,7 +104,7 @@ void init_opengl()
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glClearDepth(1.0);
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
void reshape(GLsizei width, GLsizei height)
|
||||
@ -194,8 +192,13 @@ void handle_events(App* app)
|
||||
}
|
||||
break;
|
||||
case SDL_MOUSEBUTTONDOWN:
|
||||
app_break_block(app);
|
||||
break;
|
||||
if (event.button.button == SDL_BUTTON_LEFT) {
|
||||
app_break_block(app);
|
||||
break;
|
||||
} else if (event.button.button == SDL_BUTTON_RIGHT) {
|
||||
app_place_block(app);
|
||||
break;
|
||||
}
|
||||
case SDL_MOUSEMOTION:
|
||||
SDL_GetMouseState(&x, &y);
|
||||
rotate_camera(&(app->camera), mouse_x - x, mouse_y - y);
|
||||
@ -230,10 +233,14 @@ void app_generate_world(App *app, int a)
|
||||
app->cm->chunk_count = a*a;
|
||||
app->cm->chunks = malloc(a*a*sizeof(Chunk));
|
||||
memset(app->cm->chunks, 0, a*a*sizeof(Chunk));
|
||||
long block_count = 0;
|
||||
|
||||
|
||||
unsigned char ptable[512];
|
||||
noise_init_ptable(ptable);
|
||||
|
||||
int r = irand_range(-10000, 10000);
|
||||
|
||||
for (int i = 0; i < a; i++) {
|
||||
for (int j = 0; j < a; j++) {
|
||||
Chunk c;
|
||||
@ -244,13 +251,15 @@ void app_generate_world(App *app, int a)
|
||||
for (int y = 0; y < CHUNK_MAX_Y; y++) {
|
||||
//printf("x: %d y:%d noise: %f\n", x, y, round((noise_noise2(ptable,
|
||||
// (c.start_pos.x+x)*0.03, (c.start_pos.y+y)*0.03) + 1) * 0.5 * 15);
|
||||
int mz = round((noise_noise2(ptable, (c.start_pos.x+x)*0.03, (c.start_pos.y+y)*0.03) + 1) * 0.5 * 15);
|
||||
int mz = round((noise_noise2(ptable, (c.start_pos.x+x+r)*0.02, (c.start_pos.y+y+r)*0.02)+1)* 0.5 * 10);
|
||||
if (mz < 0)
|
||||
mz = 0;
|
||||
else if (mz > CHUNK_MAX_Z)
|
||||
mz = CHUNK_MAX_Z-1;
|
||||
for (int z = 0; z < mz; z++)
|
||||
for (int z = 0; z < mz; z++) {
|
||||
c.blocks[x][y][z].type = BLOCKTYPE_DIRT;
|
||||
block_count++;
|
||||
}
|
||||
for (int z = mz; z < CHUNK_MAX_Z; z++)
|
||||
c.blocks[x][y][z].type = BLOCKTYPE_AIR;
|
||||
}
|
||||
@ -261,6 +270,7 @@ void app_generate_world(App *app, int a)
|
||||
app->cm->chunks[i+(j*a)] = c;
|
||||
}
|
||||
}
|
||||
printf("block count: %d\n", block_count);
|
||||
}
|
||||
|
||||
|
||||
@ -336,12 +346,12 @@ int check_intersection_block(App *app, vec3i *retv, int *chunk_index)
|
||||
for (int y = 0; y < CHUNK_MAX_Y; y++) {
|
||||
for (int z = 0; z < CHUNK_MAX_Z; z++) {
|
||||
if (app->cm->chunks[i].blocks[x][y][z].visible) {
|
||||
for (float j = 0; j < 8; j+=0.2) {
|
||||
for (float j = 0; j < 5; j+=0.1) {
|
||||
vec3f ray = {(c_pos.x - app->cm->chunks[i].start_pos.x) + c_dir.x * j,
|
||||
(c_pos.y - app->cm->chunks[i].start_pos.y) + c_dir.y * j,
|
||||
(c_pos.z - app->cm->chunks[i].start_pos.z) + c_dir.z * j};
|
||||
printf("ray x: %f y: %f z: %f\n", ray.x, ray.y, ray.z);
|
||||
vec3i rayi = {round(ray.x/1), round(ray.y/1), round(ray.z/1)};
|
||||
vec3i rayi = {(int)ray.x, (int)ray.y, (int)ray.z};
|
||||
|
||||
if (is_block(app->cm->chunks[i].blocks[rayi.x][rayi.y][rayi.z])) {
|
||||
retv->x = rayi.x;
|
||||
@ -357,6 +367,51 @@ int check_intersection_block(App *app, vec3i *retv, int *chunk_index)
|
||||
return -1;
|
||||
}
|
||||
|
||||
void app_draw_particles(App *app, vec3i b)
|
||||
{
|
||||
printf("%s\n", __func__);
|
||||
unsigned char index = app->particle_count;
|
||||
|
||||
if (index >= MAX_PARTICLE_GROUPS)
|
||||
return;
|
||||
|
||||
for (int i = 0; i < PARTICLES_PER_GROUP; i++) {
|
||||
vec3f p = {b.x+i/50+frand_range(-0.1,0.1),
|
||||
b.y+i/50+frand_range(-0.1,0.1),
|
||||
b.z+frand_range(-0.1, 0.1)};
|
||||
app->particles[index].pos[i] = p;
|
||||
}
|
||||
|
||||
app->particles[index].time = SDL_GetTicks();
|
||||
|
||||
app->particle_count++;
|
||||
}
|
||||
|
||||
void app_update_particles(App *app)
|
||||
{
|
||||
unsigned char particles = app->particle_count;
|
||||
printf("particle count %d\n", particles);
|
||||
for (int i = 0; i < particles; i++) {
|
||||
unsigned int time = SDL_GetTicks();
|
||||
if (time - app->particles[i].time > 1000) {
|
||||
memset(&app->particles[i], 0, sizeof(ParticleGroup));
|
||||
app->particle_count--;
|
||||
} else {
|
||||
for (int j = 0; j < PARTICLES_PER_GROUP; j++) {
|
||||
printf("particle pos: %f %f %f\n",
|
||||
app->particles[i].pos[j].x,
|
||||
app->particles[i].pos[j].y,
|
||||
app->particles[i].pos[j].z
|
||||
);
|
||||
app->particles[i].pos[j].z -= GRAVITY * app->frame_time/1000;
|
||||
draw_cube(app->cm, 0, app->particles[i].pos[j].x,
|
||||
app->particles[i].pos[j].y,
|
||||
app->particles[i].pos[j].z, 0.5);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void app_break_block(App *app)
|
||||
{
|
||||
printf("%s\n", __func__);
|
||||
@ -369,10 +424,103 @@ void app_break_block(App *app)
|
||||
//printf("chunk %d. min x: %f y: %f max x: %f y: %f\n", i, app->chunks[i].start_pos.x,
|
||||
// app->chunks[i].start_pos.y, app->chunks[i].start_pos.x+CHUNK_MAX_X, app->chunks[i].start_pos.y+CHUNK_MAX_Y);
|
||||
//printf("broken block x: %f y: %f z: %f\n", block.x+app->chunks[i].start_pos.x, block.y+app->chunks[i].start_pos.y, block.z+app->chunks[i].start_pos.z);
|
||||
if(ret < 0)
|
||||
if (ret < 0)
|
||||
return;
|
||||
|
||||
app->cm->chunks[i].blocks[block.x][block.y][block.z].type = BLOCKTYPE_AIR;
|
||||
chunk_update(app->cm, &(app->cm->chunks[i]));
|
||||
|
||||
app_draw_particles(app, block);
|
||||
}
|
||||
|
||||
void app_place_block(App *app)
|
||||
{
|
||||
float dist = 5.0;
|
||||
vec3f cam_pos = app->camera.position;
|
||||
vec3i block;
|
||||
int i;
|
||||
int ret = check_intersection_block(app, &block, &i);
|
||||
|
||||
if (ret < 0)
|
||||
return;
|
||||
|
||||
vec3f t = { (float) cam_pos.x - block.x,
|
||||
(float) cam_pos.y - block.y,
|
||||
(float) cam_pos.z - block.z };
|
||||
printf("t x: %f\n", t.x);
|
||||
printf("t y: %f\n", t.y);
|
||||
//printf("t x: %f\n", t.x);
|
||||
|
||||
if (t.z > 0) {
|
||||
app->cm->chunks[i].blocks[block.x][block.y][block.z+1].type = BLOCKTYPE_STONE;
|
||||
chunk_update(app->cm, &(app->cm->chunks[i]));
|
||||
puts("block blaced, +z");
|
||||
return;
|
||||
} else {
|
||||
app->cm->chunks[i].blocks[block.x][block.y][block.z+1].type = BLOCKTYPE_STONE;
|
||||
chunk_update(app->cm, &(app->cm->chunks[i]));
|
||||
puts("block blaced, -z");
|
||||
return;
|
||||
}
|
||||
if (t.x > 0) {
|
||||
if (t.z > 0) {
|
||||
app->cm->chunks[i].blocks[block.x][block.y][block.z+1].type = BLOCKTYPE_STONE;
|
||||
chunk_update(app->cm, &(app->cm->chunks[i]));
|
||||
puts("block blaced, +z");
|
||||
return;
|
||||
} else {
|
||||
app->cm->chunks[i].blocks[block.x][block.y][block.z+1].type = BLOCKTYPE_STONE;
|
||||
chunk_update(app->cm, &(app->cm->chunks[i]));
|
||||
puts("block blaced, -z");
|
||||
return;
|
||||
}
|
||||
if (t.y < t.x && t.y > -t.x &&
|
||||
!is_block(app->cm->chunks[i].blocks[block.x+1][block.y][block.z])) {
|
||||
|
||||
app->cm->chunks[i].blocks[block.x+1][block.y][block.z].type = BLOCKTYPE_STONE;
|
||||
chunk_update(app->cm, &(app->cm->chunks[i]));
|
||||
puts("block blaced, +x");
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
if (t.y < -t.x && t.y > t.x &&
|
||||
!is_block(app->cm->chunks[i].blocks[block.x-1][block.y][block.z])) {
|
||||
|
||||
app->cm->chunks[i].blocks[block.x-1][block.y][block.z].type = BLOCKTYPE_STONE;
|
||||
chunk_update(app->cm, &(app->cm->chunks[i]));
|
||||
puts("block blaced, -x");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (t.y > 0) {
|
||||
app->cm->chunks[i].blocks[block.x][block.y+1][block.z].type = BLOCKTYPE_STONE;
|
||||
chunk_update(app->cm, &(app->cm->chunks[i]));
|
||||
puts("block blaced, +y");
|
||||
return;
|
||||
} else {
|
||||
app->cm->chunks[i].blocks[block.x][block.y-1][block.z].type = BLOCKTYPE_STONE;
|
||||
chunk_update(app->cm, &(app->cm->chunks[i]));
|
||||
puts("block blaced, -y");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
//if (cam_pos.x < (float)block.x+dist/2 &&
|
||||
// cam_pos.x > (float)block.x-dist/2) {
|
||||
// if (cam_pos.x > block.x)
|
||||
// app->cm->chunks[i].blocks[block.x+1][block.y][block.z].type = BLOCKTYPE_STONE;
|
||||
// if (cam_pos.x < block.x)
|
||||
// app->cm->chunks[i].blocks[block.x-1][block.y][block.z].type = BLOCKTYPE_STONE;
|
||||
// chunk_update(app->cm, &(app->cm->chunks[i]));
|
||||
//}
|
||||
//if (cam_pos.y < (float)block.y+dist/2 &&
|
||||
// cam_pos.y > (float)block.y-dist/2) {
|
||||
// if (cam_pos.y > block.y)
|
||||
// app->cm->chunks[i].blocks[block.x][block.y+1][block.z].type = BLOCKTYPE_STONE;
|
||||
// if (cam_pos.y < block.y)
|
||||
// app->cm->chunks[i].blocks[block.x][block.y-1][block.z].type = BLOCKTYPE_STONE;
|
||||
// chunk_update(app->cm, &(app->cm->chunks[i]));
|
||||
//}
|
||||
}
|
||||
|
||||
|
82
src/camera.c
82
src/camera.c
@ -9,7 +9,7 @@ void init_camera(Camera* camera)
|
||||
{
|
||||
camera->position.x = 5.0;
|
||||
camera->position.y = 5.0;
|
||||
camera->position.z = 40.0;
|
||||
camera->position.z = 90.0;
|
||||
camera->rotation.x = 0.0;
|
||||
camera->rotation.y = 0.0;
|
||||
camera->rotation.z = 0.0;
|
||||
@ -18,48 +18,6 @@ void init_camera(Camera* camera)
|
||||
camera->speed.z = 0.0;
|
||||
}
|
||||
|
||||
vec3f handle_collision(vec3f camera_pos, ChunkManager *cm)
|
||||
{
|
||||
vec3f c_max = { camera_pos.x + 0.25, camera_pos.y + 0.25, camera_pos.z + 0.25 };
|
||||
vec3f c_min = { camera_pos.x - 0.25, camera_pos.y - 0.25, camera_pos.z - 0.25 };
|
||||
vec3f b_max;
|
||||
vec3f b_min;
|
||||
|
||||
int i = chunk_get_current_chunk_index(cm, camera_pos);
|
||||
|
||||
for (int x = floor(camera_pos.x-1); x < floor(camera_pos.x+1); x++) {
|
||||
for (int y = floor(camera_pos.y-1); y < floor(camera_pos.y+1); y++) {
|
||||
int z = floor(camera_pos.z+1);
|
||||
if (!check_index(x, y, z))
|
||||
continue;
|
||||
if(cm->chunks[i].blocks[x][y][z].visible) {
|
||||
b_min = (vec3f) {x+1, y+1, z};
|
||||
b_max = (vec3f) {x+2, y+2, z+1};
|
||||
if (c_max.z > b_min.z &&
|
||||
c_min.z < b_max.z) {
|
||||
return (vec3f) {0, 0, 1};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//int x = floor(camera_pos.x);
|
||||
//int y = floor(camera_pos.y);
|
||||
//int z = floor(camera_pos.z);
|
||||
|
||||
//b_min = (vec3f) {x, y, z};
|
||||
//b_max = (vec3f) {x+1, y+1, z+1};
|
||||
//
|
||||
//print_vec3f(c_max, "c_max");
|
||||
//print_vec3f(c_max, "c_min");
|
||||
//print_vec3f(c_max, "b_max");
|
||||
//print_vec3f(c_max, "b_max");
|
||||
//if (c_max.z > b_min.z &&
|
||||
// c_min.z < b_max.z) {
|
||||
// return (vec3f) {0, 0, 1};
|
||||
//}
|
||||
return (vec3f) {0, 0, 0};
|
||||
}
|
||||
void update_camera(Camera* camera, double time)
|
||||
{
|
||||
double angle;
|
||||
@ -76,9 +34,9 @@ void update_camera(Camera* camera, double time)
|
||||
float y1 = camera->position.y + sin(side_angle) * camera->speed.x * time;
|
||||
float z1 = camera->position.z + camera->speed.z * time;
|
||||
|
||||
printf("x: %f\n",camera->position.x + camera->speed.z * time);
|
||||
printf("x: %f\n",camera->position.y + cos(angle) * camera->speed.y * time);
|
||||
printf("x: %f\n",camera->position.z + sin(angle) * camera->speed.y * time);
|
||||
//printf("x: %f\n",camera->position.x + camera->speed.z * time);
|
||||
//printf("x: %f\n",camera->position.y + cos(angle) * camera->speed.y * time);
|
||||
//printf("x: %f\n",camera->position.z + sin(angle) * camera->speed.y * time);
|
||||
|
||||
//vec3f v = handle_collision(camera->position, camera->cm);
|
||||
|
||||
@ -96,44 +54,38 @@ void update_camera(Camera* camera, double time)
|
||||
vec3f cs = camera->cm->chunks[i].start_pos;
|
||||
|
||||
x -= cs.x; y -= cs.y; z -= cs.z;
|
||||
x1 -= cs.x; y1 -= cs.y; z1 -= cs.z;
|
||||
x1 -= cs.x; y1 -= cs.y; z1 -= cs.z;
|
||||
|
||||
x += 0.3; y += 0.3;
|
||||
x1 += 0.3; y1 += 0.3;
|
||||
|
||||
if(!is_block(camera->cm->chunks[i].blocks[(int)x][(int)y][(int)z-1])) {
|
||||
puts("not is block");
|
||||
//puts("not is block");
|
||||
camera->speed.z -= GRAVITY * time;
|
||||
camera->position.x += cos(angle) * camera->speed.y * time;
|
||||
camera->position.y += sin(angle) * camera->speed.y * time;
|
||||
camera->position.z += camera->speed.z * time;
|
||||
|
||||
} else {
|
||||
puts("is block");
|
||||
//puts("is block");
|
||||
camera->speed.z = 0;
|
||||
|
||||
while(is_block(camera->cm->chunks[i].blocks[(int)camera->position.x]
|
||||
[(int)camera->position.y]
|
||||
[(int)camera->position.z-1])) {
|
||||
camera->position.z+=0.2;
|
||||
print_vec3f(camera->position, "camera");
|
||||
}
|
||||
float diff = round(camera->position.z) - camera->position.z;
|
||||
camera->position.z += diff;
|
||||
}
|
||||
|
||||
if(!is_block(camera->cm->chunks[i].blocks[(int)x1][(int)y1][(int)z1-1])) {
|
||||
puts("not is block");
|
||||
//puts("not is block");
|
||||
camera->speed.z -= GRAVITY * time;
|
||||
camera->position.x += cos(side_angle) * camera->speed.x * time;
|
||||
camera->position.y += sin(side_angle) * camera->speed.x * time;
|
||||
camera->position.z += camera->speed.z * time;
|
||||
|
||||
} else {
|
||||
puts("is block");
|
||||
//puts("is block");
|
||||
camera->speed.z = 0;
|
||||
|
||||
while(is_block(camera->cm->chunks[i].blocks[(int)camera->position.x]
|
||||
[(int)camera->position.y]
|
||||
[(int)camera->position.z-1])) {
|
||||
camera->position.z+=0.2;
|
||||
print_vec3f(camera->position, "camera");
|
||||
}
|
||||
float diff = round(camera->position.z) - camera->position.z;
|
||||
camera->position.z += diff;
|
||||
}
|
||||
}
|
||||
|
||||
@ -199,7 +151,7 @@ vec3f get_camera_dir_vec3f(Camera *camera)
|
||||
sin(degree_to_radian(camera->rotation.z)) *
|
||||
cos(degree_to_radian(camera->rotation.x)),
|
||||
sin(degree_to_radian(camera->rotation.x))};
|
||||
|
||||
|
||||
vec3f_normalize(&dir);
|
||||
return dir;
|
||||
}
|
||||
|
89
src/chunk.c
89
src/chunk.c
@ -45,7 +45,7 @@ void chunk_update(ChunkManager *cm, Chunk *chunk)
|
||||
chunk_create_displayl(cm, chunk);
|
||||
}
|
||||
|
||||
void draw_cube(ChunkManager *cm, Block_type type, float x, float y, float z)
|
||||
void draw_cube(ChunkManager *cm, Block_type type, float x, float y, float z, float s)
|
||||
{
|
||||
/*x*=2;
|
||||
y*=2;
|
||||
@ -57,62 +57,65 @@ void draw_cube(ChunkManager *cm, Block_type type, float x, float y, float z)
|
||||
glBindTexture(GL_TEXTURE_2D, cm->textures[i].tid);
|
||||
}
|
||||
*/
|
||||
|
||||
glColor3f(1, 1, 1);
|
||||
|
||||
glBegin( GL_QUADS );
|
||||
|
||||
glColor3f(1, 0, 1);
|
||||
glTexCoord2f(0, 0); glVertex3f(x+1.0, y, z-1.0 );
|
||||
glTexCoord2f(0, 1); glVertex3f(x, y, z-1.0);
|
||||
glTexCoord2f(1, 1); glVertex3f(x, y, z);
|
||||
glTexCoord2f(1, 0); glVertex3f(x+1.0, y, z);
|
||||
//glColor3f(1, 0, 1);
|
||||
glColor3f( 0.0f, 1.0f, 0.0f ); // Green
|
||||
glTexCoord2f(0, 0); glVertex3f(x-0.5*s, y+0.5*s, z+0.5*s);
|
||||
glTexCoord2f(0, 1); glVertex3f(x+0.5*s, y+0.5*s, z+0.5*s);
|
||||
glTexCoord2f(1, 1); glVertex3f(x+0.5*s, y-0.5*s, z+0.5*s);
|
||||
glTexCoord2f(1, 0); glVertex3f(x-0.5*s, y-0.5*s, z+0.5*s);
|
||||
|
||||
glColor3f(1, 0, 1);
|
||||
glTexCoord2f(0, 0); glVertex3f(x+1.0, y-1.0, z-1.0);
|
||||
glTexCoord2f(0, 1); glVertex3f(x, y-1.0, z-1.0);
|
||||
glTexCoord2f(1, 1); glVertex3f(x, y-1.0, z);
|
||||
glTexCoord2f(1, 0); glVertex3f(x+1.0, y-1.0, z);
|
||||
//glColor3f(1, 0, 1);
|
||||
glColor3f(1, 1, 1);
|
||||
glTexCoord2f(0, 0); glVertex3f(x+0.5*s, y-0.5*s, z-0.5*s);
|
||||
glTexCoord2f(0, 1); glVertex3f(x-0.5*s, y-0.5*s, z-0.5*s);
|
||||
glTexCoord2f(1, 1); glVertex3f(x-0.5*s, y+0.5*s, z-0.5*s);
|
||||
glTexCoord2f(1, 0); glVertex3f(x+0.5*s, y+0.5*s, z-0.5*s);
|
||||
|
||||
glColor3f(1, 0, 1);
|
||||
glTexCoord2f(0, 0); glVertex3f(x+1.0, y, z);
|
||||
glTexCoord2f(0, 1); glVertex3f(x, y, z);
|
||||
glTexCoord2f(1, 1); glVertex3f(x, y-1.0, z);
|
||||
glTexCoord2f(1, 0); glVertex3f(x+1.0, y-1.0, z);
|
||||
//glColor3f(1, 0, 1);
|
||||
glTexCoord2f(0, 0); glVertex3f(x+0.5*s, y+0.5*s, z+0.5*s);
|
||||
glTexCoord2f(0, 1); glVertex3f(x-0.5*s, y+0.5*s, z+0.5*s);
|
||||
glTexCoord2f(1, 1); glVertex3f(x-0.5*s, y+0.5*s, z-0.5*s);
|
||||
glTexCoord2f(1, 0); glVertex3f(x+0.5*s, y+0.5*s, z-0.5*s);
|
||||
|
||||
glColor3f(1, 0, 1);
|
||||
glTexCoord2f(0, 0); glVertex3f(x, y, z-1.0); // Top-Right of back face
|
||||
glTexCoord2f(0, 1); glVertex3f(x+1.0, y, z-1.0); // Top-Left of back face
|
||||
glTexCoord2f(1, 1); glVertex3f(x+1.0, y-1.0, z-1.0); // Bottom-Left of back face
|
||||
glTexCoord2f(1, 0); glVertex3f(x, y-1.0, z-1.0); // Bottom-Right of back face
|
||||
//glColor3f(1, 0, 1);
|
||||
glTexCoord2f(0, 0); glVertex3f(x+0.5*s, y-0.5*s, z+0.5*s); // Top-Right of back face
|
||||
glTexCoord2f(0, 1); glVertex3f(x-0.5*s, y-0.5*s, z+0.5*s); // Top-Left of back face
|
||||
glTexCoord2f(1, 1); glVertex3f(x-0.5*s, y-0.5*s, z-0.5*s); // Bottom-Left of back face
|
||||
glTexCoord2f(1, 0); glVertex3f(x+0.5*s, y-0.5*s, z-0.5*s); // Bottom-Right of back face
|
||||
|
||||
glColor3f(1, 0, 1);
|
||||
glTexCoord2f(0, 0); glVertex3f(x, y, z); // Top-Right of left face
|
||||
glTexCoord2f(0, 1); glVertex3f(x, y, z-1.0); // Top-Left of left face
|
||||
glTexCoord2f(1, 1); glVertex3f(x, y-1.0, z-1.0); // Bottom-Left of left face
|
||||
glTexCoord2f(1, 0); glVertex3f(x, y-1.0, z); // Bottom-Right of left face
|
||||
//glColor3f(1, 0, 1);
|
||||
glTexCoord2f(0, 0); glVertex3f(x-0.5*s, y-0.5*s, z+0.5*s); // Top-Right of left face
|
||||
glTexCoord2f(0, 1); glVertex3f(x-0.5*s, y+0.5*s, z+0.5*s); // Top-Left of left face
|
||||
glTexCoord2f(1, 1); glVertex3f(x-0.5*s, y+0.5*s, z-0.5*s); // Bottom-Left of left face
|
||||
glTexCoord2f(1, 0); glVertex3f(x-0.5*s, y-0.5*s, z-0.5*s); // Bottom-Right of left face
|
||||
|
||||
glColor3f(1, 0, 1);
|
||||
glTexCoord2f(0, 0); glVertex3f(x+1.0, y, z); // Top-Right of left face
|
||||
glTexCoord2f(0, 1); glVertex3f(x+1.0, y, z-1.0); // Top-Left of left face
|
||||
glTexCoord2f(1, 1); glVertex3f(x+1.0, y-1.0, z-1.0); // Bottom-Left of left face
|
||||
glTexCoord2f(1, 0); glVertex3f(x+1.0, y-1.0, z); // Bottom-Right of left face
|
||||
//glColor3f(1, 0, 1);
|
||||
glTexCoord2f(0, 0); glVertex3f(x+0.5*s, y-0.5*s, z+0.5*s); // Top-Right of right face
|
||||
glTexCoord2f(0, 1); glVertex3f(x+0.5*s, y+0.5*s, z+0.5*s); // Top-Left of right face
|
||||
glTexCoord2f(1, 1); glVertex3f(x+0.5*s, y+0.5*s, z-0.5*s); // Bottom-Left of right face
|
||||
glTexCoord2f(1, 0); glVertex3f(x+0.5*s, y-0.5*s, z-0.5*s); // Bottom-Right of right face
|
||||
glEnd();
|
||||
glFlush();
|
||||
|
||||
}
|
||||
|
||||
void chunk_create_displayl(ChunkManager *cm, Chunk *chunk)
|
||||
{
|
||||
|
||||
|
||||
|
||||
//glBindTexture(GL_TEXTURE_2D, 1);
|
||||
chunk->id = glGenLists(1);
|
||||
glBindTexture(GL_TEXTURE_2D, cm->textures[0].tid);
|
||||
//glBindTexture(GL_TEXTURE_2D, cm->textures[0].tid);
|
||||
glColor3f(1, 1, 1);
|
||||
|
||||
glNewList(chunk->id, GL_COMPILE);
|
||||
for (int x = 0; x < CHUNK_MAX_X; x++) {
|
||||
for (int y = 0; y < CHUNK_MAX_Y; y++) {
|
||||
for (int z = 0; z < CHUNK_MAX_Z; z++) {
|
||||
if (chunk->blocks[x][y][z].visible)
|
||||
draw_cube(cm, chunk->blocks[x][y][z].type,
|
||||
chunk->start_pos.x + x, chunk->start_pos.y + y, chunk->start_pos.z + z);
|
||||
chunk->start_pos.x + x, chunk->start_pos.y + y, chunk->start_pos.z + z, 1.0);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -146,3 +149,13 @@ int chunk_get_current_chunk_index(ChunkManager *cm, vec3f pos)
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
GLuint get_texture(ChunkManager *cm, Block_type type)
|
||||
{
|
||||
for (int i = 0; i < 2; i++) {
|
||||
if (cm->textures[i].type == type)
|
||||
return cm->textures[i].tid;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
213
src/main.c
213
src/main.c
@ -14,226 +14,61 @@ int main()
|
||||
app.cm = &cm;
|
||||
init_app(&app, 1600, 900);
|
||||
|
||||
/////
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
|
||||
glShadeModel(GL_SMOOTH);
|
||||
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
|
||||
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
|
||||
|
||||
glClearDepth(1.0f);
|
||||
glDepthFunc(GL_LEQUAL);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
//glEnable(GL_CULL_FACE);
|
||||
|
||||
glEnable(GL_NORMALIZE);
|
||||
|
||||
|
||||
GLuint shadowmap_texture;
|
||||
|
||||
float light_proj_matrix[16];
|
||||
float light_view_matrix[16];
|
||||
float cam_proj_matrix[16];
|
||||
float cam_view_matrix[16];
|
||||
|
||||
glGenTextures(1, &shadowmap_texture);
|
||||
glBindTexture(GL_TEXTURE_2D, shadowmap_texture);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24,
|
||||
SHADOWMAP_SIZE, SHADOWMAP_SIZE, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, NULL);
|
||||
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
|
||||
glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
|
||||
glEnable(GL_COLOR_MATERIAL);
|
||||
|
||||
//GLfloat materialColor[] = {1.0f, 1.0f, 1.0f, 1.0f};
|
||||
//glMaterialfv(GL_FRONT, GL_SPECULAR, materialColor);
|
||||
glMaterialf(GL_FRONT, GL_SHININESS, 64.0f);
|
||||
|
||||
|
||||
|
||||
|
||||
//reshape(1600, 900);
|
||||
glPushMatrix();
|
||||
glLoadIdentity();
|
||||
gluPerspective(45.0f, (float)1600/900, 1.0f, 10000.0f);
|
||||
glGetFloatv(GL_MODELVIEW_MATRIX, cam_proj_matrix);
|
||||
|
||||
|
||||
|
||||
glLoadIdentity();
|
||||
gluPerspective(45.0, 1.0, 2.0, 10000.0);
|
||||
glGetFloatv(GL_MODELVIEW_MATRIX, light_proj_matrix);
|
||||
|
||||
glLoadIdentity();
|
||||
gluLookAt(80, 80, 90,
|
||||
20.0, 20.0, 10.0,
|
||||
0.0, 0.0, 1.0);
|
||||
glGetFloatv(GL_MODELVIEW_MATRIX, light_view_matrix);
|
||||
|
||||
glPopMatrix();
|
||||
/////
|
||||
while(app.is_running) {
|
||||
clock_gettime(CLOCK_MONOTONIC_RAW, &start);
|
||||
|
||||
vec3f cd = get_camera_dir_vec3f(&app.camera);
|
||||
vec3f cp = app.camera.position;
|
||||
|
||||
// glLoadIdentity();
|
||||
// gluLookAt(cp.x, cp.y, cp.z,
|
||||
// 10.0, 10.0, 30.0,
|
||||
// 0.0, 0.0, 1.0);
|
||||
set_view(&app.camera);
|
||||
glGetFloatv(GL_MODELVIEW_MATRIX, cam_view_matrix);
|
||||
|
||||
|
||||
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadMatrixf(light_proj_matrix);
|
||||
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadMatrixf(light_view_matrix);
|
||||
|
||||
glViewport(0, 0, SHADOWMAP_SIZE, SHADOWMAP_SIZE);
|
||||
|
||||
glCullFace(GL_FRONT);
|
||||
|
||||
glShadeModel(GL_FLAT);
|
||||
glColorMask(0, 0, 0, 0);
|
||||
|
||||
for (int i = 0; i < app.cm->chunk_count; i++) {
|
||||
chunk_render(&app.cm->chunks[i]);
|
||||
//printf("c sp: %f\n", app.chunks[i].start_pos.x);
|
||||
}
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, shadowmap_texture);
|
||||
glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, SHADOWMAP_SIZE, SHADOWMAP_SIZE);
|
||||
|
||||
glCullFace(GL_BACK);
|
||||
//glDisable(GL_CULL_FACE);
|
||||
glShadeModel(GL_SMOOTH);
|
||||
glColorMask(1, 1, 1, 1);
|
||||
|
||||
glClear(GL_DEPTH_BUFFER_BIT);
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadMatrixf(cam_proj_matrix);
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadMatrixf(cam_view_matrix);
|
||||
glViewport(0, 0, 1600, 900);
|
||||
///////////////
|
||||
|
||||
handle_events(&app);
|
||||
update_app(&app);
|
||||
|
||||
float color1[4] = {0, 0, 0, 0};
|
||||
float color2[4] = {0, 0, 0, 0};
|
||||
float color3[4] = {1.0, 1.0, 1.0, 0.0};
|
||||
float light_pos[4] = {80, 80, 90, 0};
|
||||
glLightfv(GL_LIGHT1, GL_POSITION, light_pos);
|
||||
glLightfv(GL_LIGHT1, GL_AMBIENT, color1);
|
||||
glLightfv(GL_LIGHT1, GL_DIFFUSE, color1);
|
||||
glLightfv(GL_LIGHT1, GL_SPECULAR, color2);
|
||||
glEnable(GL_LIGHT1);
|
||||
glEnable(GL_LIGHTING);
|
||||
set_view(&app.camera);
|
||||
reshape(1600, 900);
|
||||
|
||||
//glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
//set_view(&app.camera);
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
for (int i = 0; i < app.cm->chunk_count; i++) {
|
||||
chunk_render(&app.cm->chunks[i]);
|
||||
//printf("c sp: %f\n", app.chunks[i].start_pos.x);
|
||||
}
|
||||
|
||||
glLightfv(GL_LIGHT1, GL_DIFFUSE, color3);
|
||||
glLightfv(GL_LIGHT1, GL_SPECULAR, color3);
|
||||
float bias[16] = {0.5f, 0.0f, 0.0f, 0.0f,
|
||||
0.0f, 0.5f, 0.0f, 0.0f,
|
||||
0.0f, 0.0f, 0.5f, 0.0f,
|
||||
0.5f, 0.5f, 0.5f, 1.0f};
|
||||
float m1[16];
|
||||
float tm[16];
|
||||
mult_matrix(bias, light_proj_matrix, m1);
|
||||
mult_matrix(m1, light_view_matrix, tm);
|
||||
|
||||
float v1[4] = {tm[0], tm[1], tm[2], tm[3]};
|
||||
glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
|
||||
glTexGenfv(GL_S, GL_EYE_PLANE, v1);
|
||||
glEnable(GL_TEXTURE_GEN_S);
|
||||
float v2[4] = {tm[4], tm[5], tm[6], tm[7]};
|
||||
glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
|
||||
glTexGenfv(GL_T, GL_EYE_PLANE, v2);
|
||||
glEnable(GL_TEXTURE_GEN_T);
|
||||
float v3[4] = {tm[8], tm[9], tm[10], tm[11]};
|
||||
glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
|
||||
glTexGenfv(GL_R, GL_EYE_PLANE, v3);
|
||||
glEnable(GL_TEXTURE_GEN_R);
|
||||
float v4[4] = {tm[12], tm[13], tm[14], tm[15]};
|
||||
glTexGeni(GL_Q, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
|
||||
glTexGenfv(GL_Q, GL_EYE_PLANE, v4);
|
||||
glEnable(GL_TEXTURE_GEN_Q);
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, shadowmap_texture);
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE_ARB, GL_COMPARE_R_TO_TEXTURE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC_ARB, GL_LEQUAL);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_DEPTH_TEXTURE_MODE_ARB, GL_INTENSITY);
|
||||
glAlphaFunc(GL_GEQUAL, 0.99f);
|
||||
glEnable(GL_ALPHA_TEST);
|
||||
|
||||
//glMatrixMode(GL_MODELVIEW);
|
||||
for (int i = 0; i < app.cm->chunk_count; i++) {
|
||||
chunk_render(&app.cm->chunks[i]);
|
||||
//printf("c sp: %f\n", app.chunks[i].start_pos.x);
|
||||
}
|
||||
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
|
||||
glDisable(GL_TEXTURE_GEN_S);
|
||||
glDisable(GL_TEXTURE_GEN_T);
|
||||
glDisable(GL_TEXTURE_GEN_R);
|
||||
glDisable(GL_TEXTURE_GEN_Q);
|
||||
|
||||
glDisable(GL_LIGHTING);
|
||||
glDisable(GL_ALPHA_TEST);
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glPushMatrix();
|
||||
glLoadIdentity();
|
||||
gluOrtho2D(-1.0f, 1.0f, -1.0f, 1.0f);
|
||||
|
||||
glOrtho(0, 1600, 900, 0, -1, 1);
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glPushMatrix();
|
||||
glLoadIdentity();
|
||||
glLoadIdentity();
|
||||
|
||||
glColor3f(1, 0, 0);//white
|
||||
glLineWidth(2.0);
|
||||
glBegin(GL_LINES);
|
||||
//horizontal line
|
||||
glVertex2i(1600 / 2 - 7, 900 / 2);
|
||||
glVertex2i(1600 / 2 + 7, 900 / 2);
|
||||
glEnd();
|
||||
//vertical line
|
||||
glBegin(GL_LINES);
|
||||
glVertex2i(1600 / 2, 900 / 2 + 7);
|
||||
glVertex2i(1600 / 2, 900 / 2 - 7);
|
||||
glEnd();
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glPopMatrix();
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glPopMatrix();
|
||||
|
||||
glFinish();
|
||||
////////////
|
||||
vec3f pos = app.camera.position;
|
||||
// vec3f dir = get_camera_dir_vec3f(&app.camera);
|
||||
vec3f dir = get_camera_dir_vec3f(&app.camera);
|
||||
|
||||
// draw_cube(&app, pos.x + dir.x*3, pos.y + dir.y*3, pos.z + dir.z*3);
|
||||
draw_cube(app.cm, 0, pos.x + dir.x * 2, pos.y + dir.y * 2, pos.z + dir.z * 2, 1.0);
|
||||
|
||||
SDL_GL_SwapWindow(app.window);
|
||||
|
||||
clock_gettime(CLOCK_MONOTONIC_RAW, &end);
|
||||
app.frame_time = calc_frame_time(&start, &end);
|
||||
|
||||
printf("fps: %f\n", 1000/app.frame_time);
|
||||
//printf("fps: %f\n", 1000/app.frame_time);
|
||||
//printf("lkat pos x: %f y: %f z: %f\n", pos.x+5*dir.x, pos.y+5*dir.y, pos.z+5*dir.z);
|
||||
printf("camera x: %f y: %f z: %f\n", pos.x, pos.y, pos.z);
|
||||
//printf("camera x: %f y: %f z: %f\n", pos.x, pos.y, pos.z);
|
||||
//printf("dir x: %f y: %f z: %f\n", dir.x, dir.y, dir.z);
|
||||
printf("dird x: %f y: %f z: %f\n", app.camera.rotation.x, app.camera.rotation.y, app.camera.rotation.z);
|
||||
//printf("dird x: %f y: %f z: %f\n", app.camera.rotation.x, app.camera.rotation.y, app.camera.rotation.z);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
256
src/main1.c
Normal file
256
src/main1.c
Normal file
@ -0,0 +1,256 @@
|
||||
#include "../include/app.h"
|
||||
#include <GL/gl.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
#include <GL/glu.h>
|
||||
|
||||
#define SHADOWMAP_SIZE 4096
|
||||
|
||||
void set_light_pos(const vec3f p, float matrix[16])
|
||||
{
|
||||
glLoadIdentity();
|
||||
gluLookAt(p.x, p.y, p.z,
|
||||
4.0, 4.0, 10.0,
|
||||
0.0, 0.0, 1.0);
|
||||
glGetFloatv(GL_MODELVIEW_MATRIX, matrix);
|
||||
}
|
||||
int main()
|
||||
{
|
||||
struct timespec start;
|
||||
struct timespec end;
|
||||
App app;
|
||||
ChunkManager cm;
|
||||
app.cm = &cm;
|
||||
init_app(&app, 1600, 900);
|
||||
|
||||
/////
|
||||
vec3f light_pos = { .x = 40, .y = 40, .z = 80};
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
|
||||
glShadeModel(GL_SMOOTH);
|
||||
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
|
||||
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
|
||||
|
||||
glClearDepth(1.0f);
|
||||
glDepthFunc(GL_LEQUAL);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
//glEnable(GL_CULL_FACE);
|
||||
|
||||
glEnable(GL_NORMALIZE);
|
||||
|
||||
|
||||
GLuint shadowmap_texture;
|
||||
|
||||
float light_proj_matrix[16];
|
||||
float light_view_matrix[16];
|
||||
float cam_proj_matrix[16];
|
||||
float cam_view_matrix[16];
|
||||
|
||||
glGenTextures(1, &shadowmap_texture);
|
||||
glBindTexture(GL_TEXTURE_2D, shadowmap_texture);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24,
|
||||
SHADOWMAP_SIZE, SHADOWMAP_SIZE, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, NULL);
|
||||
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
|
||||
glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
|
||||
glEnable(GL_COLOR_MATERIAL);
|
||||
|
||||
GLfloat materialColor[] = {1.0f, 1.0f, 1.0f, 1.0f};
|
||||
glMaterialfv(GL_FRONT, GL_SPECULAR, materialColor);
|
||||
glMaterialf(GL_FRONT, GL_SHININESS, 64.0f);
|
||||
|
||||
|
||||
|
||||
|
||||
//reshape(1600, 900);
|
||||
glPushMatrix();
|
||||
glLoadIdentity();
|
||||
gluPerspective(45.0f, (float)1600/900, 1.0f, 10000.0f);
|
||||
glGetFloatv(GL_MODELVIEW_MATRIX, cam_proj_matrix);
|
||||
|
||||
|
||||
|
||||
glLoadIdentity();
|
||||
gluPerspective(80.0, 1.0, 2.0, 10000.0);
|
||||
glGetFloatv(GL_MODELVIEW_MATRIX, light_proj_matrix);
|
||||
|
||||
glLoadIdentity();
|
||||
set_light_pos(light_pos, light_view_matrix);
|
||||
|
||||
glPopMatrix();
|
||||
/////
|
||||
while(app.is_running) {
|
||||
clock_gettime(CLOCK_MONOTONIC_RAW, &start);
|
||||
|
||||
light_pos.x += 5*(app.frame_time/1000);
|
||||
set_light_pos(light_pos, light_view_matrix);
|
||||
app.camera.position.x = light_pos.x;
|
||||
app.camera.position.y = light_pos.y;
|
||||
app.camera.position.z = light_pos.z;
|
||||
printf("light pos: %f %f %f\n", light_pos.x, light_pos.y, light_pos.z);
|
||||
|
||||
vec3f cd = get_camera_dir_vec3f(&app.camera);
|
||||
vec3f cp = app.camera.position;
|
||||
|
||||
// glLoadIdentity();
|
||||
// gluLookAt(cp.x, cp.y, cp.z,
|
||||
// 10.0, 10.0, 30.0,
|
||||
// 0.0, 0.0, 1.0);
|
||||
set_view(&app.camera);
|
||||
glGetFloatv(GL_MODELVIEW_MATRIX, cam_view_matrix);
|
||||
|
||||
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadMatrixf(light_proj_matrix);
|
||||
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadMatrixf(light_view_matrix);
|
||||
|
||||
glViewport(0, 0, SHADOWMAP_SIZE, SHADOWMAP_SIZE);
|
||||
|
||||
glCullFace(GL_FRONT);
|
||||
|
||||
glShadeModel(GL_FLAT);
|
||||
glColorMask(0, 0, 0, 0);
|
||||
|
||||
for (int i = 0; i < app.cm->chunk_count; i++) {
|
||||
chunk_render(&app.cm->chunks[i]);
|
||||
//printf("c sp: %f\n", app.chunks[i].start_pos.x);
|
||||
}
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, shadowmap_texture);
|
||||
glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, SHADOWMAP_SIZE, SHADOWMAP_SIZE);
|
||||
|
||||
glCullFace(GL_BACK);
|
||||
//glDisable(GL_CULL_FACE);
|
||||
glShadeModel(GL_SMOOTH);
|
||||
glColorMask(1, 1, 1, 1);
|
||||
|
||||
glClear(GL_DEPTH_BUFFER_BIT);
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadMatrixf(cam_proj_matrix);
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadMatrixf(cam_view_matrix);
|
||||
glViewport(0, 0, 1600, 900);
|
||||
///////////////
|
||||
|
||||
handle_events(&app);
|
||||
update_app(&app);
|
||||
|
||||
float color1[4] = {0, 0, 0, 0};
|
||||
float color2[4] = {0, 0, 0, 0};
|
||||
float color3[4] = {1.0, 1.0, 1.0, 0.0};
|
||||
float light_pos[4] = {80, 80, 90, 0};
|
||||
glLightfv(GL_LIGHT1, GL_POSITION, light_pos);
|
||||
glLightfv(GL_LIGHT1, GL_AMBIENT, color1);
|
||||
glLightfv(GL_LIGHT1, GL_DIFFUSE, color1);
|
||||
glLightfv(GL_LIGHT1, GL_SPECULAR, color2);
|
||||
glEnable(GL_LIGHT1);
|
||||
glEnable(GL_LIGHTING);
|
||||
|
||||
//glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
//set_view(&app.camera);
|
||||
for (int i = 0; i < app.cm->chunk_count; i++) {
|
||||
GLuint t = get_texture(app.cm, BLOCKTYPE_DIRT);
|
||||
glBindTexture(t, GL_TEXTURE_2D);
|
||||
chunk_render(&app.cm->chunks[i]);
|
||||
//printf("c sp: %f\n", app.chunks[i].start_pos.x);
|
||||
}
|
||||
|
||||
glLightfv(GL_LIGHT1, GL_DIFFUSE, color3);
|
||||
glLightfv(GL_LIGHT1, GL_SPECULAR, color3);
|
||||
float bias[16] = {0.5f, 0.0f, 0.0f, 0.0f,
|
||||
0.0f, 0.5f, 0.0f, 0.0f,
|
||||
0.0f, 0.0f, 0.5f, 0.0f,
|
||||
0.5f, 0.5f, 0.5f, 1.0f};
|
||||
float m1[16];
|
||||
float tm[16];
|
||||
mult_matrix(bias, light_proj_matrix, m1);
|
||||
mult_matrix(m1, light_view_matrix, tm);
|
||||
|
||||
float v1[4] = {tm[0], tm[1], tm[2], tm[3]};
|
||||
glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
|
||||
glTexGenfv(GL_S, GL_EYE_PLANE, v1);
|
||||
glEnable(GL_TEXTURE_GEN_S);
|
||||
float v2[4] = {tm[4], tm[5], tm[6], tm[7]};
|
||||
glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
|
||||
glTexGenfv(GL_T, GL_EYE_PLANE, v2);
|
||||
glEnable(GL_TEXTURE_GEN_T);
|
||||
float v3[4] = {tm[8], tm[9], tm[10], tm[11]};
|
||||
glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
|
||||
glTexGenfv(GL_R, GL_EYE_PLANE, v3);
|
||||
glEnable(GL_TEXTURE_GEN_R);
|
||||
float v4[4] = {tm[12], tm[13], tm[14], tm[15]};
|
||||
glTexGeni(GL_Q, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
|
||||
glTexGenfv(GL_Q, GL_EYE_PLANE, v4);
|
||||
glEnable(GL_TEXTURE_GEN_Q);
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, shadowmap_texture);
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE_ARB, GL_COMPARE_R_TO_TEXTURE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC_ARB, GL_LEQUAL);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_DEPTH_TEXTURE_MODE_ARB, GL_INTENSITY);
|
||||
glAlphaFunc(GL_GEQUAL, 0.99f);
|
||||
glEnable(GL_ALPHA_TEST);
|
||||
|
||||
//glMatrixMode(GL_MODELVIEW);
|
||||
for (int i = 0; i < app.cm->chunk_count; i++) {
|
||||
chunk_render(&app.cm->chunks[i]);
|
||||
//printf("c sp: %f\n", app.chunks[i].start_pos.x);
|
||||
}
|
||||
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
|
||||
glDisable(GL_TEXTURE_GEN_S);
|
||||
glDisable(GL_TEXTURE_GEN_T);
|
||||
glDisable(GL_TEXTURE_GEN_R);
|
||||
glDisable(GL_TEXTURE_GEN_Q);
|
||||
|
||||
glDisable(GL_LIGHTING);
|
||||
glDisable(GL_ALPHA_TEST);
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glPushMatrix();
|
||||
glLoadIdentity();
|
||||
gluOrtho2D(-1.0f, 1.0f, -1.0f, 1.0f);
|
||||
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glPushMatrix();
|
||||
glLoadIdentity();
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glPopMatrix();
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glPopMatrix();
|
||||
|
||||
glFinish();
|
||||
////////////
|
||||
vec3f pos = app.camera.position;
|
||||
// vec3f dir = get_camera_dir_vec3f(&app.camera);
|
||||
|
||||
// draw_cube(&app, pos.x + dir.x*3, pos.y + dir.y*3, pos.z + dir.z*3);
|
||||
|
||||
SDL_GL_SwapWindow(app.window);
|
||||
|
||||
clock_gettime(CLOCK_MONOTONIC_RAW, &end);
|
||||
app.frame_time = calc_frame_time(&start, &end);
|
||||
|
||||
printf("fps: %f\n", 1000/app.frame_time);
|
||||
//printf("lkat pos x: %f y: %f z: %f\n", pos.x+5*dir.x, pos.y+5*dir.y, pos.z+5*dir.z);
|
||||
printf("camera x: %f y: %f z: %f\n", pos.x, pos.y, pos.z);
|
||||
//printf("dir x: %f y: %f z: %f\n", dir.x, dir.y, dir.z);
|
||||
printf("dird x: %f y: %f z: %f\n", app.camera.rotation.x, app.camera.rotation.y, app.camera.rotation.z);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
@ -193,3 +193,9 @@ void print_vec3f(vec3f v, const char *str)
|
||||
{
|
||||
printf("%s x: %f y: %f z: %f\n", str, v.x, v.y, v.z);
|
||||
}
|
||||
|
||||
float frand_range(float min, float max)
|
||||
{
|
||||
float scale = rand() / (float) RAND_MAX;
|
||||
return min + scale * ( max - min );
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user