Форум русскоязычного сообщества Ubuntu


За новостями русскоязычного сообщества и Ubuntu в целом можно следить на нашей страничке в Google+

Автор Тема: C - OpenGL - Camera + Car (Камеры в машины)  (Прочитано 145 раз)

0 Пользователей и 1 Гость просматривают эту тему.

Оффлайн victor00000

  • Автор темы
  • Старожил
  • *
  • Сообщений: 14958
  • Я не слышу.
    • Просмотр профиля
C - OpenGL - Camera + Car (Камеры в машины)
« : 31 Декабрь 2018, 20:31:24 »
// camera_car.c
// 0.4
// victor00000 (c) 2018
// Душинский Виктор Викторович.

// ~$ gcc camera_car.c -o camera_car -lGL -lGLU -lglut
// ~$ ./camera_car
// keyboard:
// 'space' - goto camera
// 'enter' - goto car
// 'esc' - exit

#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <GL/gl.h>
#include <GL/glut.h>
#include <GL/glu.h>
#include <GL/freeglut_ext.h>

//=====================
float cv[3], gv[3],gm[3];
float m16[16];
int camerai, cr, gr;
typedef struct {
float x, y, z, m[16];
} camera0;
camera0 camera[20];
int btrue = 0, gari;
typedef struct {
float m[16];
float shag, shagm, ltr;
int b;
} gar0;
gar0 gar[30];
float r = 0;
int t1 = 0;

//=================
void gl_getm16to3(float *m, float *f);
void gl_getm3(float *f);
void gl_cube_size(float x, float y, float z);

//=========================
int gl_ticksleep (int t0){
if (t1 == 0){
t1 = glutGet ( GLUT_ELAPSED_TIME );
return 0;
}
int t2 = glutGet ( GLUT_ELAPSED_TIME );
int t3 = t0 - (t2-t1);
if (t3 > 0){
// printf ("%d\n",t3);
usleep ( 1000 * t3 );
t1 = glutGet ( GLUT_ELAPSED_TIME );
return 0;
}
t1 = glutGet ( GLUT_ELAPSED_TIME );
return -1;
}

//===================
void gl_getm16(float *m)
{
glGetFloatv(GL_MODELVIEW_MATRIX, m);
}

//=================

//===============
void gl_shar(float sz, float x, float y, float z)
{
glLineWidth(4);
float *cf = malloc(sizeof(float) * 4);

glGetFloatv(GL_CURRENT_COLOR, cf);
glPushMatrix();

glTranslatef(x, y, z);
glutSolidSphere(sz, 10, 10);
glColor4f(0, 0, 0, 0);
glutWireSphere(sz, 10, 10);
//=============a1
glPopMatrix();
glColor4fv(cf);
free(cf);
}

//=================
void gl_gar(const char *c)
{

float *cf = malloc(sizeof(float) * 4);

glGetFloatv(GL_CURRENT_COLOR, cf);

glPushMatrix();
gl_cube_size(1, .05, 2);

glColor4f(0, 0, 0, 0);
glLineWidth(4);
// glutWireSphere (1,10,10);
glColor4fv(cf);

//=============l1
glPushMatrix();
glTranslatef(0, .1 + (.1 / 2), 0);
gl_cube_size(1, .1, 1);
glPushMatrix();
glTranslatef(0, .1 + (.3 / 2), .5);
gl_cube_size(.8, .3, .5);
glPopMatrix();
//===========l2
glTranslatef(0, .1 + (.2 / 2), -.3);
gl_cube_size(.5, .2, 1);
glPopMatrix();

//=============t1
glPushMatrix();
glColor4f(0, 0, 0, 0);
float s = .002, *m3 = malloc(sizeof(float) * 3);

gl_getm3(m3);
glLoadIdentity();
glTranslatef(m3[0], m3[1], m3[2]);
free(m3);
//=========t2
glLineWidth(8);
glTranslatef(0, .6, 0);
glScalef(s, s, s);
glutStrokeString(GLUT_STROKE_ROMAN, (uint8_t *) c);
glPopMatrix();

glLineWidth(3);
glColor4fv(cf);
//==========r1
gl_shar(.2, 1.0f / 2, 0, .5 - 2.0f / 2);
//========r2
gl_shar(.2, -1.0f / 2, 0, .5 - 2.0f / 2);

//===========r3
gl_shar(.2, 1.0f / 2, 0, -.5 + 2.0f / 2);
//=========r4
gl_shar(.2, -1.0f / 2, 0, -.5 + 2.0f / 2);

glPopMatrix();
glColor4fv(cf);
free(cf);
glLineWidth(8);
}

