7 n__3d_8h
gullradriel edited this page 2026-10-29 20:54:40 +01:00

include/nilorea/n_3d.h

Simple 3D movement simulation. More...

Structures

Name
struct PHYSICS
structure of the physics of an object

Detailed Description

Simple 3D movement simulation.

Author: Castagnier Mickael

Version: 1.0

Date: 30/04/2014

Source code

/*
 * Nilorea Library
 * Copyright (C) 2005-2026 Castagnier Mickael
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
 * implied. See the License for the specific language governing
 * permissions and limitations under the License.
 *
 * SPDX-License-Identifier: Apache-2.0
 */


#ifndef _N_3D_HEADER
#define _N_3D_HEADER

#ifdef __cplusplus
extern "C" {
#endif


#include "n_log.h"
#include "n_common.h"
#include <sys/time.h>

#define MOVE_STOPPED 0
#define MOVE_INTER 1
#define MOVE_SIMU 2

#define VECTOR3D_DONT_INTERSECT -2
#define VECTOR3D_COLLINEAR -1
#define VECTOR3D_DO_INTERSECT 0

typedef double VECTOR3D[3]; /* x , y , z  */

#define VECTOR3D_SET(VECTOR, X, Y, Z) \
    do {                              \
        VECTOR[0] = (X);              \
        VECTOR[1] = (Y);              \
        VECTOR[2] = (Z);              \
    } while (0)

typedef struct PHYSICS {
    time_t delta_t;
    VECTOR3D position;
    VECTOR3D speed;
    VECTOR3D acceleration;
    VECTOR3D orientation;
    VECTOR3D angular_speed;
    VECTOR3D angular_acceleration;
    VECTOR3D gravity;
    int can_jump;
    int sz;
    int type;
} PHYSICS;

double distance(VECTOR3D* p1, VECTOR3D* p2);
int update_physics_position_nb(PHYSICS* object, int it, double delta_t);
int update_physics_position_reverse_nb(PHYSICS* object, int it, double delta_t);
int update_physics_position(PHYSICS* object, double delta_t);
int update_physics_position_reverse(PHYSICS* object, double delta_t);
int vector_intersect(VECTOR3D* p1, VECTOR3D* p2, VECTOR3D* p3, VECTOR3D* p4, VECTOR3D* px);
double vector_dot_product(VECTOR3D* vec1, VECTOR3D* vec2);
double vector_normalize(VECTOR3D* vec);
double vector_angle_between(VECTOR3D* vec1, VECTOR3D* vec2);

#define copy_point(__src_, __dst_) \
    memcpy(__dst_, __src_, sizeof(VECTOR3D));


#ifdef __cplusplus
}
#endif

#endif  // header guard