Answer the question
In order to leave comments, you need to log in
How to move the "camera" in the direction of its direction to set the blocks?
I welcome everyone. I very very rarely ask anything on the forums, but today is an exception.
I decided to just have fun and write my own lane clone. Questions "why write in outdated OpenGL 1.x, in C, and even a clone of the game." And I will answer you that purely for fun. Don't ask.
Everything seemed to be going smoothly until I got to the block staking/destroying system. Remarkably cheating off the internet by writing the code, it didn't work. I started trying to fix it, googled only where possible. But I couldn't find anything suitable for me anywhere. If it's not difficult for anyone, could you write something about this?
Blocks are stored very simply, in the world variable. For example, "world[2][3][1][15][203] = 2;" will put a block of grass (ID 2) in chunk 2 in X, in chunk 3 in Y, and at coordinates 1x, 15y, 203z in that chunk.
Camera coordinates are stored in camera.x, camera.y, camera.z. Rotation angle - camera.Xrot ,
camera.Zrot
case WM_RBUTTONDOWN:
if(camera.x < 0 || camera.x >= 256 || camera.y < 0 || camera.y >= 256 || camera.z < 0 || camera.z >= 256) break; // сделал чтобы не выходили за границы массива
float x = camera.x;
float y = camera.y;
float z = camera.z + 1.7; // прибавляю + 1,7 чтобы было из глаз персонажа
int X, Y, Z, oldX, oldY, oldZ;
int dist = 0;
while(dist < 4) // ограничение дальности, где можно ставить блоки
{
dist++;
x += sin(camera.Zrot/180*M_PI); // Самые важные три строчки, но поскольку я ничего не понимаю в тригонометрии, скорее всего тут написан какой-то бред. Простите.
y += cos(camera.Xrot/180*M_PI);
z += tan(camera.Xrot/180*M_PI);
int chunkx = x / 16;
int chunky = y / 16; // узнаю координаты чанка
int dcx = 16*chunkx;
int dcy = 16*chunky;
X = x - dcx;
Y = y - dcy;
Z = z; // узнаю координаты именно для чанка
if(world[chunkx][chunky][X][Y][Z] != 0) // если столкнулись с предметом
{
world[chunkx][chunky][X][Y][Z] = 0; // убираем блок
break;
}
oldX=X; oldY = Y; oldZ = Z; // записываем старые коорды(чтобы потом добавить возможность ставить блоки, а так тут пока не используются)
}
break;
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question