コード例 #1
0
ファイル: Vector3.cpp プロジェクト: janisozaur/foto-results
Vector3 Vector3::GetRotatedAxis(double angle, const Vector3 & axis) const {
    if(angle==0.0)
        return (*this);

    Vector3 u=axis.GetNormalized();

    Vector3 rotMatrixRow0, rotMatrixRow1, rotMatrixRow2;

    float sinAngle=(float)sin(M_PI*angle/180);
    float cosAngle=(float)cos(M_PI*angle/180);
    float oneMinusCosAngle=1.0f-cosAngle;

    rotMatrixRow0.x=(u.x)*(u.x) + cosAngle*(1-(u.x)*(u.x));
    rotMatrixRow0.y=(u.x)*(u.y)*(oneMinusCosAngle) - sinAngle*u.z;
    rotMatrixRow0.z=(u.x)*(u.z)*(oneMinusCosAngle) + sinAngle*u.y;

    rotMatrixRow1.x=(u.x)*(u.y)*(oneMinusCosAngle) + sinAngle*u.z;
    rotMatrixRow1.y=(u.y)*(u.y) + cosAngle*(1-(u.y)*(u.y));
    rotMatrixRow1.z=(u.y)*(u.z)*(oneMinusCosAngle) - sinAngle*u.x;

    rotMatrixRow2.x=(u.x)*(u.z)*(oneMinusCosAngle) - sinAngle*u.y;
    rotMatrixRow2.y=(u.y)*(u.z)*(oneMinusCosAngle) + sinAngle*u.x;
    rotMatrixRow2.z=(u.z)*(u.z) + cosAngle*(1-(u.z)*(u.z));

    return Vector3(DotProduct(rotMatrixRow0),
                   DotProduct(rotMatrixRow1),
                   DotProduct(rotMatrixRow2));
}
コード例 #2
0
 PHYSICSDLL_API OrbitComponent::OrbitComponent(Vector3 initialVec,
                                               Vector3 target, 
                                               float targetDist,
                                               float force)
                                               : targeting_(true),
                                                 force_(force),
                                                 target_dist_(targetDist),
                                                 current_dir_(initialVec.GetNormalized()),
                                                 target_(target),
                                                 Component(CT_OrbitComponent)
 {
 }
コード例 #3
0
 PHYSICSDLL_API void OrbitComponent::Update(float dt)
 {
   if (targeting_)
   {
     Transform* tr = (Transform*)GetSibling(CT_Transform);
     Vector3 forceVec = current_dir_;
     Vector3 toTarget = target_ - tr->GetPosition();
     float bias = toTarget.Length() / target_dist_;
     forceVec += toTarget.GetNormalized() * bias;
     PhysicsComponent* pComp = (PhysicsComponent*)GetSibling(CT_PhysicsComponent);
     if (pComp)
     {
       pComp->GetRigidBody()->AddForce(forceVec);
       current_dir_ = pComp->GetRigidBody()->GetState().Velocity.GetNormalized();
       pComp->GetRigidBody()->GetState().Velocity = pComp->GetRigidBody()->GetState().Velocity.GetNormalized() * 2.0f;
     }
   }
 }
コード例 #4
0
 MATHDLL_API float AngleBetween(const Vector3& left, const Vector3& right)
 {
   return acos(left.GetNormalized().Dot(right.GetNormalized()));
 }
コード例 #5
0
  Texture * Graphics::LoadBumpMap(const std::string & map)
  {
    std::vector <unsigned char> png;
    std::vector <unsigned char> image;
    std::vector <Vector4> normals;

    //x - tan
    //y - bitan

    unsigned width, height;
    lodepng::load_file(png, "Content/Textures/" + map);
    auto error = lodepng::decode(image, width, height, png);
    if(error)
    {
      auto realerror = lodepng_error_text(error);
      __debugbreak();
    }
    for(unsigned heightEntry = 0; heightEntry < height; ++heightEntry)
    {
      for(unsigned widthEntry = 0; widthEntry < width; ++widthEntry)
      {
        Vector3 uTan;
        Vector3 vTan;

        int leftSample;
        int rightSample;
        if((widthEntry + 1) < width)
        {
          rightSample = as_2d(image, width, heightEntry * 4, (widthEntry + 1) * 4);
        }
        else
        {
          rightSample = as_2d(image, width, heightEntry * 4, widthEntry * 4);
        }

        if(widthEntry > 0)
        {
          leftSample = as_2d(image, width, heightEntry * 4, (widthEntry - 1) * 4);
        }
        else
        {
          leftSample = as_2d(image, width, heightEntry * 4, widthEntry * 4);
        }

        uTan = Vector3(1.0f, 0.0f, (rightSample - leftSample));

        int topSample;
        int bottomSample;
        if((heightEntry + 1) < height)
        {
          topSample = as_2d(image, width, (heightEntry + 1) * 4, widthEntry * 4);
        }
        else
        {
          topSample = as_2d(image, width, heightEntry * 4, widthEntry * 4);
        }

        if(heightEntry > 0)
        {
          bottomSample = as_2d(image, width, (heightEntry - 1) * 4, widthEntry * 4); 
        }
        else
        {
          bottomSample = as_2d(image, width, heightEntry * 4, widthEntry * 4);
        }
        vTan = Vector3(0.0f, 1.0f, (topSample - bottomSample));
        uTan.Normalize();
        vTan.Normalize();
        Vector3 normal = uTan.Cross(vTan);
        normals.push_back(Vector4(normal.GetNormalized(), 0.0f));
      }
    }
    
    
    std::vector<unsigned char> normalColorVersion;
    for(auto& it : normals)
    {
      normalColorVersion.push_back((it.x + 1) * 0.5f * 255);
      normalColorVersion.push_back((it.y + 1) * 0.5f * 255);
      normalColorVersion.push_back((it.z + 1) * 0.5f * 255);
      normalColorVersion.push_back(255);
    }
    TextureDesc desc;
    desc.size.x = width;
    desc.size.y = height;
    desc.writable = false;
    Texture* newTex = graphicsAPI->MakeTexture(normalColorVersion, desc);
    textures_.insert(newTex->GetName(), newTex);
    newTex->Initialize();
    return newTex;
  }