//=================
void gl_getm16to3(float *m, float *f)
{
// float *m = malloc (sizeof (
// float)*16 );
//glGetFloatv (
// GL_MODELVIEW_MATRIX  , m );
f[0] = m[0] * m[4] * m[8] + m[12];
f[1] = m[1] * m[5] * m[9] + m[13];
f[2] = m[2] * m[6] * m[10] + m[14];
// free (m);
}

//=================
void gl_getm3(float *f)
{
float *m = malloc(sizeof(float) * 16);

glGetFloatv(GL_MODELVIEW_MATRIX, m);
f[0] = m[0] * m[4] * m[8] + m[12];
f[1] = m[1] * m[5] * m[9] + m[13];
f[2] = m[2] * m[6] * m[10] + m[14];
free(m);
}

//=======================
void gl_camera(float up, const char *c)
{
glPushMatrix();
gl_cube_size(1, .1, 1);

glTranslatef(0, .1, 0);
glTranslatef(0, up / 2, 0);
gl_cube_size(.1, up, .1);

float *cf = malloc(sizeof(float) * 4);

glGetFloatv(GL_CURRENT_COLOR, cf);
glTranslatef(0, up / 2, 0);
glTranslatef(0, .3 / 2, 0);
glColor4f(0, 0, 0, 0);
glLineWidth(3);

glutWireCube(.3);
gl_getm16(m16);
glLineWidth(8);
glTranslatef(0, .3 / 2, 0);

// char *c = strdup ("123");
float *m3 = malloc(sizeof(float) * 3);

gl_getm3(m3);
glLoadIdentity();
glTranslatef(m3[0], m3[1], m3[2]);
glTranslatef(-.2, .1, 0);
free(m3);

float s = .002;

glScalef(s, s, s);
glutStrokeString(GLUT_STROKE_ROMAN, (uint8_t *) c);

// free (c);
//================s3
glColor4fv(cf);
free(cf);

glPopMatrix();
}

//=================
void gl_cube()
{

float *cf = malloc(sizeof(float) * 4);

glGetFloatv(GL_CURRENT_COLOR, cf);

glColor4f(0, 0, 0, 0);
glutWireCube(1);

glColor4fv(cf);
glutSolidCube(1);

free(cf);
}

//==================
void gl_cube_size(float x, float y, float z)
{
glPushMatrix();
glScalef(x, y, z);
gl_cube();
glPopMatrix();
}

//======================
void gl_clear()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}

