本文整理汇总了C++中ray::normalizeDirection方法的典型用法代码示例。如果您正苦于以下问题:C++ ray::normalizeDirection方法的具体用法?C++ ray::normalizeDirection怎么用?C++ ray::normalizeDirection使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ray
的用法示例。
在下文中一共展示了ray::normalizeDirection方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Get3DPos
//
// main.m
// GC3AssignmentTwo
//
// Created by Meraj Patel on 11/8/2013.
// Copyright (c) 2013 Meraj Patel. All rights reserved.
//
#include <stdlib.h>
#include <GLUT/glut.h>
#include "MathLibrary.h"
#include "PhysicsEngine.h"
#include "Particle.h"
#include "Texture.h"
#include <math.h>
#include "ray.h"
#include "Texture.h"
#include "Points.h"
ray newRay;
bool hit1, hit2;
double transparentWall1 = 1;
double transparentWall2 = 1;
int orientation[3] = {0,1,0};
bool flip1, flip2;
float moveY = -2;
float angY = 9*sin(1.05);//roation around Y
double camera[3] = {0,9,9};//declares camera at position
double bounceY = 0;
int x = -1;
PhysicsEngine game;
Texture textureObeject;
bool cameraParticlePosition = false;
bool startStop = true;
bool lightswitch = true;
bool gameOver = false;
void Get3DPos(int x, int y, float winz, GLdouble point[3])
{
GLint viewport[4];
GLdouble modelview[16];
GLdouble projection[16];
//get the matrices
glGetDoublev( GL_MODELVIEW_MATRIX, modelview );
glGetDoublev( GL_PROJECTION_MATRIX, projection );
glGetIntegerv( GL_VIEWPORT, viewport );
//"un-project" the 2D point giving the 3D position corresponding to the provided depth (winz)
gluUnProject( (float)x, (float)(viewport[3]-y), winz, modelview, projection, viewport, &point[0], &point[1], &point[2]);
}
///* rayCast - takes a mouse x,y, coordinate, and casts a ray through that point
// * for subsequent intersection tests with objects.
// */
void rayCast(float x, float y)
{
bool groundPlane = true;//check if hit on plane
GLdouble pNear[3];//depth for z
GLdouble pFar[3]; //depth for z
float inter[3];//stores object intersection
//count through number of objects to perform tests on each one
//count through number of planes of each object to perform test on each one
for (int count1 = 0; count1 < game.ActiveObjects.size(); count1++) {
for(int count2 = 0; count2 < 6; count2++) {
Get3DPos(x, y, 0.0, pNear);
Get3DPos(x, y, 1.0, pFar);
//store ray orgin
newRay.org[0] = camera[0];
newRay.org[1] = camera[1];
newRay.org[2] = camera[2];
//ray direction is the vector (pFar - pNear)
newRay.dir[0] = pFar[0] - pNear[0];
newRay.dir[1] = pFar[1] - pNear[1];
newRay.dir[2] = pFar[2] - pNear[2];
newRay.normalizeDirection();
groundPlane = newRay.rayPlaneTest(count1, count2, game.ActiveObjects);
//update the position of the object to the intersection point
if ( groundPlane == true) {
//check if object is hit between min and max bounds
if ((game.ActiveObjects.at(count1).min + game.ActiveObjects.at(count1).translateX < newRay.inter[0] && newRay.inter[0] < game.ActiveObjects.at(count1).max + game.ActiveObjects.at(count1).translateX && game.ActiveObjects.at(count1).min + game.ActiveObjects.at(count1).translateZ < newRay.inter[2] && newRay.inter[2] < game.ActiveObjects.at(count1).max + game.ActiveObjects.at(count1).translateZ && inter[1] < game.ActiveObjects.at(count1).max + game.ActiveObjects.at(count1).translateY && game.ActiveObjects.at(count1).min + game.ActiveObjects.at(count1).translateY < newRay.inter[1])) {
game.ActiveObjects.at(count1).hit = true;
//check to see right click to delete object
break;
}
//return false hit else wise
else {
game.ActiveObjects.at(count1).hit = false;
}
}
} //break out of cycle of object
if(game.ActiveObjects.at(count1).hit == true) {
for(int z = 0; z < game.ActiveObjects.size(); z++) {
//.........这里部分代码省略.........