本文整理汇总了C++中Vector4D::DotProduct方法的典型用法代码示例。如果您正苦于以下问题:C++ Vector4D::DotProduct方法的具体用法?C++ Vector4D::DotProduct怎么用?C++ Vector4D::DotProduct使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Vector4D
的用法示例。
在下文中一共展示了Vector4D::DotProduct方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
//------------------------------------------------------------------------------------------------------
//function that multiplies two Matrix objects together
//------------------------------------------------------------------------------------------------------
Matrix4D& Matrix4D::operator*(Matrix4D& rhs)
{
//variable to keep track of each matrix element of final result
int count = 0;
//the final matrix result object and two Vector4D objects
//are needed to calculate each row and column multiplication
Matrix4D result;
Vector4D<float> leftRow;
Vector4D<float> topColumn;
//loop through each of the top matrix columns
for(int i = 0; i < 4; i++)
{
//assign the elements from top to bottom
topColumn.X = rhs[i * 4];
topColumn.Y = rhs[i * 4 + 1];
topColumn.Z = rhs[i * 4 + 2];
topColumn.W = rhs[i * 4 + 3];
//loop through each of the left matrix rows
for(int j = 0; j < 4; j++)
{
//assign the elements from left to right
leftRow.X = m_matrix[j];
leftRow.Y = m_matrix[j + 4];
leftRow.Z = m_matrix[j + 8];
leftRow.W = m_matrix[j + 12];
//use dot product to produce each matrix element result
result[count++] = leftRow.DotProduct(topColumn);
}
}
//assign result to Matrix object and return reference
//of lhs matrix to allow for multiplication chaining
return (*this = result);
}
示例2: ProcessLighting
void CRenderObjectsManager::ProcessLighting(CRenderObject* pobj,POLYGON& poly)
{
VERTICESLIST &pointlist = pobj->m_translateverticesList;
int v_index1 = poly.v[0];
int v_index2 = poly.v[1];
int v_index3 = poly.v[2];
//Get the original r,g,b,a
bool bHasTexture = poly.state & OBJECT_HAS_TEXTURE;
UCHAR r_base = bHasTexture ?255:poly.color.r;
UCHAR g_base = bHasTexture ? 255:poly.color.g;
UCHAR b_base = bHasTexture?255: poly.color.b;
UCHAR a_base = bHasTexture?0:poly.color.a;//to do.modify here
int r_sum=0,g_sum = 0,b_sum = 0;
int ilightsize = m_pLightingManager->GetLightsCount();
const LIGHTSLIST& lightslist = m_pLightingManager->GetLights();
CLight *light = NULL;
//Get the normal direction
Vector4D P0P1 = pointlist[v_index2].vertex - pointlist[v_index1].vertex;
Vector4D P1P2 = pointlist[v_index3].vertex - pointlist[v_index1].vertex;
Vector4D N = P0P1.CrossProduct(P1P2);
N.Normalize();
for(int i = 0; i < ilightsize;++i)
{
light = lightslist[i];
if(!light->IsEnable()) continue;
//Get the cos value of the angle between the light and normal
Vector4D lightdir = light->m_lightdir;
float coslight2normal = N.DotProduct(-1*lightdir);
const CLight::LightType lighttype = light->GetLightType();
if(lighttype == CLight::kAmbientLight)
{
r_sum += ((light->m_amblient.r * r_base)/256);
g_sum += ((light->m_amblient.g * g_base)/256);
b_sum += ((light->m_amblient.b * b_base)/256);
}
if(lighttype == CLight::kInfiniteLigtht)
{
if(coslight2normal>0)
{
r_sum += ((light->m_diffuse.r * r_base *coslight2normal)/256);
g_sum += ((light->m_diffuse.g * g_base*coslight2normal)/256);
b_sum += ((light->m_diffuse.b * b_base*coslight2normal)/256);
}
}
if(lighttype == CLight::kPointLight)
{
// c = c_diffuse * I/(kc+kl*d+kq*d^2);
//
Vector4D vertex2lightpos = Vector4D(light->m_lightpos- pointlist[v_index1].vertex);
float d = vertex2lightpos.GetLength();
float l = vertex2lightpos.DotProduct(N);
float cosv = N.DotProduct(vertex2lightpos);
if(cosv >0)
{
cosv = cosv/d;
float k = light->m_kconst + light->m_klinear * d + light->m_kquadratic*d*d;
float fDiv = k*256;//k*256
r_sum += ((light->m_diffuse.r * r_base *cosv)/fDiv);
g_sum += ((light->m_diffuse.g * g_base*cosv)/fDiv);
b_sum += ((light->m_diffuse.b * b_base*cosv)/fDiv);
}
}
if(lighttype == CLight::kSpotLight)
{
//use this model
// c = c_diffuse * I*MAX(COSa,0)^pf/(kc+kl*d+kq*d^2)
float l = N.DotProduct(-1*lightdir);
if(l >0)
{
Vector4D vertex2lightpos = Vector4D(light->m_lightpos-pointlist[v_index1].vertex );
float d = vertex2lightpos.GetLength();
//calculate the cos value of light direction and vertext->lightpos
float l = N.DotProduct(vertex2lightpos);
if(l > 0)
{
float cosv = l/d;
float dl = cosv;
for(int i = 1; i < light->m_pf;++i)
dl *= cosv;
float k = light->m_kconst + light->m_klinear * d + light->m_kquadratic*d*d;
float fDiv = k*256;//k*256
r_sum += ((light->m_diffuse.r * r_base *dl)/fDiv);
g_sum += ((light->m_diffuse.g * g_base*dl)/fDiv);
b_sum += ((light->m_diffuse.b * b_base*dl)/fDiv);
//.........这里部分代码省略.........