//===================
void gl_display()
{
int i;

gl_clear();
if (btrue == 0) {
int l0 = 0;
for (i = 0; i < gari; i++) {
gar[i].b = 0;
glPushMatrix();

glTranslatef(10 + (-2.4f * (i%10)), 0,
l0 * -3 );
if (i%10 == 9 ) l0++;
gl_getm16(gar[i].m);
glPopMatrix();
gar[i].ltr = -1 + (rand() % 3);
if (gar[i].ltr == 0) {
gar[i].shag = 1 + (rand() % 5);
} else {
gar[i].shag = rand() % 90;
}
}

//===============cm1
for (i = 0; i < camerai; i++) {
glPushMatrix();
 cam1:
camera[i].x = -50 + (rand() % 100);
camera[i].z = -50 + (rand() % 100);
camera[i].y = 2 + (rand() % 10);

int ii;

for (ii = 0; ii < i; ii++) {
if (camera[i].x == camera[ii].x &&
    camera[i].z == camera[ii].z)
break;
}
if (ii != i)
goto cam1;

glTranslatef(camera[i].x, 0, camera[i].z);
gl_camera(camera[i].y, "0");
for (ii = 0; ii < 16; ii++) {
camera[i].m[ii] = m16[ii];
}
glPopMatrix();
}
cr = rand() % camerai;
gr = rand() % gari;
gl_getm16to3(camera[cr].m, cv);
gl_getm16to3(gar[gr].m, gv);

} else {
for (i = 0; i < gari; i++) {
glPushMatrix();
glLoadMatrixf(gar[i].m);

// glTranslatef (0,0,.01f);

if (gar[i].ltr == 0) {
glTranslatef(0, 0, .3);
gar[i].shag -= .3f;
}
if (gar[i].ltr == -1) {
glRotatef(-4, 0, 1, 0);

if (gar[i].b == 0)
glTranslatef (0,0,.1f);

gar[i].shag -= 4;
}
if (gar[i].ltr == 1) {
glRotatef(4, 0, 1, 0);

if (gar[i].b == 0)
glTranslatef (0,0,.1f);

gar[i].shag -= 4;
}
if (gar[i].shag < 0) {
gar[i].ltr = -1 + (rand() % 3);
if (gar[i].ltr == 0) {
gar[i].shag = 1 + (rand() % 5);
} else {
gar[i].shag = rand() % 90;
}
}
//===============g1
gl_getm3 (gm);
if ((gm[0] < 50 && gm[0] > -50 ) &&
( gm[2] < 50 && gm[2] > -50 )){
gl_getm16(gar[i].m);
gar[i].b = 0;
} else gar[i].b = 1;

glPopMatrix();
}
gl_getm16to3(gar[gr].m, gv);
}

btrue = 1;

gl_clear();
gluLookAt(cv[0], cv[1], cv[2], gv[0], gv[1], gv[2], 0, 1, 0);
glColor4f(1, 1, 1, 1);

//==================pole
glPushMatrix ();
glTranslatef (0,-.2/2,0);
gl_cube_size (100,.2,100);
glPopMatrix ();

// glTranslatef (0,-1,0);

//===============camera
glPushMatrix();
for (i = 0; i < camerai; i++) {
glPushMatrix();

glTranslatef(camera[i].x, 0, camera[i].z);
char *c;

asprintf(&c, "c%d", i + 1);
gl_camera(camera[i].y, c);
free(c);
glPopMatrix();
}
glPopMatrix();

//=================gar
glPushMatrix();
// glTranslatef (0,0,-4);
for (i = 0; i < gari; i++) {
glPushMatrix();

// glLoadMatrixf (gar[i].m);
glMultMatrixf(gar[i].m);
char *c;
asprintf(&c, "%d", i + 1);
gl_gar(c);
free(c);
glPopMatrix();
}
glPopMatrix();

glFlush();
// glutPostRedisplay();
if ( gl_ticksleep (30) == -1 )
// puts ("===| Error ticks loop CPU |====");
{}
else
glutSwapBuffers();
}

//====================
void gl_reshape(GLsizei width, GLsizei height)
{

if (height == 0)
height = 1;
GLfloat aspect = (GLfloat) width / (GLfloat) height;

glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0f, aspect, 0.1f, 150.0f);
}

//===============
void gl_kd(uint8_t k, int x, int y)
{
(void)x;
(void)y;
if (k == 13) {
gr += 1;
if (gr > gari - 1)
gr = 0;
gl_getm16to3(camera[cr].m, cv);
}

if (k == ' ') {
cr += 1;
if (cr > camerai - 1)
cr = 0;
gl_getm16to3(camera[cr].m, cv);
}

if (k == 27)
exit(0);
}

//==================m0
int main(int ia, char **ca)
{
gari = sizeof(gar) / sizeof(gar0);
camerai = sizeof(camera) / sizeof(camera0);
srand(time(0));
glutInit(&ia, ca);
glutInitDisplayMode(GLUT_DOUBLE);

glutInitWindowSize(
// 320,200);
  800, 600);
glutInitWindowPosition(50, 50);

// glutReshapeFunc ( gl_reshape );
glutCreateWindow("GL Camera Gar");
// glutDisplayFunc(gl_display);
glutIdleFunc ( gl_display );

//===========
glClearDepth(1.0f);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glShadeModel(GL_SMOOTH);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);

