Miglioramento precisione rotazioni
This commit is contained in:
Binary file not shown.
@@ -21,7 +21,7 @@ class JointInterface{
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
std::vector<rb::Vector3> offset;
|
std::vector<rb::Vector3> offset;
|
||||||
std::vector<rb::Vector3_s> rotOffset;
|
std::vector<rb::Vector3> rotOffset;
|
||||||
PieceInterface* father;
|
PieceInterface* father;
|
||||||
std::vector<PieceInterface*> childs;
|
std::vector<PieceInterface*> childs;
|
||||||
|
|
||||||
|
|||||||
@@ -5,9 +5,9 @@ class PivotJoint : public JointInterface {
|
|||||||
void rotate(unsigned int id) override;
|
void rotate(unsigned int id) override;
|
||||||
void traslate(unsigned int id) override;
|
void traslate(unsigned int id) override;
|
||||||
|
|
||||||
rb::Vector3_s oldRot;
|
rb::Vector3 oldRot;
|
||||||
rb::Vector3 pivot;
|
rb::Vector3 pivot;
|
||||||
std::vector<rb::Vector3_s> oldCRot;
|
std::vector<rb::Vector3> oldCRot;
|
||||||
|
|
||||||
//possono servire per calcolare l'offset rispetto alla posizione precedente
|
//possono servire per calcolare l'offset rispetto alla posizione precedente
|
||||||
rb::Vector3 oldPos;
|
rb::Vector3 oldPos;
|
||||||
|
|||||||
@@ -3,9 +3,9 @@
|
|||||||
#define ZERO_INT 0.00001
|
#define ZERO_INT 0.00001
|
||||||
|
|
||||||
void PivotJoint::rotate(unsigned int id){
|
void PivotJoint::rotate(unsigned int id){
|
||||||
rb::Vector3_s fRot = father->body.getRot();
|
rb::Vector3 fRot = father->body.getRot();
|
||||||
rb::Vector3 fPos = father->body.getPos();
|
rb::Vector3 fPos = father->body.getPos();
|
||||||
rb::Vector3_s cRot = childs[id]->body.getRot();
|
rb::Vector3 cRot = childs[id]->body.getRot();
|
||||||
|
|
||||||
//// sposto l'origine passivamente su tutti gli assi ////
|
//// sposto l'origine passivamente su tutti gli assi ////
|
||||||
|
|
||||||
@@ -75,7 +75,7 @@ PivotJoint::PivotJoint(PieceInterface* father,std::vector<PieceInterface*> child
|
|||||||
this->childs = childs;
|
this->childs = childs;
|
||||||
this->father = father;
|
this->father = father;
|
||||||
rb::Vector3 fCoords = father->globalPos + father->body.getPos();
|
rb::Vector3 fCoords = father->globalPos + father->body.getPos();
|
||||||
rb::Vector3_s fRot = father->body.getRot();
|
rb::Vector3 fRot = father->body.getRot();
|
||||||
|
|
||||||
pivot = pivotPoint;
|
pivot = pivotPoint;
|
||||||
rb::Vector3 pivotCenter = father->body.getPos() + pivot;
|
rb::Vector3 pivotCenter = father->body.getPos() + pivot;
|
||||||
@@ -83,7 +83,7 @@ PivotJoint::PivotJoint(PieceInterface* father,std::vector<PieceInterface*> child
|
|||||||
/*
|
/*
|
||||||
float sign = pivot[2] >= 0 ? 1 : -1;
|
float sign = pivot[2] >= 0 ? 1 : -1;
|
||||||
float r = sqrt(pow(pivot[0],2)+pow(pivot[2],2));
|
float r = sqrt(pow(pivot[0],2)+pow(pivot[2],2));
|
||||||
rotOffset.push_back( rb::Vector3_s{0,0,_Float16( acos(sign * pivot[0]/r) )} );
|
rotOffset.push_back( rb::Vector3{0,0,_Float16( acos(sign * pivot[0]/r) )} );
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
@@ -97,7 +97,7 @@ PivotJoint::PivotJoint(PieceInterface* father,std::vector<PieceInterface*> child
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
float r = sqrt(pow(tmpCoords[0],2)+pow(tmpCoords[2],2));
|
float r = sqrt(pow(tmpCoords[0],2)+pow(tmpCoords[2],2));
|
||||||
oldCRot.push_back( rb::Vector3_s{0,0,_Float16( acos(tmpCoords[0]/r) )} );
|
oldCRot.push_back( rb::Vector3{0,0,_Float16( acos(tmpCoords[0]/r) )} );
|
||||||
*/
|
*/
|
||||||
oldCRot.push_back(c->body.getRot());
|
oldCRot.push_back(c->body.getRot());
|
||||||
|
|
||||||
|
|||||||
@@ -5,8 +5,8 @@
|
|||||||
//using namespace glm;
|
//using namespace glm;
|
||||||
|
|
||||||
void RigidJoint::rotate(unsigned int id){
|
void RigidJoint::rotate(unsigned int id){
|
||||||
rb::Vector3_s fRot = father->body.getRot();
|
rb::Vector3 fRot = father->body.getRot();
|
||||||
rb::Vector3_s fRotOld = childs[id]->body.getRot() - rotOffset[id];
|
rb::Vector3 fRotOld = childs[id]->body.getRot() - rotOffset[id];
|
||||||
rb::Vector3 fPos = father->body.getPos();
|
rb::Vector3 fPos = father->body.getPos();
|
||||||
rb::Vector3 cPos = childs[id]->body.getPos();
|
rb::Vector3 cPos = childs[id]->body.getPos();
|
||||||
|
|
||||||
@@ -65,7 +65,7 @@ RigidJoint::RigidJoint(PieceInterface* father,std::vector<PieceInterface*> child
|
|||||||
this->childs = childs;
|
this->childs = childs;
|
||||||
this->father = father;
|
this->father = father;
|
||||||
rb::Vector3 fCoords = father->globalPos + father->body.getPos();
|
rb::Vector3 fCoords = father->globalPos + father->body.getPos();
|
||||||
rb::Vector3_s fRot = father->body.getRot();
|
rb::Vector3 fRot = father->body.getRot();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -73,7 +73,7 @@ RigidJoint::RigidJoint(PieceInterface* father,std::vector<PieceInterface*> child
|
|||||||
//mi calcolo l'offset per ogni child rispetto al padre
|
//mi calcolo l'offset per ogni child rispetto al padre
|
||||||
for(PieceInterface* c : childs){
|
for(PieceInterface* c : childs){
|
||||||
rb::Vector3 tmpCoords;
|
rb::Vector3 tmpCoords;
|
||||||
rb::Vector3_s tmpRot;
|
rb::Vector3 tmpRot;
|
||||||
|
|
||||||
rb::Vector3 cCoords = c->globalPos + c->body.getPos();
|
rb::Vector3 cCoords = c->globalPos + c->body.getPos();
|
||||||
|
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ void Caviglia::update(sf::Clock cl){
|
|||||||
sf::Shape* Caviglia::draw(ReferencePlane plane){
|
sf::Shape* Caviglia::draw(ReferencePlane plane){
|
||||||
|
|
||||||
rb::Vector3 tmpPos = body.getPos();
|
rb::Vector3 tmpPos = body.getPos();
|
||||||
rb::Vector3_s tmpRot = body.getRot();
|
rb::Vector3 tmpRot = body.getRot();
|
||||||
|
|
||||||
switch (plane)
|
switch (plane)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ void Coscia::update(sf::Clock cl){
|
|||||||
sf::Shape* Coscia::draw(ReferencePlane plane){
|
sf::Shape* Coscia::draw(ReferencePlane plane){
|
||||||
|
|
||||||
rb::Vector3 tmpPos = body.getPos();
|
rb::Vector3 tmpPos = body.getPos();
|
||||||
rb::Vector3_s tmpRot = body.getRot();
|
rb::Vector3 tmpRot = body.getRot();
|
||||||
|
|
||||||
|
|
||||||
switch (plane)
|
switch (plane)
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ void Sensore::update(sf::Clock cl){
|
|||||||
|
|
||||||
sf::Shape* Sensore::draw(ReferencePlane plane){
|
sf::Shape* Sensore::draw(ReferencePlane plane){
|
||||||
|
|
||||||
rb::Vector3_s tmpRot = body.getRot();
|
rb::Vector3 tmpRot = body.getRot();
|
||||||
rb::Vector3 tmpPos = body.getPos();
|
rb::Vector3 tmpPos = body.getPos();
|
||||||
|
|
||||||
switch (plane)
|
switch (plane)
|
||||||
@@ -105,7 +105,7 @@ void Sensore::calcRotWithG(unsigned int index){ // calcolo rotazione con valori
|
|||||||
float tmpAY = acos(tmpSinY);
|
float tmpAY = acos(tmpSinY);
|
||||||
float tmpAZ = acos(tmpSinZ);
|
float tmpAZ = acos(tmpSinZ);
|
||||||
|
|
||||||
body.setRot(rb::Vector3_s{_Float16( tmpAY),_Float16( tmpAX),_Float16( tmpAZ) });
|
body.setRot(rb::Vector3{tmpAY, tmpAX, tmpAZ });
|
||||||
|
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ void Torso::update(sf::Clock cl){
|
|||||||
|
|
||||||
sf::Shape* Torso::draw(ReferencePlane plane){
|
sf::Shape* Torso::draw(ReferencePlane plane){
|
||||||
|
|
||||||
rb::Vector3_s tmpRot = body.getRot();
|
rb::Vector3 tmpRot = body.getRot();
|
||||||
rb::Vector3 tmpPos = body.getPos();
|
rb::Vector3 tmpPos = body.getPos();
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -7,14 +7,14 @@
|
|||||||
|
|
||||||
namespace rb{
|
namespace rb{
|
||||||
typedef std::vector<float> Vector3;
|
typedef std::vector<float> Vector3;
|
||||||
typedef std::vector<_Float16> Vector3_s;
|
//typedef std::vector<_Float16> Vector3;
|
||||||
|
|
||||||
class rigidbody
|
class rigidbody
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
Vector3 vel = {0,0,0};
|
Vector3 vel = {0,0,0};
|
||||||
Vector3 acc = {0,0,0};
|
Vector3 acc = {0,0,0};
|
||||||
Vector3_s rot = {0,0,0};
|
Vector3 rot = {0,0,0};
|
||||||
Vector3 tanAcc = {0,0,0};
|
Vector3 tanAcc = {0,0,0};
|
||||||
|
|
||||||
_Float16 mass = 1;
|
_Float16 mass = 1;
|
||||||
@@ -40,9 +40,9 @@
|
|||||||
|
|
||||||
|
|
||||||
Vector3 getPos();
|
Vector3 getPos();
|
||||||
Vector3_s getRot();
|
Vector3 getRot();
|
||||||
void setPos(const Vector3 Npos);
|
void setPos(const Vector3 Npos);
|
||||||
void setRot(const Vector3_s 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 step(const sf::Clock time);
|
void step(const sf::Clock time);
|
||||||
@@ -77,29 +77,8 @@
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
inline rb::Vector3_s operator+(const rb::Vector3_s& v1, const rb::Vector3_s& v2) {
|
|
||||||
if (v1.size() != 3 || v2.size() != 3) {
|
|
||||||
throw std::invalid_argument("I vettori devono avere esattamente 3 elementi.");
|
|
||||||
}
|
|
||||||
return rb::Vector3_s{
|
|
||||||
v1[0] + v2[0],
|
|
||||||
v1[1] + v2[1],
|
|
||||||
v1[2] + v2[2]
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
inline rb::Vector3_s operator-(const rb::Vector3_s& v1, const rb::Vector3_s& v2) {
|
|
||||||
if (v1.size() != 3 || v2.size() != 3) {
|
|
||||||
throw std::invalid_argument("I vettori devono avere esattamente 3 elementi.");
|
|
||||||
}
|
|
||||||
return rb::Vector3_s{
|
|
||||||
v1[0] - v2[0],
|
|
||||||
v1[1] - v2[1],
|
|
||||||
v1[2] - v2[2]
|
|
||||||
};
|
|
||||||
}
|
|
||||||
/*
|
/*
|
||||||
inline bool operator!=(const rb::Vector3_s& v1, const rb::Vector3_s& v2) {
|
inline bool operator!=(const rb::Vector3& v1, const rb::Vector3& v2) {
|
||||||
if (v1.size() != 3 || v2.size() != 3) {
|
if (v1.size() != 3 || v2.size() != 3) {
|
||||||
throw std::invalid_argument("I vettori devono avere esattamente 3 elementi.");
|
throw std::invalid_argument("I vettori devono avere esattamente 3 elementi.");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,8 +21,8 @@ rigidbody::~rigidbody()
|
|||||||
Vector3 rigidbody::getPos(){
|
Vector3 rigidbody::getPos(){
|
||||||
return Vector3 {coords};
|
return Vector3 {coords};
|
||||||
}
|
}
|
||||||
Vector3_s rigidbody::getRot(){
|
Vector3 rigidbody::getRot(){
|
||||||
return Vector3_s {rot};
|
return Vector3 {rot};
|
||||||
}
|
}
|
||||||
|
|
||||||
void rigidbody::setPos(Vector3 Npos){
|
void rigidbody::setPos(Vector3 Npos){
|
||||||
@@ -47,7 +47,7 @@ void rigidbody::setAcc(const Vector3 Nacc){
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void rigidbody::setRot(const Vector3_s Nrot){
|
void rigidbody::setRot(const Vector3 Nrot){
|
||||||
if (Nrot.size() != 3) throw "Vel vector must be 3 in lenght!";
|
if (Nrot.size() != 3) throw "Vel vector must be 3 in lenght!";
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|||||||
+3
-3
@@ -112,10 +112,10 @@ void handle(const sf::Event::MouseMoved &mouseMoved, State &gs)
|
|||||||
gs.pieces[gs.selected]->body.setPos({tmp[0]+ (offset.x * px),tmp[1]+ (offset.x * py),tmp[2]+offset.y});
|
gs.pieces[gs.selected]->body.setPos({tmp[0]+ (offset.x * px),tmp[1]+ (offset.x * py),tmp[2]+offset.y});
|
||||||
}
|
}
|
||||||
if (gs.selected != -1 && gs.rot_Piece){
|
if (gs.selected != -1 && gs.rot_Piece){
|
||||||
rb::Vector3_s tmp = gs.pieces[gs.selected]->body.getRot();
|
rb::Vector3 tmp = gs.pieces[gs.selected]->body.getRot();
|
||||||
|
|
||||||
_Float16 nrot = _Float16(offset.x)/100;
|
float nrot = float(offset.x)/100;
|
||||||
gs.pieces[gs.selected]->body.setRot({tmp[0]+(nrot*_Float16(py)),tmp[1]+(nrot*_Float16(px)),tmp[2]});
|
gs.pieces[gs.selected]->body.setRot({tmp[0]+(nrot*py),tmp[1]+(nrot*px),tmp[2]});
|
||||||
|
|
||||||
//printf("Rotation : %f,%f,%f \n",gs.pieces[gs.selected]->body.getRot()[0],gs.pieces[gs.selected]->body.getRot()[1],gs.pieces[gs.selected]->body.getRot()[2]);
|
//printf("Rotation : %f,%f,%f \n",gs.pieces[gs.selected]->body.getRot()[0],gs.pieces[gs.selected]->body.getRot()[1],gs.pieces[gs.selected]->body.getRot()[2]);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user