void display(void) { glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); glBindBuffer(GL_ARRAY_BUFFER,buffer); mv = LookAt( eye, eye - n, up ); model_view = mv; // for(int i= -5; i<=5; i++) // for(int j= -5; j<=5; ++j) { // model_view = mv * Translate(i*3.0f,j*3.0f, 0.0f); traverse(head); } glutSwapBuffers(); }
Camera::Camera(float theta, float phi, float radius) : mPos(XMFLOAT3(0.0f,0.0f,0.0f)), mTheta(theta), mPhi(phi), mRadius(radius), mLook(XMFLOAT3(0.0f, 0.0f, 1.0f)), mUp(XMFLOAT3(0.0f, 1.0f, 0.0f)), mRight(XMFLOAT3(1.0f, 0.0f, 0.0f)) { XMMATRIX I = XMMatrixIdentity(); XMStoreFloat4x4(&mView, I); XMStoreFloat4x4(&mProj, I); LookAt(mPos, mLook, mUp); UpdateView(); }
//---------------------------------------------------------------------------- // The passive motion callback for a window is called when the mouse moves within the window while no mouse buttons are pressed. void Win_PassiveMotion(int x, int y) { g_fPhi = (float)-M_PI*(x - HALF_SIZE)/(HALF_SIZE); // 轉換成 g_fPhi 介於 -PI 到 PI 之間 (-180 ~ 180 之間) g_fTheta = (float)M_PI*(float)y/SCREEN_SIZE; g_vEye.x = g_fRadius*sin(g_fTheta)*sin(g_fPhi); g_vEye.y = g_fRadius*cos(g_fTheta); g_vEye.z = g_fRadius*sin(g_fTheta)*cos(g_fPhi); g_mxModelView = LookAt( g_vEye, g_vAt, g_vUp ); // Change ModelView Matrix g_pFloor->SetModelViewMatrix(g_mxModelView); g_pCube->SetModelViewMatrix(g_mxModelView); g_pSphere->SetModelViewMatrix(g_mxModelView); g_pLight->SetModelViewMatrix(g_mxModelView); }
void SetupRC() { glClearColor(0.1f, 0.2f, 0.3f, 0.0f); shader = gltLoadShaderPairWithAttributes("pass_thru_shader.vp", "pass_thru_shader.fp",2, GLT_ATTRIBUTE_VERTEX, "vVertex", GLT_ATTRIBUTE_COLOR, "vColor"); fprintf(stdout, "GLT_ATTRIBUTE_VERTEX : %d\nGLT_ATTRIBUTE_COLOR : %d \n",GLT_ATTRIBUTE_VERTEX, GLT_ATTRIBUTE_COLOR); MVPMatrixLocation = glGetUniformLocation(shader,"MVMatrix"); if(MVPMatrixLocation==-1) { fprintf(stderr,"uniform MVMatrix could not be found\n"); } M3DVector3f eye = {0.0f, -0.3f, 2.0f}; //Ustawienia kamery M3DVector3f at = {0.0f, 1.0f, -1.0f}; M3DVector3f up = {1.0f, 1.0f, 0.0f}; LookAt(frame,eye,at,up); }
void RenderScene(void) { // Clear the window with current clearing color glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); glUseProgram(shader); glEnable(GL_CULL_FACE); glFrontFace(GL_CW); CStopWatch timer; float angle = timer.GetElapsedSeconds()*3.14f; M3DVector3f mAt={0,0,0}; M3DVector3f mUp={0,0,1}; M3DVector3f mEye; mEye[0]=6.8f*cos(angle); mEye[1]=6.0f*sin(angle); mEye[2]=5.0f; LookAt(mFrame,mEye,mAt,mUp); mFrame.GetCameraMatrix(mCameraMatrix); matrixStack.LoadMatrix(mFrustrum.GetProjectionMatrix()); matrixStack.MultMatrix(mCameraMatrix); glUniformMatrix4fv(MVPMatrixLocation, 1, GL_FALSE, matrixStack.GetMatrix()); drawGrid(); matrixStack.Translate(1.0f,7.0f,0.0f); matrixStack.Rotate(30.0f,0.0,0.0,1.0); glUniformMatrix4fv(MVPMatrixLocation,1,GL_FALSE,matrixStack.GetMatrix()); drawPyramid(); matrixStack.PopMatrix(); matrixStack.Translate(-7.0f,0.0f,0.0f); matrixStack.Scale(2.0f, 2.0f, 2.0f); glUniformMatrix4fv(MVPMatrixLocation,1,GL_FALSE,matrixStack.GetMatrix()); drawPyramid(); matrixStack.PopMatrix(); // Perform the buffer swap to display back buffer glutSwapBuffers(); glutPostRedisplay(); }
void DefenderManager::UpdateSpawning() { if(m_WaveTimer < 0.0f) { auto angleStep = 90.0f / (GSETTINGS->m_DefenderManagerSettings->m_SpotsPerQuarter + 1); for(int i=0; i<4; ++i) { auto angleStart = 90.0f*i; auto angleEnd = 90.0f*(i+1); for (int j = 0; j < GSETTINGS->m_DefenderManagerSettings->m_CountPerWavePerQuarter; ++j) { auto spawnAngle = angleStart + angleStep*(m_RandomSpots.GetNext()+1); auto spawnDir = Vector3::Create(Math::Cos(spawnAngle*Math::DegToRadFactor), Math::Sin(spawnAngle*Math::DegToRadFactor), 0.0f); auto pos = spawnDir * GSETTINGS->m_DefenderManagerSettings->m_Radius; auto range = GSETTINGS->m_DefenderManagerSettings->m_AngleRange; auto angle = Random::GetFloat(-range, range); auto dir = (-spawnDir).Rotate(Vector3::Up, angle * Math::DegToRadFactor); // Spawn actor auto newActor = static_cast<Defender*>(m_PreloadedActor->Copy()); AddChild(newActor); newActor->SetPosition(pos); newActor->LookAt(dir); newActor->SwitchState(Defender::S_Hover); newActor->InitActor(GSETTINGS->m_DefenderSettings); m_lDefenders.push_back(newActor); } } m_WaveTimer = GSETTINGS->m_DefenderManagerSettings->m_WaveFrequency; } else m_WaveTimer -= g_fDeltaTime; if (m_SpawnTimer < 0.0f) { SwitchState(S_Defending); auto camera = EntityRenderer::Instance()->Get3DCamera(); if (camera == FOLLOWCAM) FOLLOWCAM->OnDefendersSpawned(); } else m_SpawnTimer -= g_fDeltaTime; }
void init( void ) { // Read model in woman.LoadMesh( "woman" ); // Load shaders and use the resulting shader program GLuint program = InitShader( "shaders/vshader.glsl", "shaders/fshader.glsl" ); glUseProgram( program ); GLuint loc; // Initialize shader lighting parameters point4 light_position( 0.0, 0.0, 1.0, 0.0 ); color4 light_ambient( 0.5, 0.5, 0.5, 1.0 ); color4 light_diffuse( 1.0, 1.0, 1.0, 1.0 ); // Calculate products color4 ambient_product = light_ambient; // Pass in light products glUniform4fv( glGetUniformLocation( program, "AmbientProduct" ), 1, ambient_product ); glUniform4fv( glGetUniformLocation( program, "DiffuseProduct" ), 1, light_diffuse ); glUniform4fv( glGetUniformLocation( program, "LightPosition" ), 1, light_position ); MaterialColorLoc = glGetUniformLocation( program, "MaterialColor" ); // Set our vertex projection matrix orthoProjection = Ortho( -20.0, 20.0, -20.0, 20.0, -20.0, 20.0 ); loc = glGetUniformLocation( program, "Projection" ); glUniformMatrix4fv( loc, 1, GL_TRUE, orthoProjection ); // Set up our camera vec4 eye( 0.0, 0.0, 1.0, 1.0 ); vec4 at( 0.0, 0.0, 0.0, 1.0 ); vec4 up( 0.0, 1.0, 0.0, 0.0 ); N = LookAt( eye, at, up ); glUniformMatrix4fv( glGetUniformLocation( program, "ModelView" ), 1, GL_TRUE, N ); glEnable( GL_DEPTH ); glClearColor( 1.0, 1.0, 1.0, 1.0 ); // white background }
NViewDataSet NRealisticCamerasRing(size_t nviews, size_t npoints, const NViewDatasetConfigurator config) { // 设置相机参数 NViewDataSet d; d.actual_camera_num_ = nviews; d.camera_matrix_.resize(nviews); d.rotation_matrix_.resize(nviews); d.translation_vector_.resize(nviews); d.camera_center_.resize(nviews); d.projected_points_.resize(nviews); d.projected_point_ids_.resize(nviews); d.point_3d_.resize(3, npoints); d.point_3d_.setRandom(); d.point_3d_ *= 0.6; Vecu all_point_ids(npoints); for (size_t j = 0; j < npoints; ++j) all_point_ids[j] = j; for (size_t i = 0; i < nviews; ++i) { Vec3 camera_center, t, jitter, lookdir; const double theta = i * 2 * M_PI / nviews; // 圆的方程式 camera_center << sin(theta), 0.0, cos(theta); // Y axis UP camera_center *= config._dist; d.camera_center_[i] = camera_center; jitter.setRandom(); jitter *= config._jitter_amount / camera_center.norm(); lookdir = -camera_center + jitter; d.camera_matrix_[i] << config._fx, 0, config._cx, 0, config._fy, config._cy, 0, 0, 1; d.rotation_matrix_[i] = LookAt(lookdir); // Y axis UP d.translation_vector_[i] = -d.rotation_matrix_[i] * camera_center; // [t]=[-RC] Cf HZ. d.projected_points_[i] = Project(d.P(i), d.point_3d_); d.projected_point_ids_[i] = all_point_ids; } return d; }
NViewDataSet NRealisticCamerasRing(size_t nviews, size_t npoints, const nViewDatasetConfigurator config) { //-- Setup a camera circle rig. NViewDataSet d; d._n = nviews; d._K.resize(nviews); d._R.resize(nviews); d._t.resize(nviews); d.C.resize(nviews); d._x.resize(nviews); d._x_ids.resize(nviews); d.X.resize(3, npoints); d.X.setRandom(); d.X *= 0.6; Vecu all_point_ids(npoints); for (size_t j = 0; j < npoints; ++j) all_point_ids[j] = j; for (size_t i = 0; i < nviews; ++i) { Vec3 camera_center, t, jitter, lookdir; const double theta = i * 2 * M_PI / nviews; //-- Circle equation camera_center << sin(theta), 0.0, cos(theta); // Y axis UP camera_center *= config._dist; d.C[i] = camera_center; jitter.setRandom(); jitter *= config._jitter_amount / camera_center.norm(); lookdir = -camera_center + jitter; d._K[i] << config._fx, 0, config._cx, 0, config._fy, config._cy, 0, 0, 1; d._R[i] = LookAt(lookdir); // Y axis UP d._t[i] = -d._R[i] * camera_center; // [t]=[-RC] Cf HZ. d._x[i] = Project(d.P(i), d.X); d._x_ids[i] = all_point_ids; } return d; }
FocusCamera::FocusCamera(Level * level_, GameObject * focus_, Vec3 position_) : Camera(level_){ focus = focus_; stateMachine.ChangeState(new ::Stare(this)); behaviour = LookState::Stare; position = position_; if (focus){ followDistance = Vec3::length(position - focus->position); LookAt(focus->position); MinCameraDistance = int(followDistance / 3.0f); MaxCameraDistance = int(followDistance * 3.0f); selfieStick = position - focus->position; } xInverted = 1; yInverted = 1; lookSpeed = 1.f; }
void Pointer::Update(float timeStep_) { GameObject::Update(timeStep_); position.y = ball->position.y; if (Input->isKeyDown(SDLK_RIGHT) || Input->isKeyDown(SDLK_d)) { RotateAround(ball->position, Vec3::BasisY(), 3 * timeStep_); } if (Input->isKeyDown(SDLK_LEFT) || Input->isKeyDown(SDLK_a)) { RotateAround(ball->position, Vec3::BasisY(), -3 * timeStep_); } if (Input->isKeyReleased(SDLK_k)) followCam = !followCam; if (Input->isMouseDown(SDL_BUTTON_RIGHT) && followCam) { //RotateAround(ball->position, Vec3::BasisY(), Input->deltaMouse().x * timeStep_); PointAtBall(); } if (((DIY_Level*)GAME->currentLevel)->levelState == DIY_Level_State::PLAYING && ((DIY_Level*)GAME->currentLevel)->playingState == DIY_Level_Playing_State::SHOOTING) { if (!isEnabled) { PointAtBall(); } isEnabled = true; } else isEnabled = false; renderer->isEnabled = isEnabled; //position += (level->currentCamera->right() * 0.5f); LookAt(ball->position); Rotate(Quat(M_PI / 2, Vec3::BasisY())); }
// Called when the state should become visible and start runnnig void GameState::Enter() { // Create Camera auto cameraNode = _scene->CreateChild("Camera"); auto camera = cameraNode->CreateComponent<Urho3D::Camera>(); auto soundListener = cameraNode->CreateComponent<Urho3D::SoundListener>(); cameraNode->SetPosition(Urho3D::Vector3(0.f, 10.f, -10.f)); cameraNode->LookAt(Urho3D::Vector3(0, 0, 0)); // Setup viewport Urho3D::SharedPtr<Urho3D::Viewport> viewport(new Urho3D::Viewport(context_, _scene, camera)); GetSubsystem<Urho3D::Renderer>()->SetViewport(0, viewport); GetSubsystem<Urho3D::Audio>()->SetListener(soundListener); // Set debug camera view _scene->GetComponent<Urho3D::DebugRenderer>()->SetView(camera); }
void display( void ) { glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); // Create new eye vector from sphericaleye vector eye.z = sphericaleye.x * cos(sphericaleye.y) * sin(sphericaleye.z); eye.x = sphericaleye.x * sin(sphericaleye.y) * sin(sphericaleye.z); eye.y = sphericaleye.x * cos(sphericaleye.z); std::cout << "Eye: (" << eye.x << "," << eye.y << "," << eye.z << ") \t"; std::cout << "Spherical Eye: (" << sphericaleye.x << "," << sphericaleye.y << "," << sphericaleye.z << ")" << std::endl; mat4 model_view = LookAt( eye, at, up ); glUniformMatrix4fv( ModelView, 1, GL_TRUE, model_view ); glDrawElements( GL_TRIANGLE_STRIP,sizeof(elems),GL_UNSIGNED_BYTE,NULL); glutSwapBuffers(); }
void RenderScene(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); glFrontFace(GL_CW); glUseProgram(shader); M3DVector3f at={0.0f, 0.0f, 0.0f}; M3DVector3f up={0.0f, 0.0f, 1.0f}; M3DVector3f eye; float angle = timer.GetElapsedSeconds()*3.14159f/8; eye[0]= 6.8f * cos(angle); eye[1]= 6.0f * sin(angle); eye[2]= 25.0f; LookAt(cameraFrame,eye,at,up); projection.LoadMatrix(viewFrustum.GetProjectionMatrix()); modelView.PushMatrix(); M3DMatrix44f mCamera; cameraFrame.GetCameraMatrix(mCamera); modelView.LoadMatrix(mCamera); modelView.PushMatrix(); glUniformMatrix4fv(MVMatrixLocation,1,GL_FALSE,geometryPipeline.GetModelViewProjectionMatrix()); szachownica(); modelView.Translate(0.0f, 0.0f, 0.0f); glUniformMatrix4fv(MVMatrixLocation,1,GL_FALSE,geometryPipeline.GetModelViewProjectionMatrix()); rysujPiramidke(); modelView.PopMatrix(); modelView.PushMatrix(); modelView.Translate(5.0f, 0.0f, 0.0f); glUniformMatrix4fv(MVMatrixLocation,1,GL_FALSE,geometryPipeline.GetModelViewProjectionMatrix()); rysujPiramidke(); modelView.PopMatrix(); modelView.PushMatrix(); modelView.Translate(-5.0f, 0.0f, 0.0f); modelView.Scale(2.0f, 2.0f, 2.0f); glUniformMatrix4fv(MVMatrixLocation,1,GL_FALSE,geometryPipeline.GetModelViewProjectionMatrix()); rysujPiramidke(); modelView.PopMatrix(); modelView.PopMatrix(); glutSwapBuffers(); glutPostRedisplay(); }
void Entity::rotate(glm::vec3 rotation) { this->_modelMatrix = glm::rotate(this->_modelMatrix, rotation.x, glm::vec3(1.0f, 0.0f, 0.0f)); this->_modelMatrix = glm::rotate(this->_modelMatrix, rotation.y, glm::vec3(0.0f, 1.0f, 0.0f)); this->_modelMatrix = glm::rotate(this->_modelMatrix, rotation.z, glm::vec3(0.0f, 0.0f, 1.0f)); //Quaternion to avoid Gimbol Lock glm::vec3 gPosition1(-1.5f, 0.0f, 0.0f); glm::vec3 gPosition2( 1.5f, 0.0f, 0.0f); glm::vec3 desiredDir = gPosition1-gPosition2; glm::vec3 desiredUp = glm::vec3(0.0f, 0.0f, 1.0f); // +Y // Compute the desired orientation glm::quat targetOrientation = glm::normalize(LookAt(desiredDir, desiredUp)); // And interpolate glm::quat gOrientation2 = RotateTowards(gOrientation2, targetOrientation, 1.0f*0.5f); }
void Camera::OrbitHorizontal(float angle)//correct { //get the angle between the up of the camera and the up of the world //pitch the camaera by that angle XMVECTOR offsetAngle = XMVector3AngleBetweenVectors(XMLoadFloat3(&XMFLOAT3(0.0, 1.0, 0.0)), XMLoadFloat3(&mUp) ); Pitch(XMVectorGetX(offsetAngle) + 0.001f); XMMATRIX matrixRot = XMMatrixRotationY(angle); //add rotation to the matrix XMStoreFloat3(&mPosition, XMVector3TransformNormal(XMLoadFloat3(&mPosition), matrixRot)); //XMVECTOR lookVector = XMLoadFloat3(&mPosition) - XMVectorZero(); //XMStoreFloat3(&mLook, lookVector); XMStoreFloat3(&mLook, XMVector3TransformNormal(XMLoadFloat3(&mLook), matrixRot)); //XMStoreFloat3(&mUp, XMVector3TransformNormal(XMLoadFloat3(&mUp), matrixRot)); //look at the center XMFLOAT3 zero(0.01, 0.01, 0.01); LookAt(mPosition, zero, XMFLOAT3(0.0, 1.0, 0.0)); }
void Camera::LookAt(const Point& target) { // No navel gazing: if (target == Pos()) return; Point tgt, tmp = target - Pos(); // Rotate into the view orientation: tgt.x = (tmp * vrt()); tgt.y = (tmp * vup()); tgt.z = (tmp * vpn()); if (tgt.z == 0) { Pitch(0.5); Yaw(0.5); LookAt(target); return; } double az = atan(tgt.x/tgt.z); double el = atan(tgt.y/tgt.z); // if target is behind, offset by 180 degrees: if (tgt.z < 0) az -= PI; Pitch(-el); Yaw(az); // roll to upright position: double deflection = vrt().y; while (fabs(deflection) > 0.001) { double theta = asin(deflection/vrt().length()); Roll(-theta); deflection = vrt().y; } }
bool CSDKBot::ThinkMelee() { CBasePlayer* pEnemy = m_PlayerSearchInfo.CloseEnemy(); if (pEnemy) { LookAt(pEnemy->Weapon_ShootPosition() + downToHead, m_pDifficult->m_flMeleeTurnLerp, m_pDifficult->m_flRandomAim); } if (m_flNextFireTime < gpGlobals->curtime && !IsAimingAtTeammate(m_PlayerSearchInfo.CloseEnemyDist())) { m_curCmd.buttons |= IN_ATTACK; } DoMelee(); if (gpGlobals->curtime > m_flNextStrafeTime) { CheckSwitchWeapon(); //check if we've fired and need to switch weapon float randomStrafe = bot_randfloat(); if (randomStrafe < 0.45f) { m_curCmd.buttons |= IN_LEFT; m_curCmd.buttons &= ~IN_RIGHT; } else if (randomStrafe < 0.9f) { m_curCmd.buttons &= ~IN_LEFT; m_curCmd.buttons |= IN_RIGHT; } else { m_curCmd.buttons &= ~IN_LEFT; m_curCmd.buttons &= ~IN_RIGHT; } float randomForward = bot_randfloat(); //don't move forward if we're too close if (m_PlayerSearchInfo.CloseEnemyDist() < m_flAdjustedMeleeRange) { m_curCmd.buttons &= ~IN_FORWARD; m_curCmd.buttons |= IN_BACK; } else if (randomForward < 0.5f){ m_curCmd.buttons |= IN_FORWARD; m_curCmd.buttons &= ~IN_BACK; } else { m_curCmd.buttons &= ~IN_FORWARD; m_curCmd.buttons &= ~IN_BACK; } m_flNextStrafeTime += RandomFloat(0.05f, 0.2f); } return true; }
void display( void ) { glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); point4 eye( radius*sin(theta)*cos(phi), radius*sin(theta)*sin(phi), radius*cos(theta), 1.0 ); point4 at( 0.0, 0.0, 0.0, 1.0 ); vec4 up( 0.0, 1.0, 0.0, 0.0 ); mat4 mv = LookAt( eye, at, up ); glUniformMatrix4fv( model_view, 1, GL_TRUE, mv ); mat4 p = Frustum( left, right, bottom, top, zNear, zFar ); glUniformMatrix4fv( projection, 1, GL_TRUE, p ); glDrawArrays( GL_TRIANGLES, 0, NumVertices ); glutSwapBuffers(); }
void Camera::ResetDefault(const Size2F& winSize, bool isOrtho /*= false*/) { mWinSize = winSize; mIsOrtho = isOrtho; float zEye = winSize.Height / 1.1566f;//this magic number will show the picture "pixel-to-pixel" on the screen mEyePosition = Point3F(winSize.Width / 2.f, winSize.Height / 2.f, zEye); mEyeTarget = Vector3F(winSize.Width / 2.f, winSize.Height / 2.f, 0.f); mCameraUp=Vector3F(0.f,1.f,0.f); if (mIsOrtho) { SetOrtho(mWinSize, 0.f, 2048.f); } else { mFovY = Math::ToRadian(60.f); mNearZ = 0.1f; mFarZ = zEye * 2; SetPerspectiveFov(mWinSize,mFovY, mNearZ, mFarZ); } LookAt(mEyePosition,mEyeTarget,mCameraUp); }
bool Curve::Intersect(const Ray &r, Float *tHit, SurfaceInteraction *isect, bool testAlphaTexture) const { ++nTests; // Transform _Ray_ to object space Vector3f oErr, dErr; Ray ray = (*WorldToObject)(r, &oErr, &dErr); // Compute object-space control points for curve segment, _cpObj_ Point3f cpObj[4]; cpObj[0] = BlossomBezier(common->cpObj, uMin, uMin, uMin); cpObj[1] = BlossomBezier(common->cpObj, uMin, uMin, uMax); cpObj[2] = BlossomBezier(common->cpObj, uMin, uMax, uMax); cpObj[3] = BlossomBezier(common->cpObj, uMax, uMax, uMax); // Project curve control points to plane perpendicular to ray Vector3f dx, dy; CoordinateSystem(ray.d, &dx, &dy); Transform objectToRay = LookAt(ray.o, ray.o + ray.d, dx); Point3f cp[4] = {objectToRay(cpObj[0]), objectToRay(cpObj[1]), objectToRay(cpObj[2]), objectToRay(cpObj[3])}; // Compute refinement depth for curve, _maxDepth_ Float L0 = 0; for (int i = 0; i < 2; ++i) L0 = std::max( L0, std::max( std::max(std::abs(cp[i].x - 2 * cp[i + 1].x + cp[i + 2].x), std::abs(cp[i].y - 2 * cp[i + 1].y + cp[i + 2].y)), std::abs(cp[i].z - 2 * cp[i + 1].z + cp[i + 2].z))); Float eps = std::max(common->width[0], common->width[1]) * .05f; // width / 20 #define LOG4(x) (std::log(x) * 0.7213475108f) Float fr0 = LOG4(1.41421356237f * 12.f * L0 / (8.f * eps)); #undef LOG4 int r0 = (int)std::round(fr0); int maxDepth = Clamp(r0, 0, 10); return recursiveIntersect(ray, tHit, isect, cp, Inverse(objectToRay), uMin, uMax, maxDepth); }
void display( SDL_Window* screen ){ glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); // Define view mat4 view = LookAt( eye, at, up ); // Draw elements of vao1 glUseProgram( programP1 ); glBindVertexArray( vao1 ); glUniformMatrix4fv( mMatrix, 1, GL_TRUE, modelP1 ); glUniformMatrix4fv( vMatrix, 1, GL_TRUE, view ); glDrawElements( GL_TRIANGLE_FAN,sizeof(elemsArray),GL_UNSIGNED_BYTE,0 ); glBindVertexArray( 0 ); glUseProgram( 0 ); // Draw elements of vao2 glUseProgram( programP2 ); glBindVertexArray( vao2 ); glUniformMatrix4fv( mMatrix, 1, GL_TRUE, modelP2 ); glUniformMatrix4fv( vMatrix, 1, GL_TRUE, view ); glDrawElements( GL_TRIANGLE_FAN,sizeof(elemsArray),GL_UNSIGNED_BYTE,0 ); glBindVertexArray( 0 ); glUseProgram( 0 ); // Draw elements of vao3 glUseProgram( programB ); glBindVertexArray( vao3 ); glUniformMatrix4fv( mMatrix, 1, GL_TRUE, modelB ); glUniformMatrix4fv( vMatrix, 1, GL_TRUE, view ); glDrawElements( GL_TRIANGLE_FAN,sizeof(elemsArray),GL_UNSIGNED_BYTE,0 ); glBindVertexArray( 0 ); glUseProgram( 0 ); // Release binds and swap buffers glBindVertexArray( 0 ); glUseProgram( 0 ); glFlush(); SDL_GL_SwapWindow(screen); }
void display(void) { /*clear all pixels*/ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //Take care of any mouse rotations or panning mv = LookAt(vec4(0, 0, 10+z_distance, 1.0), vec4(0, 0, 0, 1.0), vec4(0, 1, 0, 0.0)); mv = mv * RotateX(view_rotx) * RotateY(view_roty) * RotateZ(view_rotz); glUniformMatrix4fv(model_view, 1, GL_TRUE, mv); //You need to send some vertex attributes and uniform variables here glUniform4fv(ambient_light, 1, vec4(0.2, 0.2, 0.2, 1)); glUniform4fv(light_color, 1, vec4(1, 1, 1, 1)); glUniform4fv(light_position, 1, mv*vec4(50, 50, 50, 1)); // Light will follow the object (Because of mv) glVertexAttrib4fv(vAmbientDiffuseColor, vec4(0, 0.5, 0, 1)); glVertexAttrib4fv(vSpecularColor, vec4(1, 1, 1, 1)); glVertexAttrib1f(vSpecularExponent, 10); if(mode == 0){ glBindVertexArray( vao[0] ); glDrawArrays( GL_TRIANGLES, 0, spherevertcount ); // draw the sphere }else{ //WARNING: //Nvidia kludge: If you want the teapot to show up correctly, make sure that //vPosition is the first attribute listed in your vertex shader, and vNormal //is the 3rd attribute listed. Not sure what ATI cards will do with this glBindVertexArray(0); glutSolidTeapot(2); //not very bandwidth efficient } glFlush(); /*start processing buffered OpenGL routines*/ glutSwapBuffers(); }
void weapon_mini_rocket_proccess(float timePassed){ #define COLLISION geWorld_Collision(mini_rocketCurrentWorld,&(g->box.Min),&(g->box.Max),&(g->position),&newPos,GE_CONTENTS_SOLID_CLIP,GE_COLLIDE_ALL,0xffffffff, cb_move, 0, &lCol) int i; InfMiniRocket* g; geVec3d newPos; geVec3d to; geVec3d angles; GE_Collision lCol; for( i=0; i<NUMBER_OF_MINIROCKETS; i++){ g = & miniRockets[i]; if( g->active ){ geVec3d_AddScaled(&(g->position), &(g->velocity), timePassed, &(newPos) ); if( COLLISION ) { g->position = lCol.Impact; //geVec3d_Scale(&(g->velocity), -0.8f, &(g->velocity) ); weapon_mini_rocket_destroy(g); } else { g->position = newPos; } geVec3d_Add(&(g->position), &(g->velocity), &to); LookAt(g->position, to, &angles); angles.X += GE_PI/2; // update xform variable geXForm3d_SetIdentity(&(g->xform)); geXForm3d_RotateX(&(g->xform), angles.X); geXForm3d_RotateY(&(g->xform), angles.Y); geXForm3d_RotateZ(&(g->xform), angles.Z); g->xform.Translation = g->position; geActor_ClearPose(g->mini_rocket, &(g->xform) ); } } #undef COLLISION }
void CApp::OnRender() { glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); mat4 modelViewCamera = LookAt(eye, eye-n, v); glUseProgram(program); // Bind the Ka/Kd/Ks to the shader glUniform4fv( glGetUniformLocation(program, "AmbientProduct"),1, ambient_product); glUniform4fv( glGetUniformLocation(program, "DiffuseProduct"),1, diffuse_product); glUniform4fv( glGetUniformLocation(program, "SpecularProduct"),1,specular_product); glUniform1f( glGetUniformLocation(program, "mat_shininess"), material_shininess); glUniform4fv( glGetUniformLocation(program, "lightPosition"),1, light_position); // Retrieve transformation uniform variable locations ModelViewCam = glGetUniformLocation( program, "modelView" ); ModelViewObj = glGetUniformLocation(program, "ModelViewObj"); Projection = glGetUniformLocation( program, "projection" ); NormalTransformation = glGetUniformLocation( program, "normalTransformation" ); glUniformMatrix4fv(ModelViewCam, 1, GL_TRUE, modelViewCamera); mat4 modelViewObject = RotateZ(roll)*RotateY(yaw)*RotateX(pitch)*Scale(1.0, 2.2, 1.0); mat4 normalMatrix = modelViewCamera*RotateZ(roll)*RotateY(yaw)*RotateX(pitch)*Scale(1.0, 1.0/2.2, 1.0); glUniformMatrix4fv( ModelViewObj, 1, GL_TRUE, modelViewObject ); glUniformMatrix4fv(NormalTransformation , 1, GL_TRUE, normalMatrix); glBindVertexArray( vao ); glDrawArrays( GL_TRIANGLES, 0, NumVertices ); SDL_GL_SwapWindow(Main_window); glUseProgram(0); glBindVertexArray(0); }
void MtxLookAt2(matrix_t row, const float eyes_x, const float eyes_y, const float eyes_z, const float x, const float y, const float z) { /* 00 01 02 0 */ /* 0 11 12 0 */ /* 20 21 22 0 */ /* 0 0 0 1 */ /* --------------------------------------- */ /* 1 0 0 0| 00 01 02 0 */ /* 0 1 0 0| 0 11 12 0 */ /* 0 0 1 0| 20 21 22 0 */ /* X Y Z 1| X.00 X.01 X.02 1 */ /* Z.20 Y.11 Y.12 */ /* Z.21 Z.22 */ LookAt(row, x-eyes_x, y-eyes_y, z-eyes_z); row[3][0] = row[0][0] * -eyes_x + row[2][0] * -eyes_z; row[3][1] = row[0][1] * -eyes_x + row[1][1] * -eyes_y + row[2][1] * -eyes_z; row[3][2] = row[0][2] * -eyes_x + row[1][2] * -eyes_y + row[2][2] * -eyes_z; }
// Called when the state needs to load itself void GameState::Load() { auto cache = GetSubsystem<Urho3D::ResourceCache>(); // Setup Scene _scene = new Urho3D::Scene(context_); // Add Scene components _scene->CreateComponent<Urho3D::Octree>(); _scene->CreateComponent<Urho3D::DebugRenderer>(); _scene->CreateComponent<Urho3D::PhysicsWorld>(); // Add custom Scene components auto saveData = _scene->CreateComponent<SaveData>(); auto dungeon = _scene->CreateComponent<Dungeon>(); auto playerInterface = _scene->CreateComponent<PlayerInterface>(); // Create Character auto characterNode = _scene->CreateChild("Character"); characterNode->SetPosition(Urho3D::Vector3(0.f, 1.f, 0.f)); characterNode->SetScale(Urho3D::Vector3(.45f, .85f, .45f)); auto character = characterNode->CreateComponent<Character>(); auto characterModel = characterNode->CreateComponent<Urho3D::StaticModel>(); characterModel->SetModel(cache->GetResource<Urho3D::Model>("Models/Sphere.mdl")); characterModel->SetMaterial(cache->GetResource<Urho3D::Material>("Materials/Stone.xml")); // Attach spotlight node to Character auto lightNode = characterNode->CreateChild("Character"); lightNode->SetPosition(Urho3D::Vector3(0.f, 10.f, -10.f)); lightNode->LookAt(Urho3D::Vector3(0, 0, 0)); // Create directional light auto light = lightNode->CreateComponent<Urho3D::Light>(); light->SetLightType(Urho3D::LIGHT_DIRECTIONAL); }
//=============================================================================================================== //=============================================================================================================== void setupTransforms_MainColor(void) { LoadIdentity(view); LookAt(view, eyePosition[0] - moveModelWithMiddleMouse[0], eyePosition[1] - moveModelWithMiddleMouse[1], eyePosition[2] - zoomModelWithMiddleMouse , 0.0 - moveModelWithMiddleMouse[0] , 0.0 - moveModelWithMiddleMouse[1] , 0.0 , 0.0, 1.0, 0.0); /* Translate(view, eyePosition[0] + moveModelWithMiddleMouse[0] eyePosition[1] + moveModelWithMiddleMouse[1], eyePosition[2] + zoomModelWithMiddleMouse); */ LoadIdentity(view_rotate); //-------------------- Rotate(view, 1.0, 0.0, 0.0, rotateModelWithMiddleMouse[0]); Rotate(view, 0.0, 1.0, 0.0, rotateModelWithMiddleMouse[1]); Translate(view_rotate, moveScenePivot[0], moveScenePivot[1], moveScenePivot[2]); //=========================================== LoadIdentity(invertView); InvertMatrix(invertView, view); //============================= }
void Camera::OrbitVertical(float angle) { //orbit back to the starting position //this orbit angle is not quite right. float orbitAngle = XMVectorGetX(XMVector3AngleBetweenVectors(XMLoadFloat3(&XMFLOAT3(0.0, 0.0, 1.0)), XMVector3Cross(GetRightXM(), XMVectorSet(0.0, 1.0, 0.0, 1.0)))); //special case for when you pass 180 if (mPosition.x < 0) orbitAngle = 180 + (90 - orbitAngle); OrbitHorizontal(orbitAngle); //get the angle between the right? of the camera and the right? of the world float check = XMVectorGetX(XMVector3AngleBetweenVectors(XMLoadFloat3(&XMFLOAT3(0.0, 0.0, 1.0)), XMLoadFloat3(&mLook))); if (check < MathHelper::Pi * 0.45 || ((mPosition.y > 0 && angle < 0 ) || ((mPosition.y < 0 && angle > 0))) ) { pitch += angle; //pitch the camaera by that angle XMVECTOR offsetAngle = XMVector3AngleBetweenVectors(XMLoadFloat3(&XMFLOAT3(1.0, 0.0, 0.0)), XMLoadFloat3(&mRight)); RotateY(XMVectorGetX(offsetAngle) + 0.001f); XMMATRIX matrixRot = XMMatrixRotationX(angle); XMStoreFloat3(&mPosition, XMVector3TransformNormal(XMLoadFloat3(&mPosition), matrixRot)); XMStoreFloat3(&mRight, XMVector3TransformNormal(XMLoadFloat3(&mRight), matrixRot)); } //move back OrbitHorizontal(-orbitAngle); //look at the center XMFLOAT3 zero(0.01, 0.01, 0.01); LookAt(mPosition, zero, XMFLOAT3(0.0, 1.0, 0.0)); }
TEST(RayTracerTest, TurbineMeshTest) { SceneLoader& loader = SceneLoader::GetInstance(); std::string path = "../assets/blade.ply"; std::string status = ""; Scene scene; std::cout << "loading" << std::endl; bool success = loader.LoadScene(path, scene, status); EXPECT_TRUE(success); EXPECT_EQ("OK", status); std::cout << "done loading" << std::endl; int image_width = 1024; int image_height = 1024; glm::vec3 eye_pos = glm::vec3(-274.564f, -282.243f, 950.0f); glm::vec3 at_pos = glm::vec3(-274.564f, -282.243f, 254.327f); glm::vec3 up_dir = glm::vec3(0.0f, 1.0f, 0.0f); std::cout << "set camera" << std::endl; glm::mat4x4 look_at = LookAt(eye_pos, at_pos, up_dir); Camera camera(image_width, image_height, Orthographic(0.0f, 1.0f), look_at); std::cout << "camera set" << std::endl; Light point_light; glm::vec3 point_light_color = glm::vec3(0.4f, 0.4f, 0.4f); point_light.ka = point_light_color; point_light.kd = point_light_color; point_light.ks = point_light_color; point_light.ray = Ray(glm::vec3(0.0, -400.0, 400.0f), glm::vec3(0.0f)); point_light.type = Light::kPoint; point_light.attenuation_coefficients = glm::vec3(0.25f, 0.003372407f, 0.000045492f); Light directional_light; glm::vec3 directional_light_color = glm::vec3(0.4f, 0.4f, 0.4f); directional_light.ka = directional_light_color; directional_light.kd = directional_light_color; directional_light.ks = directional_light_color; directional_light.ray = Ray(glm::vec3(0.0f), glm::vec3(0.0f, -1.0f, -1.0f)); directional_light.type = Light::kDirectional; scene.AddLight(point_light); scene.AddLight(directional_light); Trimesh* trimesh = static_cast<Trimesh*>(scene.scene_objects()[0]); OctreeType octree; std::cout << "Building octree" << std::endl; octree.Build(trimesh->faces()); //octree.set_trace(true); //octree.Print(std::cout); std::cout << "Octree built.\n"; std::cout << "bounds = " << octree.GetBounds() << " center = " << octree.GetBounds().GetCenter() << std::endl; trimesh->set_accelerator(&octree); Image image; image.Resize(image_width, image_height); RayTracer ray_tracer(&scene, &camera); ray_tracer.set_display_progress(!use_timing); ray_tracer.set_display_stats(!use_timing); ray_tracer.set_background_color(glm::vec3(0.05f, 0.05f, 0.05f)); timeval t_start, t_finish; if (use_timing) gettimeofday(&t_start, NULL); std::cout << "Rendering..." << std::endl; ray_tracer.Render(image); if (use_timing) { gettimeofday(&t_finish, NULL); float sec = t_finish.tv_sec - t_start.tv_sec + t_finish.tv_usec / 1000000.0f - t_start.tv_usec / 1000000.0f; std::cout << "Render time:" << sec << std::endl; } else std::cout << "Done." << std::endl; ImageStorage& storage = ImageStorage::GetInstance(); success = storage.WriteImage("blade_octree.jpg", image, status); EXPECT_TRUE(success); EXPECT_EQ("OK", status); }