glClearColor(1.0f-.3, 1.0f-.3,
 1.0f-.3, 1.0f - .3);
glColor4f(0, 0, 0, 0);

glutReshapeFunc(gl_reshape);

glLineWidth(8);

glutKeyboardFunc(gl_kd);

glutFullScreen();
glutMainLoop();
return 0;
}

http://paste.ubuntu.com/p/9sXv6dBvpG/
« Последнее редактирование: 02 Январь 2019, 05:12:52 от victor00000 »
~.o

Оффлайн victor00000

  • Автор темы
  • Старожил
  • *
  • Сообщений: 14958
  • Я не слышу.
    • Просмотр профиля
Re: C - OpenGL - Camera + Car (Камеры в машины)
« Ответ #1 : 03 Январь 2019, 09:26:20 »
// camera_car.c
// 0.5
// victor00000 (c) 2018
// Душинский Виктор Викторович.

// ~$ gcc camera_car.c -o camera_car -lGL -lGLU -lglut
// ~$ ./camera_car
// keyboard:
// 'space' - goto camera
// 'enter' - goto car
// 'esc' - exit

#include <stdio.h>
#include <unistd.h>
#include <time.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <GL/gl.h>
#include <GL/glut.h>
#include <GL/glu.h>
#include <GL/freeglut_ext.h>

//=====================
float cv[3], gv[3],gm[3],cm[3];
float m16[16];
int camerai, cr, gr;
typedef struct {
float x, y, z, m[16];
} camera0;
camera0 camera[10];
int btrue = 0, gari;
typedef struct {
float m[16];
float shag, shagm, ltr;
int b;
} gar0;
gar0 gar[20];
float r = 0;
int t1 = 0;

//=================
void gl_getm16to3(float *m, float *f);
void gl_getm3(float *f);
void gl_cube_size(float x, float y, float z);

//==================
void gl_getz (float *z){
float *cf = malloc (sizeof (float)*4);
glGetFloatv(GL_CURRENT_COLOR, cf);
glColor4f ( 0, 0, 0, 0 );
glPushMatrix ();
glLoadIdentity();
glTranslatef (-.05,-.04,-.1);
glScalef (.0001,.00005,.0001);
char *c;
asprintf (&c,"meter: %-4.01f",z[2]*-1.0f);
glutStrokeString(GLUT_STROKE_ROMAN,
(uint8_t*) c);
free (c);
glPopMatrix ();
glColor4fv (cf);
free (cf);
}

//================
int gl_ifgg (int l){
int i;
gl_getm16to3 (gar[l].m,gm);
for (i=0;i<gari;i++){
if (l == i) continue;
gl_getm16to3 (gar[i].m,cm);

if (( gm[0] < cm[0] + 1 &&
gm[0] > cm [0] - 1 ) &&
( gm[2] < cm[2] + 1 &&
gm[2] > cm[2] - 1 ) ){
// puts ("===========");
// }else{
return 1;
}
}
return 0;
}

//================
int gl_ifgar (float *f3){
int i;
for (i=0;i<gari;i++){
gl_getm16to3 (gar[i].m,gm);
//====================g2
if ((
gm[0] < f3[0] + .5 &&
gm[0] > f3[0] - .5) &&
(
gm[2] < f3[2] + .5 &&
gm[2] > f3[2] - .5) ){
// }else{
return 1;
}
}
return 0;
}

//===================
int gl_ifcamera (float *f3){
int i;
for (i=0;i<camerai;i++){

if ((f3[0] <  camera [i].x + 1 &&
f3 [0] > camera[i].x - 1)  &&
(f3[2] < camera[i].z + 1 &&
f3[2] > camera[i].z - 1) ){
// printf ("%d\n",i);
return 1;
}
}
return 0;
}

