Aggiunta calcolo rotazione da accTan in rb
This commit is contained in:
Binary file not shown.
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
Caviglia::Caviglia(rb::Vector3 coords, _Float16 mass){
|
Caviglia::Caviglia(rb::Vector3 coords, _Float16 mass){
|
||||||
rb::Vector3 com = {caviglia_Dim.x/2,caviglia_Dim.x/2, caviglia_Dim.y/2};
|
rb::Vector3 com = {caviglia_Dim.x/2,caviglia_Dim.x/2, caviglia_Dim.y/2};
|
||||||
body = rb::rigidbody(coords, com, mass);
|
body = rb::rigidbody(coords, com, mass, caviglia_Dim.x/2);
|
||||||
color = caviglia_Col;
|
color = caviglia_Col;
|
||||||
globalPos = {0,0,0};
|
globalPos = {0,0,0};
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
Coscia::Coscia(rb::Vector3 coords, _Float16 mass){
|
Coscia::Coscia(rb::Vector3 coords, _Float16 mass){
|
||||||
rb::Vector3 com = {coscia_Dim.x/2,coscia_Dim.z/2,coscia_Dim.y/2};
|
rb::Vector3 com = {coscia_Dim.x/2,coscia_Dim.z/2,coscia_Dim.y/2};
|
||||||
body = rb::rigidbody(coords, com, mass);
|
body = rb::rigidbody(coords, com, mass, coscia_Dim.z/2);
|
||||||
color = coscia_Col;
|
color = coscia_Col;
|
||||||
globalPos = {0,0,0};
|
globalPos = {0,0,0};
|
||||||
initialize_shapes(coscia_Dim);
|
initialize_shapes(coscia_Dim);
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
Sensore::Sensore(rb::Vector3 coords, _Float16 mass){
|
Sensore::Sensore(rb::Vector3 coords, _Float16 mass){
|
||||||
rb::Vector3 com = {sensore_Dim.x/2,sensore_Dim.z/2, sensore_Dim.y/2};
|
rb::Vector3 com = {sensore_Dim.x/2,sensore_Dim.z/2, sensore_Dim.y/2};
|
||||||
body = rb::rigidbody(coords, com, mass);
|
body = rb::rigidbody(coords, com, mass, sensore_Dim.z/2);
|
||||||
color = sensore_Col;
|
color = sensore_Col;
|
||||||
globalPos = {0,0,0};
|
globalPos = {0,0,0};
|
||||||
initialize_shapes(sensore_Dim);
|
initialize_shapes(sensore_Dim);
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
Torso::Torso(rb::Vector3 coords, _Float16 mass){
|
Torso::Torso(rb::Vector3 coords, _Float16 mass){
|
||||||
rb::Vector3 com = {torso_Dim.x/2, torso_Dim.y/2, torso_Dim.z/2};
|
rb::Vector3 com = {torso_Dim.x/2, torso_Dim.y/2, torso_Dim.z/2};
|
||||||
body = rb::rigidbody(coords,com, mass);
|
body = rb::rigidbody(coords,com, mass, torso_Dim.y/2);
|
||||||
color = torso_Col;
|
color = torso_Col;
|
||||||
globalPos = {0,0,0};
|
globalPos = {0,0,0};
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,9 @@
|
|||||||
Vector3 acc = {0,0,0};
|
Vector3 acc = {0,0,0};
|
||||||
Vector3 rot = {0,0,0};
|
Vector3 rot = {0,0,0};
|
||||||
Vector3 tanAcc = {0,0,0};
|
Vector3 tanAcc = {0,0,0};
|
||||||
|
Vector3 tanVel = {0,0,0};
|
||||||
|
|
||||||
|
float R = 1;
|
||||||
_Float16 mass = 1;
|
_Float16 mass = 1;
|
||||||
|
|
||||||
Vector3 coords = {0,0,0};
|
Vector3 coords = {0,0,0};
|
||||||
@@ -34,8 +36,8 @@
|
|||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
rigidbody(){}
|
rigidbody(){ }
|
||||||
rigidbody(Vector3 coords, Vector3 centerOfMass, _Float16 mass);
|
rigidbody(Vector3 coords, Vector3 centerOfMass, _Float16 mass, float radius);
|
||||||
~rigidbody();
|
~rigidbody();
|
||||||
|
|
||||||
|
|
||||||
@@ -45,7 +47,7 @@
|
|||||||
void setRot(const Vector3 Nrot);
|
void setRot(const Vector3 Nrot);
|
||||||
void setVel(const Vector3 Nacc);
|
void setVel(const Vector3 Nacc);
|
||||||
void setAcc(const Vector3 Nvel);
|
void setAcc(const Vector3 Nvel);
|
||||||
void setTanAcc(const Vector3 Dacc, const Vector3 pos);
|
void setTanAcc(const Vector3 Dacc);
|
||||||
void step(const sf::Clock time);
|
void step(const sf::Clock time);
|
||||||
|
|
||||||
//complesso, deve definire accelerazione e accelerazione tangenziale
|
//complesso, deve definire accelerazione e accelerazione tangenziale
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
using namespace rb ;
|
using namespace rb ;
|
||||||
|
|
||||||
rigidbody::rigidbody(Vector3 coords, Vector3 centerOfMass, _Float16 mass)
|
rigidbody::rigidbody(Vector3 coords, Vector3 centerOfMass, _Float16 mass, float radius)
|
||||||
{
|
{
|
||||||
if (coords.size() != 3) throw "Coords must be 3";
|
if (coords.size() != 3) throw "Coords must be 3";
|
||||||
if (centerOfMass.size() != 3) throw "COM coords must be 3";
|
if (centerOfMass.size() != 3) throw "COM coords must be 3";
|
||||||
@@ -11,7 +11,7 @@ rigidbody::rigidbody(Vector3 coords, Vector3 centerOfMass, _Float16 mass)
|
|||||||
this->coords = coords;
|
this->coords = coords;
|
||||||
this->centerOfMass = centerOfMass;
|
this->centerOfMass = centerOfMass;
|
||||||
this->mass = mass;
|
this->mass = mass;
|
||||||
|
this->R = radius;
|
||||||
}
|
}
|
||||||
|
|
||||||
rigidbody::~rigidbody()
|
rigidbody::~rigidbody()
|
||||||
@@ -37,7 +37,7 @@ void rigidbody::setPos(Vector3 Npos){
|
|||||||
}
|
}
|
||||||
|
|
||||||
void rigidbody::setAcc(const Vector3 Nacc){
|
void rigidbody::setAcc(const Vector3 Nacc){
|
||||||
if (Nacc.size() != 3) throw "Vel vector must be 3 in lenght!";
|
if (Nacc.size() != 3) throw "Acc vector must be 3 in lenght!";
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (float axis : Nacc){
|
for (float axis : Nacc){
|
||||||
@@ -93,15 +93,42 @@ void rigidbody::step(const sf::Clock time){
|
|||||||
float dt = (float(Dtime) / 1000000.0) - (float(prevT) / 1000000.0);
|
float dt = (float(Dtime) / 1000000.0) - (float(prevT) / 1000000.0);
|
||||||
prevT = Dtime;
|
prevT = Dtime;
|
||||||
|
|
||||||
|
calcRot(dt);
|
||||||
calcPos(dt);
|
calcPos(dt);
|
||||||
calcVel(dt);
|
calcVel(dt);
|
||||||
}
|
}
|
||||||
|
|
||||||
void rigidbody::setTanAcc(const Vector3 Dacc, const Vector3 pos){
|
void rigidbody::setTanAcc(const Vector3 Dacc){
|
||||||
|
if (Dacc.size() != 3) throw "Vel vector must be 3 in lenght!";
|
||||||
|
|
||||||
|
int i = 0;
|
||||||
|
for (float a : Dacc ){
|
||||||
|
tanAcc[i] = a;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void rigidbody::calcRot(const float Dtime){
|
void rigidbody::calcRot(const float Dtime){
|
||||||
|
// Ds = wt +1/2*at^2 -> l'accelerazione angolare la trovo ac = v^2/R
|
||||||
|
Vector3 tmpVel;
|
||||||
|
for (float a : tanAcc){
|
||||||
|
tmpVel.push_back( a*Dtime );
|
||||||
|
}
|
||||||
|
int i = 0;
|
||||||
|
for (float nv : tmpVel){
|
||||||
|
tanVel[i++] += nv;
|
||||||
|
}
|
||||||
|
|
||||||
|
Vector3 tmpTanAcc;
|
||||||
|
for (int i = 0; i<3; i++){
|
||||||
|
tmpTanAcc.push_back( pow(tanVel[i],2) / R );
|
||||||
|
}
|
||||||
|
|
||||||
|
i=0;
|
||||||
|
for (auto axes : rot){
|
||||||
|
axes += 0.5 * tmpTanAcc[i] * pow(Dtime,2);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user