本文整理汇总了C++中Vector4::Length方法的典型用法代码示例。如果您正苦于以下问题:C++ Vector4::Length方法的具体用法?C++ Vector4::Length怎么用?C++ Vector4::Length使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Vector4
的用法示例。
在下文中一共展示了Vector4::Length方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GetPointLightOnPoint
Vector4 LightInfo::GetPointLightOnPoint(const Vector4& _cameraSpacePoint, const Vector4& _point, const Vector4& _normal, int _lightIndex, const Vector4& _diffuse, const Vector4& _specular) {
// Get the difference in position from the light and the point.
Vector4 diff = GetPointLights()[_lightIndex].GetPosition() - _point;
Vector4 lightDirection = diff;
// The distance
float distance = diff.Length();
// The direction
diff.Normalize();
// The attenuation
float attenuation = GetPointLights()[_lightIndex].GetAttenuation(distance);
// Diffuse lighting.
Vector4 pointColor = GetPointLights()[_lightIndex].GetIntensity()
* diff.Dot(_normal)
* attenuation
* _diffuse;
pointColor.Clamp();
// Specular
// We get the half angle between the camera and the direction to the camera.
Vector4 halfAngle = lightDirection + _cameraSpacePoint;
halfAngle.Normalize();
Vector4 specular = _specular * powf(halfAngle.Dot(_normal), 10) * attenuation;
specular.Clamp();
pointColor += specular;
return pointColor;
}
示例2: AddImpulse
static void AddImpulse(void)
{
static Vector4 vPosition(0.0f, 0.0f, 0.0f, 0.0f);
//Vector4 vDiff = vPosition - g_vPosition;
Vector4 vDiff = g_vPosition - vPosition;
Vector4 vLength = vDiff.Length();
if ( vLength[0]<2.0f )
return;
Vector4 vDir = vDiff / vLength;
Vector4 vVec0(vDir[1],-vDir[0], 0.0f, 0.0f);
Vector4 vVec1(vDir[0], vDir[1], 0.0f, 0.0f);
vPosition = g_vPosition;
Vector4 vVec0_old = g_orient_matrix[0];
Vector4 vVec1_old = g_orient_matrix[1];
Vector4 vVec0_new = VectorLerp(vVec0_old, vVec0, 0.2f);
Vector4 vVec1_new = VectorLerp(vVec1_old, vVec1, 0.2f);
vVec0_new.Normalize();
vVec1_new.Normalize();
Vector4 vVec2_new = Vector3CrossProduct(vVec0_new, vVec1_new);
g_orient_matrix.Identity();
g_orient_matrix[0] = vVec0_new;
g_orient_matrix[1] = vVec1_new;
g_orient_matrix[2] = vVec2_new;
LPDIRECT3DDEVICE9 device = GutGetGraphicsDeviceDX9();
device->SetRenderTarget(0, g_pSurfaces[TEX_HEIGHT1]);
device->SetDepthStencilSurface(NULL);
Matrix4x4 view_matrix = g_Control.GetViewMatrix();
Matrix4x4 world_matrix;
world_matrix.Scale_Replace(g_fRippleSize, g_fRippleSize, 1.0f);
world_matrix[3] = g_vPosition;
Matrix4x4 wvp_matrix = g_orient_matrix * world_matrix * view_matrix * g_proj_matrix;
D3DXHANDLE shader = g_pWaterEffect->GetTechniqueByName("AddImpulse");
D3DXHANDLE wvp_matrix_var = g_pWaterEffect->GetParameterByName(NULL, "wvp_matrix");
D3DXHANDLE force_var = g_pWaterEffect->GetParameterByName(NULL, "fForce");
g_pWaterEffect->SetTechnique(shader);
g_pWaterEffect->SetMatrix(wvp_matrix_var, (D3DXMATRIX *)&wvp_matrix);
g_pWaterEffect->SetFloat(force_var, 0.05f);
g_pWaterEffect->Begin(NULL, 0);
g_pWaterEffect->BeginPass(0);
g_Model_DX9.Render(0);
g_pWaterEffect->EndPass();
g_pWaterEffect->End();
vPosition = g_vPosition;
}
示例3: UtcDaliRandomAxisMethod
int UtcDaliRandomAxisMethod(void)
{
TestApplication application; // Reset all test adapter return codes
for(size_t i=0; i<100; i++)
{
Vector4 axis = Dali::Random::Axis();
DALI_TEST_EQUALS(axis.Length(), 1.0f, 0.0001f, TEST_LOCATION);
}
END_TEST;
}
示例4: MouseMove
GLvoid Scene::MouseMove( GLint x, GLint y, GLboolean &isNeedRedisplay ){
GLint dx,dy;
if ( _camera->_isScaling || _camera->_isMoving || _camera->_isRotating )
{
dx = x - _prevMouseX;
dy = - ( y - _prevMouseY );
if ( dx == 0 && dy == 0 ) return;
if ( _camera->_isRotating )
{
Vector4 v;
v[0] = (GLfloat) dx;
v[1] = (GLfloat) dy;
v[2] = v[3] = 0.0f;
Vector4 vz;
vz[0] = vz[1] = vz[3] = 0.0f;
vz[2] = 1.0f;
v = vz%v;
GLfloat length = v.Length();
v *= 1.0f / length;
_camera->_rotateAngle = Quaternion(v[0],v[1],v[2],length * _camera->_rotateGridSize ) * _camera->_rotateAngle_ref;
_camera->_isNeedUpdateMatrix = true;
_mainCraft->_rotation = Quaternion(v[0],v[1],v[2],-length * _camera->_rotateGridSize ) * _camera->_rotateAngle_ref;
isNeedRedisplay = true;
}
else if ( _camera->_isMoving )
{
GLfloat distance_eye = ( _camera->_viewport[1] * 0.5f) / tanf( _camera->_viewfields * PI / 360.0f );
_camera->_translate[0] = _camera->_translate_ref[0] - (GLfloat)dx / distance_eye * _camera->_initialDistanceZ;
_camera->_translate_ref[1] = _camera->_translate_ref[1] - (GLfloat)dy / distance_eye * _camera->_initialDistanceZ;
_camera->_isNeedUpdateMatrix = true;
isNeedRedisplay = true;
}
else if ( _camera->_isScaling)
{
_camera->_scale = _camera->_scale_ref * expf( _camera->_scaleRatio * (GLfloat)dy );
_camera->_isNeedUpdateMatrix = true;
isNeedRedisplay = true;
}
}
}
示例5: GetSpotLightOnPoint
// Get the spot light info on a point.
Vector4 LightInfo::GetSpotLightOnPoint(const Vector4& _cameraSpacePoint, const Vector4& _point, const Vector4& _normal, int _lightIndex, const Vector4& _diffuse, const Vector4& _specular) {
// Get the difference in position from the light and the point.
Vector4 diff = GetSpotLights()[_lightIndex].GetPosition() - _point;
Vector4 lightDirection = diff;
// The distance
float distance = diff.Length();
// The direction
diff.Normalize();
// Calculate the spot light values
float spotLightValue = diff.Dot(GetSpotLights()[_lightIndex].GetDirection() * -1);
if (spotLightValue > 0.2f)
return Vector4(0, 0, 0, 0);
float smoothing = GetSpotLights()[_lightIndex].SmoothStep(diff.Dot(_normal));
// The attenuation
float attenuation = GetSpotLights()[_lightIndex].GetAttenuation(distance);
// Diffuse lighting.
Vector4 pointColor = GetSpotLights()[_lightIndex].GetIntensity()
* diff.Dot(_normal)
* attenuation
* _diffuse
* spotLightValue;
// Specular
// We get the half angle between the camera and the direction to the camera.
Vector4 halfAngle = lightDirection + _cameraSpacePoint;
halfAngle.Normalize();
pointColor += _specular * powf(halfAngle.Dot(_normal), 10) * attenuation;
return pointColor;
}
示例6: Compute
// pocitanie funkcie pre vsetky trojuholniky, O(n2)
void CSDFController::Compute(LinkedList<Face>* triangles, Octree* root)
{
float min = FLOAT_MAX;
float max = 0.0;
unsigned int n_rays = 30;
float angle = 120.0f;
unsigned int counter = 0;
//------------------prealocated variables------------------
Vector4 tangens, normal, binormal;
Mat4 t_mat;
std::vector<float> rays;
std::vector<float> weights;
// precompute those N rays
srand (123); // initial seed for random number generator
float* rndy = new float[n_rays];
float* rndx = new float[n_rays];
for(unsigned int i = 0; i < n_rays; i++)
{
rndy[i] = float(rand()%int(angle / 2));
rndx[i] = float(rand()%(360));
if(rndy[i] == 0.0)
rndy[i] = 0.5;
}
float dist = FLOAT_MAX;
float dist2 = FLOAT_MAX;
float theta = 0.0f;
bool intersected = false;
LinkedList<Face>* face_list = NULL;
LinkedList<Face>::Cell<Face>* intersected_face = NULL;
//------------------prealocated variables------------------
LinkedList<Face>::Cell<Face>* current_face = triangles->start;
while(current_face != NULL)
{
// vypocet TNB vektorov a matice
ComputeTNB(current_face->data, tangens, normal, binormal);
t_mat = Mat4(tangens, normal, binormal);
rays.clear();
weights.clear();
for(unsigned int i = 0; i < n_rays; i++)
{
Vector4 ray = CalcRayFromAngle(rndx[i], rndy[i]) * t_mat;
ray.Normalize();
dist = FLOAT_MAX;
face_list = GetFaceList(triangles, root, current_face->data->center, ray);
intersected_face = face_list->start;
while(intersected_face != NULL)
{
if(current_face == intersected_face)
{
intersected_face = intersected_face->next;
continue;
}
dist2 = FLOAT_MAX;
intersected = rayIntersectsTriangle(current_face->data->center, ray, intersected_face->data->v[0]->P, intersected_face->data->v[1]->P, intersected_face->data->v[2]->P, dist2);
if(intersected == true)
{
theta = acos( (ray * intersected_face->data->normal) / (ray.Length() * intersected_face->data->normal.Length()) );
theta = theta * float(180.0 / M_PI);
//loggger->logInfo(MarshalString("pridany ray s thetou: " + theta));
if((theta < 90.0f) && (dist2 < dist))
dist = dist2;
}
intersected_face = intersected_face->next;
}
if(dist < (FLOAT_MAX - 1.0f))
{
//loggger->logInfo(MarshalString("pridany ray s dlzkou: " + dist));
rays.push_back(dist);
weights.push_back(180.0f - rndy[i]);
}
//if(root != NULL)
//delete face_list; // generated list, bez prealokovania
}
if(rays.size() > 0)
{
current_face->data->ComputeSDFValue(rays, weights);
if(current_face->data->diameter->value < min)
min = current_face->data->diameter->value;
if(current_face->data->diameter->value > max)
max = current_face->data->diameter->value;
}
counter = counter + 1;
current_face = current_face->next;
}
fc_list->Clear();
oc_list->Clear();
delete [] rndy;
delete [] rndx;
//.........这里部分代码省略.........