//=========================
int gl_ticksleep (int t0){
if (t1 == 0){
t1 = glutGet ( GLUT_ELAPSED_TIME );
return 0;
}
int t2 = glutGet ( GLUT_ELAPSED_TIME );
int t3 = t0 - (t2-t1);
if (t3 > 0){
// printf ("%d\n",t3);
usleep ( 1000 * t3 );
t1 = glutGet ( GLUT_ELAPSED_TIME );
return 0;
}
t1 = glutGet ( GLUT_ELAPSED_TIME );
return -1;
}

//===================
void gl_getm16(float *m)
{
glGetFloatv(GL_MODELVIEW_MATRIX, m);
}

//=================

//===============
void gl_shar(float sz, float x, float y, float z)
{
glLineWidth(4);
float *cf = malloc(sizeof(float) * 4);

glGetFloatv(GL_CURRENT_COLOR, cf);
glPushMatrix();

glTranslatef(x, y, z);
glutSolidSphere(sz, 10, 10);
glColor4f(0, 0, 0, 0);
glutWireSphere(sz, 10, 10);
//=============a1
glPopMatrix();
glColor4fv(cf);
free(cf);
}

//=================
void gl_gar(const char *c)
{

float *cf = malloc(sizeof(float) * 4);

glGetFloatv(GL_CURRENT_COLOR, cf);

glPushMatrix();
gl_cube_size(1, .05, 2);

glColor4f(0, 0, 0, 0);
glLineWidth(4);
// glutWireSphere (1,10,10);
glColor4fv(cf);

//=============l1
glPushMatrix();
glTranslatef(0, .1 + (.1 / 2), 0);
gl_cube_size(1, .1, 1);
glPushMatrix();
glTranslatef(0, .1 + (.3 / 2), .5);
gl_cube_size(.8, .3, .5);
glPopMatrix();
//===========l2
glTranslatef(0, .1 + (.2 / 2), -.3);
gl_cube_size(.5, .2, 1);
glPopMatrix();

//=============t1
glPushMatrix();
glColor4f(0, 0, 0, 0);
float s = .002, *m3 = malloc(sizeof(float) * 3);

gl_getm3(m3);
glLoadIdentity();
glTranslatef(m3[0], m3[1], m3[2]);
free(m3);
//=========t2
glLineWidth(8);
glTranslatef(0, .6, 0);
glScalef(s, s, s);
glutStrokeString(GLUT_STROKE_ROMAN, (uint8_t *) c);
glPopMatrix();

glLineWidth(3);
glColor4fv(cf);
//==========r1
gl_shar(.2, 1.0f / 2, 0, .5 - 2.0f / 2);
//========r2
gl_shar(.2, -1.0f / 2, 0, .5 - 2.0f / 2);

//===========r3
gl_shar(.2, 1.0f / 2, 0, -.5 + 2.0f / 2);
//=========r4
gl_shar(.2, -1.0f / 2, 0, -.5 + 2.0f / 2);

glPopMatrix();
glColor4fv(cf);
free(cf);
glLineWidth(8);
}

//=================
void gl_getm16to3(float *m, float *f)
{
// float *m = malloc (sizeof (
// float)*16 );
//glGetFloatv (
// GL_MODELVIEW_MATRIX  , m );
f[0] = m[0] * m[4] * m[8] + m[12];
f[1] = m[1] * m[5] * m[9] + m[13];
f[2] = m[2] * m[6] * m[10] + m[14];
// free (m);
}

//=================
void gl_getm3(float *f)
{
float *m = malloc(sizeof(float) * 16);

glGetFloatv(GL_MODELVIEW_MATRIX, m);
f[0] = m[0] * m[4] * m[8] + m[12];
f[1] = m[1] * m[5] * m[9] + m[13];
f[2] = m[2] * m[6] * m[10] + m[14];
free(m);
}

