File: linecurve.cpp

package info (click to toggle)
amoeba 1.1-19
  • links: PTS
  • area: contrib
  • in suites: lenny
  • size: 816 kB
  • ctags: 966
  • sloc: cpp: 8,286; makefile: 173
file content (39 lines) | stat: -rw-r--r-- 814 bytes parent folder | download | duplicates (11)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/*
 * Intended to be a _fast_ and simple curve type. :-)
 */

#include "main/linecurve.h"
#include "demolib_prefs.h"
#include "exception.h"

#include <stdio.h>

#if DEMOLIB_MAINLOOP

LineCurve::LineCurve()
{
	this->num_points = 0;
}
LineCurve::~LineCurve() {}

void LineCurve::add_curvepoint(float x, float y)
{
	this->x[this->num_points] = x;
	this->y[this->num_points] = y;
	this->num_points++;
}
void LineCurve::end_curvepoints(float start, float length)
{
	if (this->num_points < 1 || this->num_points > 2)
		throw new FatalException("Need exactly two points for line movement!");

	/* just trust that they come in order ;-) */
	this->base = this->y[0];
	this->step = (this->num_points == 1) ? 0.0f : (this->y[1] - base);
}
float LineCurve::get_value(float x)
{
	return this->base + this->step * x;
}

#endif