Caricamento v0.2
This commit is contained in:
-16515
File diff suppressed because it is too large
Load Diff
-44
@@ -1,44 +0,0 @@
|
||||
#include<math.h>
|
||||
#include"rb_class.cpp"
|
||||
#include<time.h>
|
||||
|
||||
/*
|
||||
Questo namespace deve contenere le funzioni di gestione della fisica del motore.
|
||||
Ogni moto in questo engine sarà ti tipo uniformemente accelerato per dare una semplificazione della realtà.
|
||||
Le funzioni necessarie sono:
|
||||
|
||||
- Calcolo velocità, richiede:
|
||||
(Oggetto rigidbody)
|
||||
(time di partenza, time di arrivo o delta t)
|
||||
(Accelerazione media)
|
||||
(velocità iniziale)
|
||||
|
||||
- Calcolo rotazione, richiede:
|
||||
(Oggetto rigidbody)
|
||||
(time di partenza, time di arrivo o delta t)
|
||||
(Accelerazione tangenziale)
|
||||
(RAD/s iniziale)
|
||||
|
||||
- Calcolo accelerazione, deve modificare i valori di accelerazione su oggetti di tipo rigidbody, richiede:
|
||||
(Oggetto rigidbody)
|
||||
|
||||
- Calcolo posizione, deve calcolare la posizione di un rigidbody in in un intervallo di tempo
|
||||
|
||||
- Calcolo energia potenziale
|
||||
|
||||
- Calcolo inerzia
|
||||
|
||||
- Calcolo energia meccanica
|
||||
|
||||
*/
|
||||
using namespace rb;
|
||||
|
||||
namespace fis{
|
||||
|
||||
void calcVel(rigidbody body, const time_t Dtime);
|
||||
void calcRot(rigidbody body, const time_t Dtime);
|
||||
void calcAcc(rigidbody body, const std::vector<float> Dacc);
|
||||
void calcTanAcc(rigidbody body, const std::vector<float> Dacc);
|
||||
void calcPos(rigidbody body, const time_t Dtime);
|
||||
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
#include "csv/headers/csv.hpp"
|
||||
#include "sfml_util.cpp"
|
||||
#include "pieces/headers/coscia.hpp"
|
||||
#include "pieces/headers/caviglia.hpp"
|
||||
#include "pieces/headers/sensore.hpp"
|
||||
#include "joints/headers/rigid_joint.hpp"
|
||||
#include "joints/headers/pivot_joint.hpp"
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "../../pieces/headers/piece_interface.hpp"
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
#ifndef JOINT_INTERFACE_H
|
||||
#define JOINT_INTERFACE_H
|
||||
|
||||
@@ -4,55 +4,43 @@
|
||||
|
||||
void PivotJoint::rotate(unsigned int id){
|
||||
rb::Vector3_s fRot = father->body.getRot();
|
||||
rb::Vector3 fPos = father->body.getPos();
|
||||
rb::Vector3_s cRot = childs[id]->body.getRot();
|
||||
|
||||
//// sposto l'origine passivamente su tutti gli assi ////
|
||||
|
||||
float r1 = sqrt(pow(pivot[0],2)+pow(pivot[2],2)); //calcolo modulo dell'offset (per ora solo sul piano xz)
|
||||
float r2 = sqrt(pow(offset[id][0],2)+pow(offset[id][2],2));
|
||||
if (r1>ZERO_INT){
|
||||
|
||||
float sign = pivot[2] >= 0 ? 1 : -1;
|
||||
float alpha = float (fRot[2] - oldRot[2]);
|
||||
float cosA = glm::cos(alpha);
|
||||
float sinA = glm::sin(alpha);
|
||||
|
||||
float beta = float (cRot[2] - oldCRot[id][2]);
|
||||
float cosB = glm::cos(beta);
|
||||
float sinB = glm::sin(beta);
|
||||
|
||||
sf::Angle alpha = sf::radians(fRot[2] - oldRot[2]); // angolo aggiunto
|
||||
sf::Angle alpha1 = sf::radians(acos(sign * pivot[0]/r1)); // angolo rispetto alla posizione del pivot
|
||||
sf::Angle alpha2 = alpha + alpha1;
|
||||
glm::mat3 R1 = glm::mat3(
|
||||
/*cos*/ cosA, /*sin*/ sinA, 0,
|
||||
/*-sin*/ -sinA , /*cos*/ cosA, 0,
|
||||
0, 0, 1
|
||||
);
|
||||
|
||||
sf::Vector2f tmpCoordsX = sf::Vector2f(r1,alpha2);
|
||||
pivot = {sign * tmpCoordsX.x,pivot[1],sign * tmpCoordsX.y};
|
||||
glm::mat3 R2 = glm::mat3(
|
||||
/*cos*/ cosB, /*sin*/ sinB, 0,
|
||||
/*-sin*/ -sinB , /*cos*/ cosB, 0,
|
||||
0, 0, 1
|
||||
);
|
||||
|
||||
//calcolo la posizione in base alla rotazione del child
|
||||
sign = offset[id][2] >= 0 ? 1 : -1;
|
||||
glm::vec3 pivotNXZ = R1 * glm::vec3(pivot[0],pivot[2],1);
|
||||
pivot = rb::Vector3{pivotNXZ[0],pivot[1],pivotNXZ[1]};
|
||||
glm::vec3 offsetNXZ = R2 * glm::vec3(offset[id][0],offset[id][2],1);
|
||||
offset[id] = rb::Vector3{offsetNXZ[0],offset[id][1],offsetNXZ[1]};
|
||||
|
||||
sf::Angle beta = sf::radians(cRot[2] - oldCRot[id][2]);
|
||||
sf::Angle beta1 = sf::radians(acos(sign * offset[id][0]/r2));
|
||||
sf::Angle beta2 = beta + beta1;
|
||||
sf::Vector2f tmpCoordsC = sf::Vector2f(r2,beta2);
|
||||
offset[id] = {sign * tmpCoordsC.x,offset[id][1],sign * tmpCoordsC.y};
|
||||
|
||||
|
||||
//ora devo muovere il child rispetto al nuovo offset
|
||||
rb::Vector3 pivotPos = father->body.getPos()+father->globalPos+pivot;
|
||||
rb::Vector3 cPos = childs[id]->body.getPos() + childs[id]->globalPos;
|
||||
|
||||
rb::Vector3 tmpChild = pivotPos + offset[id];
|
||||
|
||||
childs[id]->body.setPos(tmpChild - childs[id]->globalPos);
|
||||
}
|
||||
|
||||
childs[id]->body.setPos(rb::Vector3{fPos[0]+offset[id][0]+pivot[0],fPos[1]+offset[id][1]+pivot[1],fPos[2]+offset[id][2]+pivot[2]});
|
||||
|
||||
|
||||
oldRot = fRot; //aggiorno la rotazione per il ciclo successivo
|
||||
oldCRot[id] = cRot;
|
||||
|
||||
// r cosA = x -> x/r = cosA
|
||||
|
||||
/*
|
||||
Devo spostare l'offset per poter ricalcolare la posizione relativa dei child rispetto al father dopo aver eseguito la rotazione.
|
||||
La rotazione va eseguita nella posizione del mondo, ovvero sulle coordinate di body
|
||||
|
||||
Le coordinate camera non vanno toccate, determinano solo lo spostamento rispetto alla telecamera
|
||||
*/
|
||||
}
|
||||
|
||||
void PivotJoint::traslate(unsigned int id){
|
||||
|
||||
@@ -2,55 +2,40 @@
|
||||
|
||||
#define ZERO_INT 0.00001
|
||||
|
||||
//using namespace glm;
|
||||
|
||||
void RigidJoint::rotate(unsigned int id){
|
||||
rb::Vector3_s fRot = father->body.getRot();
|
||||
rb::Vector3_s fRotOld = childs[id]->body.getRot() - rotOffset[id];
|
||||
|
||||
rb::Vector3 cPos = childs[id]->body.getPos() + childs[id]->globalPos;
|
||||
rb::Vector3 fPos = father->body.getPos();
|
||||
rb::Vector3 cPos = childs[id]->body.getPos();
|
||||
|
||||
childs[id]->body.setRot(fRot + rotOffset[id]);
|
||||
|
||||
//// sposto l'origine passivamente su tutti gli assi ////
|
||||
//se si muove il child devo muovere anche il padre -> devo trovare la differenza di posizione prima di ricalcolare l'offset
|
||||
/*
|
||||
if (cPos != oldCPos[id]);*/
|
||||
|
||||
float r = sqrt(pow(offset[id][0],2)+pow(offset[id][2],2)); //calcolo modulo dell'offset (per ora solo sul piano xz)
|
||||
// sposto il alla distanza offset rispetto all'origine R*pos
|
||||
// calcolo alpha angolo
|
||||
|
||||
if (r>ZERO_INT){
|
||||
|
||||
float sign = offset[id][2] >= 0 ? 1 : -1;
|
||||
|
||||
float alpha = float (fRot[2] - fRotOld[2]);
|
||||
float cosA = glm::cos(alpha);
|
||||
float sinA = glm::sin(alpha);
|
||||
|
||||
sf::Angle alpha = sf::radians(fRot[2] - fRotOld[2]); // angolo aggiunto
|
||||
sf::Angle alpha1 = sf::radians(acos(sign * offset[id][0]/r)); // angolo rispetto alla posizione del child
|
||||
sf::Angle beta = alpha + alpha1;
|
||||
glm::mat3 R = glm::mat3(
|
||||
/*cos*/ cosA, /*sin*/ sinA, 0,
|
||||
/*-sin*/ -sinA , /*cos*/ cosA, 0,
|
||||
0, 0, 1
|
||||
);
|
||||
|
||||
sf::Vector2f tmpCoordsX = sf::Vector2f(r,beta);
|
||||
offset[id] = {sign * tmpCoordsX.x,offset[id][1],sign * tmpCoordsX.y};
|
||||
//sposto il child all'origine rispetto al padre
|
||||
|
||||
//ora devo muovere il child rispetto al nuovo offset
|
||||
glm::vec3 XZ_cPos = {offset[id][0],offset[id][2],1};
|
||||
glm::vec3 resRot = R * XZ_cPos;
|
||||
|
||||
|
||||
offset[id][0] = resRot[0] ;
|
||||
offset[id][2] = resRot[1] ;
|
||||
|
||||
rb::Vector3 fPos = father->body.getPos() + father->globalPos;
|
||||
rb::Vector3 tmpChild = fPos + offset[id];
|
||||
|
||||
childs[id]->body.setPos(tmpChild - childs[id]->globalPos);
|
||||
}
|
||||
else{
|
||||
childs[id]->body.setPos(father->body.getPos()+father->globalPos-childs[id]->globalPos);
|
||||
}
|
||||
|
||||
|
||||
// r cosA = x -> x/r = cosA
|
||||
|
||||
/*
|
||||
Devo spostare l'offset per poter ricalcolare la posizione relativa dei child rispetto al father dopo aver eseguito la rotazione.
|
||||
La rotazione va eseguita nella posizione del mondo, ovvero sulle coordinate di body
|
||||
|
||||
Le coordinate camera non vanno toccate, determinano solo lo spostamento rispetto alla telecamera
|
||||
*/
|
||||
childs[id]->body.setPos({fPos[0]-offset[id][0],offset[id][1],fPos[2] -offset[id][2]});
|
||||
|
||||
}
|
||||
|
||||
void RigidJoint::traslate(unsigned int id){
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
#include "piece_interface.hpp"
|
||||
|
||||
#ifndef CAVIGLIA_H
|
||||
#define CAVIGLIA_H
|
||||
|
||||
const sf::Vector2f caviglia_Dim = {60, 200};
|
||||
const sf::Color caviglia_Col = sf::Color(230,160,11,255);
|
||||
|
||||
|
||||
class Caviglia : public PieceInterface{
|
||||
public:
|
||||
|
||||
Caviglia(rb::Vector3 coords, _Float16 mass);
|
||||
~Caviglia();
|
||||
|
||||
void update(sf::Clock cl) override;
|
||||
sf::Shape* draw(ReferencePlane plane) override;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -1,17 +1,12 @@
|
||||
#include <SFML/Graphics.hpp>
|
||||
#include <math.h>
|
||||
#include "../../rigidbody/headers/rb.hpp"
|
||||
//#include "../../joints/headers/joint_interface.hpp"
|
||||
|
||||
|
||||
#ifndef PIECE_INTERFACE_H
|
||||
#define PIECE_INTERFACE_H
|
||||
|
||||
|
||||
// costanti
|
||||
|
||||
const sf::Vector2f caviglia_Dim = {50, 200};
|
||||
const sf::Color caviglia_Col = sf::Color::Red;
|
||||
|
||||
enum class ReferencePlane {
|
||||
XY,
|
||||
YZ,
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
#include "../headers/caviglia.hpp"
|
||||
|
||||
Caviglia::Caviglia(rb::Vector3 coords, _Float16 mass){
|
||||
size = caviglia_Dim;
|
||||
rb::Vector3 com = {size.x/2,0, size.y/2};
|
||||
body = rb::rigidbody(coords, com, mass);
|
||||
color = caviglia_Col;
|
||||
shape = new sf::RectangleShape(size);
|
||||
shape->setOrigin({size.x/2,size.y/2});
|
||||
globalPos = {0,0,0};
|
||||
}
|
||||
|
||||
Caviglia::~Caviglia(){
|
||||
delete shape;
|
||||
}
|
||||
|
||||
void Caviglia::update(sf::Clock cl){
|
||||
//body.step(cl);
|
||||
}
|
||||
|
||||
sf::Shape* Caviglia::draw(ReferencePlane plane){
|
||||
shape->setFillColor(color);
|
||||
rb::Vector3 tmpPos = body.getPos();
|
||||
rb::Vector3_s tmpRot = body.getRot();
|
||||
|
||||
switch (plane)
|
||||
{
|
||||
case ReferencePlane::XZ:
|
||||
shape->setPosition({tmpPos[0]+globalPos[0],tmpPos[2]+globalPos[2]});
|
||||
shape->setRotation(sf::Angle(sf::radians(tmpRot[2])));
|
||||
break;
|
||||
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
return shape;
|
||||
}
|
||||
@@ -4,10 +4,10 @@
|
||||
Sensore::Sensore(rb::Vector3 coords, _Float16 mass){
|
||||
size = sensore_Dim;
|
||||
rb::Vector3 com = {size.x/2,0, size.y/2};
|
||||
body = rb::rigidbody({0,0,0}, com, mass);
|
||||
body = rb::rigidbody(coords, com, mass);
|
||||
color = sensore_Col;
|
||||
shape = new sf::RectangleShape(size);
|
||||
globalPos = coords;
|
||||
globalPos = {0,0,0};
|
||||
}
|
||||
|
||||
Sensore::Sensore(rb::Vector3 coords, _Float16 mass, unsigned int st, unsigned int dataIntvl, std::vector<std::vector<float>> data) : Sensore(coords, mass){
|
||||
|
||||
@@ -51,7 +51,7 @@ void rigidbody::setRot(const Vector3_s Nrot){
|
||||
if (Nrot.size() != 3) throw "Vel vector must be 3 in lenght!";
|
||||
|
||||
int i = 0;
|
||||
for (float axis : Nrot){
|
||||
for (_Float16 axis : Nrot){
|
||||
rot[i] = axis;
|
||||
i++;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user