|
@@ -866,8 +866,12 @@ void tnsClearTranslation44d(tnsMatrix44d mat){
|
|
|
mat[11] = 0;
|
|
|
}
|
|
|
|
|
|
-void tnsExtractXYZEuler44d(tnsMatrix44d mat, real *xyz_result){
|
|
|
+void tnsExtractXYZEuler44d(tnsMatrix44d _mat, real *xyz_result){
|
|
|
real xRot, yRot, zRot;
|
|
|
+ tnsMatrix44d mat; tnsCopyMatrix44d(_mat,mat);
|
|
|
+ tnsNormalizeSelf3d(&mat[0]);
|
|
|
+ tnsNormalizeSelf3d(&mat[4]);
|
|
|
+ tnsNormalizeSelf3d(&mat[8]);
|
|
|
|
|
|
if (mat[2] < 1){
|
|
|
if (mat[2] > -1){
|
|
@@ -894,9 +898,10 @@ void tnsExtractLocation44d(tnsMatrix44d mat, real *xyz_result){
|
|
|
xyz_result[1] = mat[13];
|
|
|
xyz_result[2] = mat[14];
|
|
|
}
|
|
|
-void tnsExtractUniformScale44d(tnsMatrix44d mat, real *uniform_result){
|
|
|
- tnsVector3d v = {mat[0], mat[1], mat[2]};
|
|
|
- *uniform_result = tnsLength3d(v);
|
|
|
+void tnsExtractScale44d(tnsMatrix44d mat, real *xyz_result){
|
|
|
+ xyz_result[0] = tnsLength3d(&mat[0]);
|
|
|
+ xyz_result[1] = tnsLength3d(&mat[4]);
|
|
|
+ xyz_result[2] = tnsLength3d(&mat[8]);
|
|
|
}
|
|
|
|
|
|
#define L(row, col) l[(col << 2) + row]
|
|
@@ -1113,9 +1118,7 @@ void tnsMakeRotationZMatrix44d(tnsMatrix44d m, real angle_rad){
|
|
|
}
|
|
|
void tnsMakeScaleMatrix44d(tnsMatrix44d m, real x, real y, real z){
|
|
|
tnsLoadIdentity44d(m);
|
|
|
- m[0] = x;
|
|
|
- m[5] = y;
|
|
|
- m[10] = z;
|
|
|
+ m[0] = x; m[5] = y; m[10] = z;
|
|
|
}
|
|
|
void tnsMakeViewportMatrix44d(tnsMatrix44d m, real w, real h, real Far, real Near){
|
|
|
tnsLoadIdentity44d(m);
|
|
@@ -3111,25 +3114,25 @@ void tnsExtractDeltaTransformValue(tnsObject *o){
|
|
|
if (!o) return;
|
|
|
tnsExtractLocation44d(o->DeltaTransform, o->DLocation);
|
|
|
tnsExtractXYZEuler44d(o->DeltaTransform, o->DRotation);
|
|
|
- tnsExtractUniformScale44d(o->DeltaTransform, &o->DScale);
|
|
|
+ tnsExtractScale44d(o->DeltaTransform, o->DScale);
|
|
|
}
|
|
|
void tnsExtractSelfTransformValue(tnsObject *o){
|
|
|
if (!o) return;
|
|
|
tnsExtractLocation44d(o->SelfTransform, o->Location);
|
|
|
tnsExtractXYZEuler44d(o->SelfTransform, o->Rotation);
|
|
|
- tnsExtractUniformScale44d(o->SelfTransform, &o->Scale);
|
|
|
+ tnsExtractScale44d(o->SelfTransform, o->Scale);
|
|
|
}
|
|
|
void tnsExtractGlobalTransformValue(tnsObject *o){
|
|
|
if (!o) return;
|
|
|
tnsExtractLocation44d(o->GlobalTransform, o->GLocation);
|
|
|
tnsExtractXYZEuler44d(o->GlobalTransform, o->GRotation);
|
|
|
- tnsExtractUniformScale44d(o->GlobalTransform, &o->GScale);
|
|
|
+ tnsExtractScale44d(o->GlobalTransform, o->GScale);
|
|
|
}
|
|
|
void tnsCopyGlobalTransform(tnsObject *to, tnsObject *from){
|
|
|
memcpy(to->GlobalTransform, from->GlobalTransform, sizeof(tnsMatrix44d));
|
|
|
memcpy(to->GLocation, from->GLocation, sizeof(tnsVector3d));
|
|
|
memcpy(to->GRotation, from->GRotation, sizeof(tnsVector3d));
|
|
|
- to->GScale = from->GScale;
|
|
|
+ memcpy(to->GScale, from->GScale, sizeof(tnsVector3d));
|
|
|
tnsGlobalTransformValueChanged(to);
|
|
|
}
|
|
|
|
|
@@ -3176,7 +3179,10 @@ void tnsSelfTransformValueChanged(tnsObject* o){
|
|
|
tnsMatrix44d Trans, Rot1, Rot2, Rot3, Scale, Res1, Res2;
|
|
|
tnsLoadIdentity44d(o->SelfTransform);
|
|
|
tnsMakeTranslationMatrix44d(Trans, LA_COLOR3(o->Location));
|
|
|
- tnsMakeScaleMatrix44d(Scale, o->Scale,o->Scale,o->Scale);
|
|
|
+ if(o->Scale[0]<1e-5){ o->Scale[0]=1e-5; }
|
|
|
+ if(o->Scale[1]<1e-5){ o->Scale[1]=1e-5; }
|
|
|
+ if(o->Scale[2]<1e-5){ o->Scale[2]=1e-5; }
|
|
|
+ tnsMakeScaleMatrix44d(Scale, LA_COLOR3(o->Scale));
|
|
|
|
|
|
tnsMakeRotationXMatrix44d(Rot1, o->Rotation[0]);
|
|
|
tnsMakeRotationYMatrix44d(Rot2, o->Rotation[1]);
|
|
@@ -3196,7 +3202,7 @@ void tnsDeltaTransformValueChanged(tnsObject* o){
|
|
|
tnsMatrix44d Trans, Rot1, Rot2, Rot3, Scale, Res1, Res2;
|
|
|
tnsLoadIdentity44d(o->DeltaTransform);
|
|
|
tnsMakeTranslationMatrix44d(Trans, LA_COLOR3(o->DLocation));
|
|
|
- tnsMakeScaleMatrix44d(Scale, o->DScale,o->DScale,o->DScale);
|
|
|
+ tnsMakeScaleMatrix44d(Scale, LA_COLOR3(o->DScale));
|
|
|
|
|
|
tnsMakeRotationXMatrix44d(Rot1, o->DRotation[0]);
|
|
|
tnsMakeRotationYMatrix44d(Rot2, o->DRotation[1]);
|
|
@@ -3216,7 +3222,7 @@ void tnsGlobalTransformValueChanged(tnsObject* o){
|
|
|
tnsMatrix44d Trans, Rot1, Rot2, Rot3, Scale, Res1, Res2;
|
|
|
tnsLoadIdentity44d(o->GlobalTransform);
|
|
|
tnsMakeTranslationMatrix44d(Trans, LA_COLOR3(o->GLocation));
|
|
|
- tnsMakeScaleMatrix44d(Scale, o->GScale,o->GScale,o->GScale);
|
|
|
+ tnsMakeScaleMatrix44d(Scale, LA_COLOR3(o->GScale));
|
|
|
|
|
|
tnsMakeRotationXMatrix44d(Rot1, o->GRotation[0]);
|
|
|
tnsMakeRotationYMatrix44d(Rot2, o->GRotation[1]);
|
|
@@ -3244,15 +3250,9 @@ void tnsInitObjectBase(tnsObject *o, tnsObject *under, char *Name, int Type,
|
|
|
if (!o) return;
|
|
|
strSafeSet(&o->Name, Name);
|
|
|
o->Type = Type;
|
|
|
- o->Location[0] = AtX;
|
|
|
- o->Location[1] = AtY;
|
|
|
- o->Location[2] = AtZ;
|
|
|
- o->Rotation[0] = RotX;
|
|
|
- o->Rotation[1] = RotY;
|
|
|
- o->Rotation[2] = RotZ;
|
|
|
- o->Rotation[3] = RotW;
|
|
|
- o->RotationMode = RotationMode;
|
|
|
- o->Scale = Scale;
|
|
|
+ tnsVectorSet3(o->Location,AtX,AtY,AtZ);
|
|
|
+ tnsVectorSet4(o->Rotation,RotX,RotY,RotZ,RotW); o->RotationMode = RotationMode;
|
|
|
+ tnsVectorSet3(o->Scale,Scale,Scale,Scale);
|
|
|
o->Show = 1;
|
|
|
o->DrawMode = GL_LINE_LOOP;
|
|
|
tnsLoadIdentity44d(o->DeltaTransform);
|
|
@@ -3290,13 +3290,13 @@ void tnsUnparentObject(tnsObject *o, int KeepTransform){
|
|
|
void tnsCopyObjectTransformationsLocal(tnsObject* to, tnsObject* from){
|
|
|
tnsVectorCopy3d(from->Location, to->Location);
|
|
|
tnsVectorCopy3d(from->Rotation, to->Rotation); to->RotationMode=from->RotationMode;
|
|
|
- to->Scale = from->Scale;
|
|
|
+ tnsVectorCopy3d(from->Scale, to->Scale);
|
|
|
tnsSelfTransformValueChanged(to);
|
|
|
}
|
|
|
void tnsCopyObjectTransformationsGlobal(tnsObject* to, tnsObject* from){
|
|
|
tnsVectorCopy3d(from->GLocation, to->GLocation);
|
|
|
tnsVectorCopy3d(from->GRotation, to->GRotation); to->RotationMode=from->RotationMode;
|
|
|
- to->GScale = from->GScale;
|
|
|
+ tnsVectorCopy3d(from->GScale, to->GScale);
|
|
|
tnsGlobalTransformValueChanged(to);
|
|
|
}
|
|
|
void tnsRotateObjectLocalValues(tnsObject *o, real x, real y, real z){
|
|
@@ -3309,7 +3309,7 @@ void tnsSetObjectPositionLocal(tnsObject*o, real x, real y, real z){
|
|
|
void tnsResetObjectTransformations(tnsObject* o, int reset_loc,int reset_rot,int reset_sca){
|
|
|
if(reset_loc){ tnsVectorSet3(o->Location,0,0,0); }
|
|
|
if(reset_rot){ tnsVectorSet4(o->Rotation,0,0,0,0); }
|
|
|
- if(reset_sca){ o->Scale=1; }
|
|
|
+ if(reset_sca){ tnsVectorSet3(o->Rotation,1,1,1); }
|
|
|
tnsSelfTransformValueChanged(o);
|
|
|
}
|
|
|
void tnsMoveObjectLocal(tnsObject *o, real x, real y, real z){
|
|
@@ -3408,28 +3408,27 @@ void tnsRotateObjectGlobalForDelta(tnsObject *o, real x, real y, real z, real an
|
|
|
//memcpy(o->GlobalTransform, res1, sizeof(tnsMatrix44d));
|
|
|
tnsGlobalMatrixChangedForDelta(o,1);
|
|
|
}
|
|
|
-void tnsScaleObject(tnsObject *o, real fac, real cx,real cy,real cz){
|
|
|
+void tnsScaleObject(tnsObject *o, real x,real y,real z, real cx,real cy,real cz){
|
|
|
tnsMatrix44d sca,res1,res2;
|
|
|
- tnsMakeScaleMatrix44d(sca,fac,fac,fac);
|
|
|
+ tnsMakeScaleMatrix44d(sca,x,y,z);
|
|
|
tnsMultiply44d(res1,o->GlobalTransform,sca);
|
|
|
tnsVector3d delta; delta[0]=res1[12]-cx; delta[1]=res1[13]-cy; delta[2]=res1[14]-cz;
|
|
|
tnsVector3d c; c[0]=cx; c[1]=cy; c[2]=cz;
|
|
|
- tnsVectorMultiSelf3d(delta, fac);
|
|
|
+ delta[0]*=x; delta[1]*=y; delta[2]*=z;
|
|
|
tnsVectorPlus3d(&res1[12],c,delta);
|
|
|
memcpy(o->GlobalTransform, res1, sizeof(tnsMatrix44d));
|
|
|
tnsGlobalMatrixChanged(o,1);
|
|
|
}
|
|
|
-void tnsScaleObjectDelta(tnsObject *o, real fac, real cx,real cy,real cz){
|
|
|
+void tnsScaleObjectDelta(tnsObject *o, real x,real y,real z, real cx,real cy,real cz){
|
|
|
tnsMatrix44d sca,res1,res2;
|
|
|
- tnsMakeScaleMatrix44d(sca,fac,fac,fac);
|
|
|
- tnsMultiply44d(res1,o->DeltaTransform,sca);
|
|
|
+ tnsMakeScaleMatrix44d(sca,x,y,z);
|
|
|
+ tnsMultiply44d(res1,o->GlobalTransform,sca);
|
|
|
tnsVector3d delta; delta[0]=res1[12]-cx; delta[1]=res1[13]-cy; delta[2]=res1[14]-cz;
|
|
|
tnsVector3d c; c[0]=cx; c[1]=cy; c[2]=cz;
|
|
|
- tnsVectorMultiSelf3d(delta, fac);
|
|
|
+ delta[0]*=x; delta[1]*=y; delta[2]*=z;
|
|
|
tnsVectorPlus3d(&res1[12],c,delta);
|
|
|
- memcpy(o->DeltaTransform, res1, sizeof(tnsMatrix44d));
|
|
|
- tnsExtractDeltaTransformValue(o);
|
|
|
- tnsSelfMatrixChanged(o,1);
|
|
|
+ memcpy(o->GlobalTransform, res1, sizeof(tnsMatrix44d));
|
|
|
+ tnsGlobalMatrixChangedForDelta(o,1);
|
|
|
}
|
|
|
void tnsZoomViewingCamera(tnsCamera *c, real Ratio){
|
|
|
if (c->FocusDistance < 0.1) return;
|