//=======================
void gl_camera(float up, const char *c)
{
glPushMatrix();
gl_cube_size(1, .1, 1);

glTranslatef(0, .1, 0);
glTranslatef(0, up / 2, 0);
gl_cube_size(.1, up, .1);

float *cf = malloc(sizeof(float) * 4);

glGetFloatv(GL_CURRENT_COLOR, cf);
glTranslatef(0, up / 2, 0);
glTranslatef(0, .3 / 2, 0);
glColor4f(0, 0, 0, 0);
glLineWidth(3);

glutWireCube(.3);
gl_getm16(m16);
glLineWidth(8);
glTranslatef(0, .3 / 2, 0);

// char *c = strdup ("123");
float *m3 = malloc(sizeof(float) * 3);

gl_getm3(m3);
glLoadIdentity();
glTranslatef(m3[0], m3[1], m3[2]);
glTranslatef(-.2, .1, 0);
free(m3);

float s = .002;

glScalef(s, s, s);
glutStrokeString(GLUT_STROKE_ROMAN, (uint8_t *) c);

// free (c);
//================s3
glColor4fv(cf);
free(cf);

glPopMatrix();
}

//=================
void gl_cube()
{

float *cf = malloc(sizeof(float) * 4);

glGetFloatv(GL_CURRENT_COLOR, cf);

glColor4f(0, 0, 0, 0);
glutWireCube(1);

glColor4fv(cf);
glutSolidCube(1);

free(cf);
}

//==================
void gl_cube_size(float x, float y, float z)
{
glPushMatrix();
glScalef(x, y, z);
gl_cube();
glPopMatrix();
}

//======================
void gl_clear()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}

//===================
void gl_display()
{
int i;

gl_clear();
if (btrue == 0) {
int l0 = 0;
for (i = 0; i < gari; i++) {
gar[i].b = 0;
glPushMatrix();

glTranslatef(10 + (-2.4f * (i%10)), 0,
l0 * -3 );
if (i%10 == 9 ) l0++;
gl_getm16(gar[i].m);
glPopMatrix();
gar[i].ltr = -1 + (rand() % 3);
if (gar[i].ltr == 0) {
gar[i].shag = 1 + (rand() % 5);
} else {
gar[i].shag = rand() % 90;
}
}

//===============cm1
for (i = 0; i < camerai; i++) {
glPushMatrix();
 cam1:
camera[i].x = -50 + (rand() % 100);
camera[i].z = -50 + (rand() % 100);
camera[i].y = 1 + (rand() % 10);

int ii;

for (ii = 0; ii < i; ii++) {
if (camera[i].x == camera[ii].x &&
    camera[i].z == camera[ii].z)
break;
}
if (ii != i)
goto cam1;

//==================ifc
cm [1] = 0;
cm [0] = camera [i].x;
cm [2] = camera [i].z;
if (gl_ifgar(cm) == 1)
goto cam1;


glTranslatef(camera[i].x, 0, camera[i].z);
gl_camera(camera[i].y, "0");
for (ii = 0; ii < 16; ii++) {
camera[i].m[ii] = m16[ii];
}
glPopMatrix();
}
cr = rand() % camerai;
gr = rand() % gari;
gl_getm16to3(camera[cr].m, cv);
gl_getm16to3(gar[gr].m, gv);

} else {
for (i = 0; i < gari; i++) {
glPushMatrix();
glLoadMatrixf(gar[i].m);

// glTranslatef (0,0,.01f);

if (gar[i].ltr == 0) {

// if (gar[i].b != 0)
// glTranslatef(0, 0, 1);

glTranslatef(0, 0, .3);
gar[i].shag -= .3f;
}
if (gar[i].ltr == -1) {
glRotatef(-4, 0, 1, 0);

if (gar[i].b == 0)
glTranslatef (0,0,.2f);

gar[i].shag -= 4;
}
if (gar[i].ltr == 1) {
glRotatef(4, 0, 1, 0);

if (gar[i].b == 0)
glTranslatef (0,0,.2f);

gar[i].shag -= 4;
}
if (gar[i].shag < 0) {
gar[i].ltr = -1 + (rand() % 3);
if (gar[i].ltr == 0) {
gar[i].shag = 1 + (rand() % 5);
} else {
gar[i].shag = rand() % 90;
}
}
//===============g1
gl_getm3 (gm);
if (
// (gl_ifgg(i) == 0) &&
// (gl_ifcamera (gm) == 0) &&
((gm[0] < 50 && gm[0] > -50 ) &&
( gm[2] < 50 && gm[2] > -50 ))){

// if (gl_ifgg(i) == 0){
gl_getm16(gar[i].m);
gar[i].b = 0;

if (gl_ifcamera (gm) != 0)
gar[i].b = 1;
if (gl_ifgg(i) != 0)
gar[i].b = 1;


// } else gar[i].b = 1;
} else gar[i].b = 1;

glPopMatrix();
}
gl_getm16to3(gar[gr].m, gv);
}

btrue = 1;

gl_clear();
gluLookAt(cv[0], cv[1], cv[2], gv[0], gv[1], gv[2], 0, 1, 0);
glColor4f(1, 1, 1, 1);

//==================pole
glPushMatrix ();
glTranslatef (0,-.2/2,0);
gl_cube_size (100,.2,100);
glPopMatrix ();

// glTranslatef (0,-1,0);

//===============camera
glPushMatrix();
for (i = 0; i < camerai; i++) {
glPushMatrix();

glTranslatef(camera[i].x, 0, camera[i].z);
char *c;

asprintf(&c, "c%d", i + 1);
gl_camera(camera[i].y, c);
free(c);
glPopMatrix();
}
glPopMatrix();

//=================gar
glPushMatrix();
// glTranslatef (0,0,-4);
for (i = 0; i < gari; i++) {
glPushMatrix();

// glLoadMatrixf (gar[i].m);
glMultMatrixf(gar[i].m);
if (i == gr )
{gl_getm3 (gm);
gl_getz (gm);
}
char *c;
asprintf(&c, "%d", i + 1);
gl_gar(c);
free(c);
glPopMatrix();
}
glPopMatrix();

glFlush();
// glutPostRedisplay();
if ( gl_ticksleep (30) == -1 )
// puts ("===| Error ticks loop CPU |====");
{}
else
glutSwapBuffers();
}

