File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -3718,31 +3718,23 @@ Matrix4x4 Npc::mkPositionMatrix() const {
37183718 const auto ground = groundNormal ();
37193719 const bool align = isAlignedToGround ();
37203720
3721- Matrix4x4 mt ;
3721+ float angY = mvAlgo. isDive () ? angleY : 0 ;
37223722 if (align) {
3723- auto oy = Vec3::normalize (ground);
3724- auto ox = Vec3::crossProduct (oy,{0 ,0 ,1 });
3725- auto oz = Vec3::crossProduct (oy,ox);
3726- float v[16 ] = {
3727- ox.x , ox.y , ox.z , 0 ,
3728- oy.x , oy.y , oy.z , 0 ,
3729- -oz.x ,-oz.y ,-oz.z , 0 ,
3730- x, y, z, 1
3731- };
3732- mt = Matrix4x4 (v);
3733- } else {
3734- float v[16 ] = {
3735- 1 , 0 , 0 , 0 ,
3736- 0 , 1 , 0 , 0 ,
3737- 0 , 0 , 1 , 0 ,
3738- x, y, z, 1
3739- };
3740- mt = Matrix4x4 (v);
3723+ float rot = rotationRad ();
3724+ float s = std::sin (rot), c = std::cos (rot);
3725+ auto dir = Vec3 (s,0 ,-c);
3726+ auto norm = Vec3::normalize (ground);
3727+
3728+ float cx = Vec3::dotProduct (norm,dir);
3729+ angY = -std::asin (cx)*180 .f /float (M_PI);
37413730 }
37423731
3732+ Matrix4x4 mt = Matrix4x4 ();
3733+ mt.identity ();
3734+ mt.translate (x,y,z);
37433735 mt.rotateOY (180 -angle);
3744- if (mvAlgo. isDive () )
3745- mt.rotateOX (-angleY );
3736+ if (angY!= 0 )
3737+ mt.rotateOX (-angY );
37463738 if (isPlayer () && !align) {
37473739 mt.rotateOZ (runAng);
37483740 }
You can’t perform that action at this time.
0 commit comments