Add basics module
This commit is contained in:
parent
31fefc9235
commit
296605f364
3 changed files with 75 additions and 0 deletions
|
@ -1,6 +1,7 @@
|
|||
Import('env')
|
||||
|
||||
files = Split("""
|
||||
basics.c
|
||||
charles.c
|
||||
scene.c
|
||||
""")
|
||||
|
|
48
src/basics.c
Normal file
48
src/basics.c
Normal file
|
@ -0,0 +1,48 @@
|
|||
/* basics.c
|
||||
*
|
||||
* Definition of basic types: Vector.
|
||||
*
|
||||
* Eryn Wells <eryn@erynwells.me>
|
||||
*/
|
||||
|
||||
#include "basics.h"
|
||||
|
||||
|
||||
/*
|
||||
* vector_init --
|
||||
*
|
||||
* Create a new vector given x, y, and z coordinates.
|
||||
*/
|
||||
Vector3
|
||||
vector_init(float x, float y, float z)
|
||||
{
|
||||
Vector3 v;
|
||||
v.x = x;
|
||||
v.y = y;
|
||||
v.z = z;
|
||||
return v;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* vector_mult_scalar --
|
||||
*
|
||||
* Multiply a vector by a scalar. Return a new vector.
|
||||
*/
|
||||
Vector3
|
||||
vector_mult_scalar(Vector3 v, float f)
|
||||
{
|
||||
return vector_init(f * v.x, f * v.y, f * v.z);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* vector_mult_vector --
|
||||
*
|
||||
* Multiply a vector by another vector. Return a new vector.
|
||||
*/
|
||||
Vector3
|
||||
vector_mult_vector(Vector3 v, Vector3 f)
|
||||
{
|
||||
return vector_init(v.x * f.x, v.y * f.y, v.z * f.z);
|
||||
}
|
26
src/basics.h
Normal file
26
src/basics.h
Normal file
|
@ -0,0 +1,26 @@
|
|||
/* basics.h
|
||||
*
|
||||
* Declaration of basic types: Vector.
|
||||
*
|
||||
* Eryn Wells <eryn@erynwells.me>
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __BASICS_H
|
||||
#define __BASICS_H
|
||||
|
||||
|
||||
typedef struct {
|
||||
float x, y, z;
|
||||
} Vector3;
|
||||
|
||||
|
||||
extern const Vector3 ZeroVector3;
|
||||
|
||||
|
||||
Vector3 vector_init(float x, float y, float z);
|
||||
Vector3 vector_mult_scalar(Vector3 v, float f);
|
||||
Vector3 vector_mult_vector(Vector3 v, Vector3 f);
|
||||
|
||||
|
||||
#endif
|
Loading…
Add table
Add a link
Reference in a new issue