//====================
void gl_reshape(GLsizei width, GLsizei height)
{

if (height == 0)
height = 1;
GLfloat aspect = (GLfloat) width / (GLfloat) height;

glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0f, aspect,
0.1f, 150.0f);
}

//===============
void gl_kd(uint8_t k, int x, int y)
{
(void)x;
(void)y;
if (k == 13) {
gr += 1;
if (gr > gari - 1)
gr = 0;
gl_getm16to3(camera[cr].m, cv);
}

if (k == ' ') {
cr += 1;
if (cr > camerai - 1)
cr = 0;
gl_getm16to3(camera[cr].m, cv);
}

if (k == 27)
exit(0);
}

//==================m0
int main(int ia, char **ca)
{
gari = sizeof(gar) / sizeof(gar0);
camerai = sizeof(camera) / sizeof(camera0);
srand(time(0));
glutInit(&ia, ca);
glutInitDisplayMode(GLUT_DOUBLE);

glutInitWindowSize(
// 320,200);
  800, 600);
glutInitWindowPosition (
//1000, 1000);
50, 50);

// glutReshapeFunc ( gl_reshape );
glutCreateWindow("GL Camera Gar");
// glutDisplayFunc(gl_display);
glutIdleFunc ( gl_display );

//===========
glClearDepth(1.0f);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glShadeModel(GL_SMOOTH);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);

glClearColor(1.0f-.4, 1.0f-.4,
 1.0f-.4, 1.0f - .4);
glColor4f(0, 0, 0, 0);

glutReshapeFunc(gl_reshape);

glLineWidth(8);

glutKeyboardFunc(gl_kd);

glutFullScreen();
glutMainLoop();
return 0;
}

http://paste.ubuntu.com/p/5HPXrC7nx8/
« Последнее редактирование: 03 Январь 2019, 21:53:39 от victor00000 »
~.o

 

Страница сгенерирована за 0.056 секунд. Запросов: 24.