///////////////////////////////
#include <acknex.h>
#include <default.c>
#include <stdio.h>
///////////////////////////////
void createFile();
void createAdvanced();
void clickAround();
BMAP *sand = "b1.tga";
BMAP *gras = "b2.tga";
STRING *line = "";
ENTITY *wall;
void main()
{
mouse_mode = 4;
mouse_pointer = 2;
mouse_sync = 1;
video_switch(10, 32, 2);
wait(1);
level_load("");
createAdvanced();
camera.pan = 90;
camera.y = -512;
camera->flags |= ISOMETRIC;
camera.arc = 20;
clickAround();
}
void clickAround()
{
VECTOR to;
while(1)
{
if(mouse_left)
{
vec_set(to, mouse_dir3d);
vec_scale(to, 1000);
vec_add(to,mouse_pos3d);
c_trace(mouse_pos3d, to, USE_POLYGON | SCAN_TEXTURE);
if(hit.entity != NULL)
{
ENTITY *w = hit.entity;
var s = hit.triangle;
if(s % 2 != 0) { s++; }
s /= 2;
int v1 = ((s - 1) * 4) + 1;
CONTACT *c = ent_getvertex(w, NULL, v1);
c.v = NULL;
c.x += 8;
ent_setvertex(w, c, v1);
c = ent_getvertex(w, NULL, v1 + 1);
c.v = NULL;
c.x -= 8;
ent_setvertex(w, c, v1 + 1);
c = ent_getvertex(w, NULL, v1 + 2);
c.v = NULL;
c.x += 8;
ent_setvertex(w, c, v1 + 2);
c = ent_getvertex(w, NULL, v1 + 3);
c.v = NULL;
c.x -= 8;
ent_setvertex(w, c, v1 + 3);
}
while(mouse_left) { wait(1); }
}
wait(1);
}
}
void createAdvanced()
{
int px, py;
int x, y;
double rx, ry;
int i = 0;
STRING *f = str_create("");
int mesh = 0;
BMAP *map01 = bmap_createblack(320, 320, 32);
for(px = 0; px < 1; px++)
{
for(py = 0; py < 1; py++)
{
str_printf(f, "mesh%.0f.obj", (double)mesh);
FILE *file = fopen(f.chars, "wb");
for(y = 0; y < 20; y++)
{
for(x = 0; x < 20; x++)
{
rx = x * 8;
ry = -y * 8;
str_printf(line, "v %.0f %.0f 0\n", rx, ry);
fputs(line.chars, file);
str_printf(line, "v %.0f %.0f 0\n", rx + 8, ry);
fputs(line.chars, file);
str_printf(line, "v %.0f %.0f 0\n", rx, ry - 8);
fputs(line.chars, file);
str_printf(line, "v %.0f %.0f 0\n", rx + 8, ry - 8);
fputs(line.chars, file);
}
}
fputs("\n", file);
for(y = 0; y < 20; y++)
{
for(x = 0; x < 20; x++)
{
str_printf(line, "vt %.3f %.3f\n", (double)x / 20.0, (double)y / 20.0);
fputs(line.chars, file);
str_printf(line, "vt %.3f %.3f\n", ((double)x + 1) / 20.0, (double)y / 20.0);
fputs(line.chars, file);
str_printf(line, "vt %.3f %.3f\n", (double)x / 20.0, ((double)y + 1) / 20.0);
fputs(line.chars, file);
str_printf(line, "vt %.3f %.3f\n", ((double)x + 1) / 20.0, ((double)y +1) / 20.0);
fputs(line.chars, file);
bmap_blit(map01, sand, vector(x * 16, y * 16, 0), NULL);
}
}
fputs("\n", file);
for(i = 0; i < 400; i++)
{
double v1 = i * 4 + 1;
double v2 = v1 + 1;
double v3 = v1 + 2;
double v4 = v1 + 3;
str_printf(line, "g plane%.0f\n", (double)i);
fputs(line.chars, file);
str_printf(line, "f %.0f/%.0f %.0f/%.0f %.0f/%.0f\n", v3, v3, v2, v2, v1, v1);
fputs(line.chars, file);
str_printf(line, "f %.0f/%.0f %.0f/%.0f %.0f/%.0f\n", v3, v3, v4, v4, v2, v2);
fputs(line.chars, file);
}
fclose(file);
wall = ent_create(f, vector(px * 160, 0, py * 160), NULL);
ent_setskin(wall, map01, 1);
mesh++;
}
}
str_remove(f);
}