本文整理汇总了C++中Vector4f::normalize方法的典型用法代码示例。如果您正苦于以下问题:C++ Vector4f::normalize方法的具体用法?C++ Vector4f::normalize怎么用?C++ Vector4f::normalize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Vector4f
的用法示例。
在下文中一共展示了Vector4f::normalize方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: get_color
Vector4f get_color(Vector4f viewer, Vector4f normal, Vector4f intersect){
Vector4f R = objects[hit_index].ka;
MatrixXf None(4,2); None<<0,0,0,0,0,0,0,0;
Ray testshadow;
MatrixXf is_shadow;
if (pt_light_counter != 0) {
for (int l = 0; l < pt_light_counter; l++) {
Vector4f pt_light_xyz = pt_xyz[l];
Vector4f pt_light_rgb = pt_rgb[l];
Vector4f light = pt_light_xyz - intersect;
light.normalize();
testshadow = Ray(intersect, light);
is_shadow = Find_nearest(testshadow, objects);
if(is_shadow==None){
Vector4f diffuse = diffuseTerm(kd, pt_light_rgb, normal, light);
Vector4f specular = specularTerm(ks, pt_light_rgb, normal, light, viewer, p);
Vector4f ambient = times(ka,pt_light_rgb);
R = R + (diffuse + specular + ambient);
}
}
}
if (dl_light_counter != 0) {
for (int l = 0; l < dl_light_counter; l++) {
Vector4f dl_light_rgb = dl_rgb[l];
Vector4f light = dl_xyz[l];
light.normalize();
testshadow = Ray(intersect, light);
is_shadow = Find_nearest(testshadow, objects);
if(is_shadow==None){
Vector4f diffuse = diffuseTerm(kd, dl_light_rgb, normal, light);
Vector4f specular = specularTerm(ks, dl_light_rgb, normal, light, viewer, p);
Vector4f ambient = times(ka,dl_light_rgb);
R = R + (diffuse + specular + ambient);
}
}
}
return R;
};
示例2: bind
void DeferredDirectionalLighting::bind(const DirectionalLight& light, const Matrix4f& modelView)
{
_program.bind();
//tell the shader about uniforms
GLint program = _program.getProgram();
Vector3f lightDir = light.getDirection();
//light in view space
Vector4f lightDirection(lightDir.x(),
lightDir.y(),
lightDir.z(),
0);
Vector4f lightDirectionView = (modelView) * lightDirection;
lightDirectionView.normalize();
glUniform3f(glGetUniformLocation(program, "lightdir"),
lightDirectionView.x(),
lightDirectionView.y(),
lightDirectionView.z());
}
示例3: Update
bool Quaternion::Update(){
if(_mOmega->getIsValided()){
Vector3f omega = _mOmega->getOmega() * MathTools::RADIAN_PER_DEGREE;
Vector4f q;
q << 0, omega[0], omega[1], omega[2];
Vector4f t;
t[0] = -q[1]*_Quaternion[1]-q[2]*_Quaternion[2]-q[3]*_Quaternion[3];
t[1] = q[1]*_Quaternion[0]+q[2]*_Quaternion[3]-q[3]*_Quaternion[2];
t[2] = -q[1]*_Quaternion[3]+q[2]*_Quaternion[0]+q[3]*_Quaternion[1];
t[3] = q[1]*_Quaternion[2]-q[2]*_Quaternion[1]+q[3]*_Quaternion[0];
Interval = App::mApp->mTicks->getTicks() - PrevTick;
PrevTick = App::mApp->mTicks->getTicks();
Interval /= 1000.0f;
if(Interval <= 0){
Valid = false;
return false;
}
t *= 0.5f * Interval;
q = _Quaternion + 0.5f * (t + PrevT);
PrevT = t;
q.normalize();
Vector3f e = QuaternionToEuler(q);
bool valid = true;
bool AccValid = _mAcceleration->getIsValided() && (_mAcceleration->getAcc().norm() > Acceleration::Gravity * 0.95f) && (_mAcceleration->getAcc().norm() < Acceleration::Gravity * 1.05f);
Vector3f angle;
bool MagValid;
if(IsUseCompass){
MagValid = _mCompass->getIsValided() && _mCompass->getMag().norm() > 0.9f && _mCompass->getMag().norm() < 1.1f;
}
if(AccValid){
angle = _mAcceleration->getAngle();
if(IsUseCompass && MagValid){
angle[2] = _mCompass->getAngle()[2];
}
else if(IsUseEncoderYaw){
angle[2] = _mEncoderYaw->getYaw();
}
else{
angle[2] = e[2];
}
}
else{
angle[0] = e[0];
angle[1] = e[1];
if(IsUseCompass && MagValid){
angle[2] = _mCompass->getAngle()[2];
}
else if(IsUseEncoderYaw){
angle[2] = _mEncoderYaw->getYaw();
}
else{
angle[2] = e[2];
}
}
Matrix3f A;
A.setIdentity();
Matrix3f H;
H.setIdentity();
if(valid && AccValid && _QuaternionKalman->Filtering(A, e, H, angle)){
angle = _QuaternionKalman->getCorrectedData();
for(int i = 0; i < 3; i++){
if(angle[i] != angle[i]){
Valid = false;
return false;
}
}
if(IsUseEncoderYaw && fabs(fabs(_mEncoderYaw->getYaw()) - MathTools::PI) < 0.01f){
angle[2] = _mEncoderYaw->getYaw();
}
_Euler = angle;
}
else{
_Euler = e;
}
_Quaternion = EulerToQuaternion(_Euler);
return true;
}
else{
Valid = false;
return false;
}
}
示例4: main
//.........这里部分代码省略.........
obj_counter = 1;
objects.push_back(test_sphere);
pt_light_counter = 0;
// pt_xyz[0] = Vector4f(1.0f, 1.0f, 1.0f, 1.0f);
// pt_rgb[0] = Vector4f(1.0f, 1.0f, 1.0f, 0.0f);
dl_light_counter = 0;
// printf("problem4\n");
bool gogo = true;
if (gogo){
for (int i=0; i<WIDTH; i++){
for (int j=0; j<HEIGHT; j++){
//construct a ray
if (i == 0 && j == 0){
printf("Ray Tracer Initialized, System Rendering. . .\n");
}
if (i == 0 && j == HEIGHT/2){
printf("Ray Tracing Running, 12.5 percent completed. . .\n");
}
if (i == 0 && j == HEIGHT){
printf("Ray Tracing Running, 25 percent completed. . .\n");
}
if (i == WIDTH/2 && j == 0){
printf("Ray Tracing Running, 37.5 percent completed. . .\n");
}
if (i == WIDTH/2 && j == HEIGHT/2){
printf("Ray Tracing Running, 50 percent completed. . .\n");
}
if (i == WIDTH/2 && j == HEIGHT){
printf("Ray Tracing Running, 62.5 percent completed. . .\n");
}
if (i == WIDTH && j == 0){
printf("Ray Tracing Running, 75 percent completed. . .\n");
}
if (i == WIDTH && j == HEIGHT/2){
printf("Ray Tracing Running, 86.5 percent completed. . .\n");
}
if (i == WIDTH && j == HEIGHT){
printf("Ray Tracing Running, 100 percent completed. . .\n");
}
float x = ((2.0f * (float) j) - (float) WIDTH) / (float)WIDTH * tanFovW;
float y = ((2.0f * (float) i) - (float) HEIGHT) / (float)HEIGHT * tanFovH;
Vector4f target = Vector4f(x, y, zNear, 0);
target.normalize();
Ray initialRay = Ray(camara_position, target);
// if ((initialRay.direction)[3] != 0 || (initialRay.origin)[3] != 1){
// cout << "\n";
// cout << "fuckfuck fuck fuck";
// cout << initialRay.origin << endl;
// cout << initialRay.direction << endl;
// cout << "\n";
// }
// printf(" sub_problem1\n");
Vector4f result = trace(initialRay, objects, TraceDepth);
// printf(" sub_problem2\n");
color.rgbRed = result[2]*255;
color.rgbGreen = result[1]*255;
color.rgbBlue = result[0]*255;
// if (color.rgbRed != 0 || color.rgbGreen != 0 || color.rgbBlue != 0){
// printf("weird, isn't it? but at least you got values");
// }
FreeImage_SetPixelColor (bitmap, i, j, &color);
}
}
}
// printf("problem5\n");
// delete [] objects;
// printf("problem6\n");
if (FreeImage_Save(FIF_PNG, bitmap, "test.png", 0))
cout << "Image successfully saved!" << endl;
FreeImage_DeInitialise();
}