Включение позиции и аффинного преобразования в проект для Visual Studio
This commit is contained in:
parent
7175c4148a
commit
3c2b89f369
9 changed files with 191 additions and 12 deletions
156
basic-geometry-dev/affine3.c
Normal file
156
basic-geometry-dev/affine3.c
Normal file
|
|
@ -0,0 +1,156 @@
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <basic-geometry.h>
|
||||||
|
#include "affine3.h"
|
||||||
|
|
||||||
|
#ifdef _WIN64
|
||||||
|
#include <windows.h>
|
||||||
|
#else
|
||||||
|
#include <time.h>
|
||||||
|
#endif // _WINDOWS_
|
||||||
|
|
||||||
|
BgcAffine3FP32* _create_bgc_affine3_list(int affine_amount)
|
||||||
|
{
|
||||||
|
BgcAffine3FP32* affines = malloc(affine_amount * sizeof(BgcAffine3FP32));
|
||||||
|
|
||||||
|
if (affines == 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < affine_amount; i++) {
|
||||||
|
bgc_affine3_reset_fp32(&affines[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return affines;
|
||||||
|
}
|
||||||
|
|
||||||
|
float get_random_value_fp32()
|
||||||
|
{
|
||||||
|
return rand() * (2.0f / RAND_MAX) - 1.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
BgcAffine3FP32* _create_bgc_affine3_random_list(int affine_amount)
|
||||||
|
{
|
||||||
|
BgcAffine3FP32* affines = malloc(affine_amount * sizeof(BgcAffine3FP32));
|
||||||
|
|
||||||
|
if (affines == 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
BgcPosition3FP32 position;
|
||||||
|
|
||||||
|
for (int i = 0; i < affine_amount; i++) {
|
||||||
|
bgc_versor_set_values_fp32(
|
||||||
|
get_random_value_fp32(),
|
||||||
|
get_random_value_fp32(),
|
||||||
|
get_random_value_fp32(),
|
||||||
|
get_random_value_fp32(),
|
||||||
|
&position.turn
|
||||||
|
);
|
||||||
|
|
||||||
|
position.shift.x1 = get_random_value_fp32();
|
||||||
|
position.shift.x2 = get_random_value_fp32();
|
||||||
|
position.shift.x3 = get_random_value_fp32();
|
||||||
|
|
||||||
|
bgc_position3_get_affine3_map_fp32(&position, &affines[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return affines;
|
||||||
|
}
|
||||||
|
|
||||||
|
BgcVector3FP32* _create_bgc_vector3_list(int amount)
|
||||||
|
{
|
||||||
|
return malloc(amount * sizeof(BgcVector3FP32));
|
||||||
|
}
|
||||||
|
|
||||||
|
BgcVector3FP32* _create_bgc_vector3_random_list(int amount)
|
||||||
|
{
|
||||||
|
BgcVector3FP32* vectors = _create_bgc_vector3_list(amount);
|
||||||
|
|
||||||
|
if (vectors == 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < amount; i++) {
|
||||||
|
vectors[i].x1 = get_random_value_fp32();
|
||||||
|
vectors[i].x2 = get_random_value_fp32();
|
||||||
|
vectors[i].x3 = get_random_value_fp32();
|
||||||
|
}
|
||||||
|
|
||||||
|
return vectors;
|
||||||
|
}
|
||||||
|
|
||||||
|
float test_bgc_affine3_performance(int affine_amount, int vector_per_affine)
|
||||||
|
{
|
||||||
|
BgcAffine3FP32* affines;
|
||||||
|
BgcVector3FP32* source_vectors;
|
||||||
|
BgcVector3FP32* result_vectors;
|
||||||
|
|
||||||
|
int vector_index = 0;
|
||||||
|
float time = -1.0f;
|
||||||
|
|
||||||
|
#ifdef _WIN64
|
||||||
|
ULONGLONG start, end;
|
||||||
|
|
||||||
|
start = GetTickCount64();
|
||||||
|
|
||||||
|
srand((unsigned int)(start & 0xfffffff));
|
||||||
|
#else
|
||||||
|
struct timespec start, end;
|
||||||
|
clock_gettime(0, &start);
|
||||||
|
srand((unsigned int)(start.tv_nsec & 0xfffffff));
|
||||||
|
#endif // _WIN64
|
||||||
|
|
||||||
|
affines = _create_bgc_affine3_random_list(affine_amount);
|
||||||
|
|
||||||
|
if (affines == 0) {
|
||||||
|
return time;
|
||||||
|
}
|
||||||
|
|
||||||
|
source_vectors = _create_bgc_vector3_random_list(affine_amount * vector_per_affine);
|
||||||
|
|
||||||
|
if (source_vectors == 0) {
|
||||||