//---------------------------------------------------------------------------- bool Castle::OnInitialize () { if (!WindowApplication3::OnInitialize()) { return false; } mCamera->SetFrustum(45.0f, GetAspectRatio(), 1.0f, 44495.0f); CreateScene(); mScene->Update(); // Center-and-fit the scene. The hard-coded center/position are based // on a priori knowledge of the data set. APoint worldCenter(1.3778250f,-0.70154405f,2205.9973f); mTrnNode->LocalTransform.SetTranslate(-worldCenter); APoint camPosition(527.394f, 86.8992f, -2136.00f); AVector camDVector(1.0f, 0.0f, 0.0f); AVector camUVector(0.0f, 0.0f, 1.0f); AVector camRVector = camDVector.Cross(camUVector); mCamera->SetFrame(camPosition, camDVector, camUVector, camRVector); mScene->Update(); mCuller.SetCamera(mCamera); mCuller.ComputeVisibleSet(mScene); InitializeCameraMotion(0.5f, 0.001f); InitializeObjectMotion(mScene); MoveForward(); return true; }
//---------------------------------------------------------------------------- bool ReflectionsAndShadows::OnInitialize () { if (!WindowApplication3::OnInitialize()) { return false; } // Set up the camera. mCamera->SetFrustum(60.0f, GetAspectRatio(), 1.0f, 1000.0f); APoint camPosition(180.0f, 0.0f, 23.0f); AVector camDVector(-1.0f, 0.0f, 0.0f); AVector camUVector(0.0f, 0.0f, 1.0f); AVector camRVector = camDVector.Cross(camUVector); mCamera->SetFrame(camPosition, camDVector, camUVector, camRVector); CreateScene (); // Initial update of objects. mScene->Update(); mBiped->Update(mUpdateTime); // Initial culling of scene, mSceneCuller.SetCamera(mCamera); mSceneCuller.ComputeVisibleSet(mScene); mBipedCuller.SetCamera(mCamera); mBipedCuller.ComputeVisibleSet(mBiped); InitializeCameraMotion(0.1f, 0.01f); InitializeObjectMotion(mScene); return true; }
//---------------------------------------------------------------------------- bool BlendedAnimations::OnInitialize () { if (!WindowApplication3::OnInitialize()) { return false; } CreateScene(); // Center-and-fit for camera viewing. mCamera->SetFrustum(60.0f, GetAspectRatio(), 1.0f, 1000.0f); APoint camPosition(-60.0f, -60.0f, 90.0f); AVector camDVector(1.0f, 1.0f, -1.0f); camDVector.Normalize(); AVector camUVector(0.5f, 0.5f, 1.0f); camUVector.Normalize(); AVector camRVector = camDVector.Cross(camUVector); mCamera->SetFrame(camPosition, camDVector, camUVector, camRVector); // Initial update of objects. mScene->Update(mAnimTime); InitializeCameraMotion(0.01f, 0.01f); InitializeObjectMotion(mScene); return true; }
//---------------------------------------------------------------------------- bool NonuniformScale::OnInitialize () { if (!WindowApplication3::OnInitialize()) { return false; } // Set up the camera. mCamera->SetFrustum(60.0f, GetAspectRatio(), 1.0f, 100.0f); float cs = 0.866025f, sn = 0.5f; APoint camPosition(0.0f, -4.0f, 2.0f); AVector camDVector(0.0f, cs, -sn); AVector camUVector(0.0f, sn, cs); AVector camRVector = camDVector.Cross(camUVector); mCamera->SetFrame(camPosition, camDVector, camUVector, camRVector); CreateScene(); // Initial update of objects. mScene->Update(); // Initial culling of scene. mCuller.SetCamera(mCamera); mCuller.ComputeVisibleSet(mScene); InitializeCameraMotion(0.01f, 0.001f); InitializeObjectMotion(mScene); return true; }
//---------------------------------------------------------------------------- bool RoughPlaneSolidBox::OnInitialize () { if (!WindowApplication3::OnInitialize()) { return false; } // Set up the camera. mCamera->SetFrustum(60.0f, GetAspectRatio(), 1.0f, 100.0f); float angle = 0.1f*Mathf::PI; float cs = Mathf::Cos(angle), sn = Mathf::Sin(angle); APoint camPosition(17.695415f, 0.0f, 6.4494629f); AVector camDVector(-cs, 0.0f, -sn); AVector camUVector(-sn, 0.0f, cs); AVector camRVector = camDVector.Cross(camUVector); mCamera->SetFrame(camPosition, camDVector, camUVector, camRVector); InitializeModule(); CreateScene(); // Initial update of objects. mScene->Update(); // Initial culling of scene. mCuller.SetCamera(mCamera); mCuller.ComputeVisibleSet(mScene); InitializeCameraMotion(0.001f, 0.001f); InitializeObjectMotion(mScene); return true; }
//---------------------------------------------------------------------------- bool ScreenPolygons::OnInitialize () { if (!WindowApplication3::OnInitialize()) { return false; } CreateScene(); // Set up the camera. mCamera->SetFrustum(60.0f, GetAspectRatio(), 1.0f, 1000.0f); APoint camPosition(80.0f, 0.0f, 23.0f); AVector camDVector(-1.0f, 0.0f, 0.0f); AVector camUVector(0.0f, 0.0f, 1.0f); AVector camRVector = camDVector.Cross(camUVector); mCamera->SetFrame(camPosition, camDVector, camUVector, camRVector); // Initial update of objects. mScene->Update(); mCuller.SetCamera(mCamera); mCuller.ComputeVisibleSet(mScene); InitializeCameraMotion(0.01f, 0.01f); InitializeObjectMotion(mScene); return true; }
//---------------------------------------------------------------------------- bool IntersectConvexPolyhedra::OnInitialize () { if (!WindowApplication3::OnInitialize()) { return false; } // Set up the camera. mCamera->SetFrustum(60.0f, GetAspectRatio(), 0.1f, 1000.0f); APoint camPosition(16.0f, 0.0f, 0.0f); AVector camDVector(-1.0f, 0.0f, 0.0f); AVector camUVector(0.0f, 0.0f, 1.0f); AVector camRVector = camDVector.Cross(camUVector); mCamera->SetFrame(camPosition, camDVector, camUVector, camRVector); CreateScene(); // Initial update of objects. mScene->Update(); // Initial culling of scene. mCuller.SetCamera(mCamera); mCuller.ComputeVisibleSet(mScene); InitializeCameraMotion(0.01f, 0.001f); InitializeObjectMotion(mScene); return true; }
//---------------------------------------------------------------------------- bool Terrains::OnInitialize () { if (!WindowApplication3::OnInitialize()) { return false; } // Set up the camera. Position the camera in the middle of page[0][0]. // Orient it to look diagonally across the terrain pages. mCamera->SetFrustum(60.0f, GetAspectRatio(), 1.0f, 1500.0f); APoint camPosition(64.0f, 64.0f, mHeightAboveTerrain); AVector camDVector(Mathf::INV_SQRT_2, Mathf::INV_SQRT_2, 0.0f); AVector camUVector(0.0f, 0.0f, 1.0f); AVector camRVector = camDVector.Cross(camUVector); mCamera->SetFrame(camPosition, camDVector, camUVector, camRVector); CreateScene(); // Initial update of objects. mScene->Update(); // Initial culling of scene. mCuller.SetCamera(mCamera); mCuller.ComputeVisibleSet(mScene); InitializeCameraMotion(1.0f, 0.01f); MoveForward(); return true; }
//---------------------------------------------------------------------------- bool BouncingSpheres::OnInitialize () { if (!WindowApplication3::OnInitialize()) { return false; } // Set up the camera. mCamera->SetFrustum(60.0f, GetAspectRatio(), 1.0f, 1000.0f); float angle = 0.02f*Mathf::PI; float cs = Mathf::Cos(angle), sn = Mathf::Sin(angle); APoint camPosition(27.5f, 8.0f, 8.9f); AVector camDVector(-cs, 0.0f, -sn); AVector camUVector(-sn, 0.0f, cs); AVector camRVector = camDVector.Cross(camUVector); mCamera->SetFrame(camPosition, camDVector, camUVector, camRVector); CreateScene(); // Initial update of objects. mScene->Update(); // Initialize balls with correct transformations. PhysicsTick(); // Initial culling of scene. mCuller.SetCamera(mCamera); mCuller.ComputeVisibleSet(mScene); return true; }
//---------------------------------------------------------------------------- bool ExtremalQuery::OnInitialize () { if (!WindowApplication3::OnInitialize()) { return false; } // Set up an orthogonal camera. This projection type is used to make it // clear that the displayed extreme points really are extreme! (The // perspective projection is deceptive.) mCamera = new0 Camera(false); mRenderer->SetCamera(mCamera); mCamera->SetFrustum(1.0f, 1000.0f, -1.5f, 1.5f, -2.0, 2.0f); APoint camPosition(4.0f, 0.0f, 0.0f); AVector camDVector(-1.0f, 0.0f, 0.0f); AVector camUVector(0.0f, 0.0f, 1.0f); AVector camRVector = camDVector.Cross(camUVector); mCamera->SetFrame(camPosition, camDVector, camUVector, camRVector); // Set up the scene. CreateScene(); // Initial update of objects. mScene->Update(); // Initial culling of scene. mCuller.SetCamera(mCamera); mCuller.ComputeVisibleSet(mScene); InitializeObjectMotion(mScene); return true; }
//---------------------------------------------------------------------------- bool ShadowMaps::OnInitialize () { if (!WindowApplication3::OnInitialize()) { return false; } // Set up the camera. mCamera->SetFrustum(60.0f, 1.0f, 0.1f, 100.0f); APoint camPosition(8.0f, 0.0f, 4.0f); AVector camDVector = APoint::ORIGIN - camPosition; // look at origin camDVector.Normalize(); AVector camUVector(camDVector[2], 0, -camDVector[0]); AVector camRVector(0.0f, 1.0f, 0.0f); mCamera->SetFrame(camPosition, camDVector, camUVector, camRVector); CreateScene(); // Initial update of objects. mScene->Update(); // Initial culling of scene. mCuller.SetCamera(mCamera); mCuller.ComputeVisibleSet(mScene); InitializeCameraMotion(0.01f, 0.001f); InitializeObjectMotion(mScene); return true; }
//---------------------------------------------------------------------------- bool BouncingBall::OnInitialize () { if (!WindowApplication3::OnInitialize()) { return false; } // Set up the camera. mCamera->SetFrustum(60.0f, GetAspectRatio(), 1.0f, 1000.0f); float angle = 0.1f*Mathf::PI; float cs = Mathf::Cos(angle); float sn = Mathf::Sin(angle); APoint camPosition(6.75f, 0.0f, 2.3f); AVector camDVector(-cs, 0.0f, -sn); AVector camUVector(-sn, 0.0f, cs); AVector camRVector = camDVector.Cross(camUVector); mCamera->SetFrame(camPosition, camDVector, camUVector, camRVector); CreateScene(); // Initial update of objects. mScene->Update(); mBallNode->Update(); // Initialize ball with correct transformations. PhysicsTick(); mSimTime = 0.0f; // All objects are visible. mSceneVisibleSet.Insert(mWall); mBallNodeVisibleSet.Insert(mBall->GetMesh()); InitializeCameraMotion(0.1f, 0.01f); return true; }
pair<Vec3, Vec3> RotateDesktopGesture::calculateCameraPosition() { // Right Direction Vec3 referenceDirection(-1.0f, 0.0f, 0.0f); Vec3 position, direction; Vec3 startPosition, endPosition; Vec3 startDirection, endDirection; int startWallIndex, endWallIndex; float ratio = 1.0f; Vec3 camDirection(cam->getDir().x, cam->getDir().z, 0.0f); Vec3 camPosition(cam->getEye().x, cam->getEye().z, 0.0f); float angle = getAngleBetween(camDirection, referenceDirection); if (camDirection.y > 0.0f) { // The camera is pointing in the upper quadrants if (angle < 90.0f) { //first quadrant ratio = angle / 90.0f; startWallIndex = 2; endWallIndex = 0; } else if (angle >= 90.0f && angle <= 180.0f) { //second quadrant ratio = (angle - 90.0f) / 90.0f; startWallIndex = 0; endWallIndex = 3; } } else { // The camera is pointing in the lower quadrants if (angle < 90.0f) { //fourth quadrant ratio = angle / 90.0f; startWallIndex = 2; endWallIndex = 1; } else if (angle >= 90.0f && angle <= 180.0f) { //third quadrant ratio = (angle - 90.0f) / 90.0f; startWallIndex = 1; endWallIndex = 3; } } // Find the two points in the world to interpolate between cam->lookAtWall(GLOBAL(Walls)[startWallIndex], startPosition, startDirection); cam->lookAtWall(GLOBAL(Walls)[endWallIndex], endPosition, endDirection); position = lerp(startPosition, endPosition, ratio); direction = lerp(startDirection, endDirection, ratio); return make_pair(position, direction); }
//---------------------------------------------------------------------------- void PerformanceAMDWindow::CreateCamera() { mCamera.SetFrustum(60.0f, GetAspectRatio(), 0.01f, 100.0f); Vector4<float> camPosition(0.0f, 0.0f, 4.0f, 1.0f); Vector4<float> camDVector(0.0f, 0.0f, -1.0f, 0.0f); Vector4<float> camUVector(0.0f, 1.0f, 0.0f, 0.0f); Vector4<float> camRVector = Cross(camDVector, camUVector); mCamera.SetFrame(camPosition, camDVector, camUVector, camRVector); EnableCameraMotion(0.005f, 0.002f, 2.0f, 2.0f); }
int RotateDesktopGesture::getWallCameraIsFacing() { Vec3 camDirection(cam->getDir().x, cam->getDir().z, 0.0f); Vec3 camPosition(cam->getEye().x, cam->getEye().z, 0.0f); Vec3 referenceDirection(-1.0f, 0.0f, 0.0f); float angle = getAngleBetween(camDirection, referenceDirection); Vec3 desktopDims = GetDesktopBox().GetExtents(); if (camDirection.y > 0.0f) { float frontLeftAngle = getAngleBetween(Vec3(desktopDims.x, desktopDims.z, 0.0f) - camPosition, referenceDirection); float frontRightAngle = getAngleBetween(Vec3(-desktopDims.x, desktopDims.z, 0.0f) - camPosition, referenceDirection); if (angle < frontRightAngle) { return 2; } else if (angle >= frontRightAngle && angle < frontLeftAngle) { return 0; } else if (angle >= frontLeftAngle) { return 3; } } else { float backRightAngle = getAngleBetween(Vec3(-desktopDims.x, -desktopDims.z, 0.0f) - camPosition, referenceDirection); float backLeftAngle = getAngleBetween(Vec3(desktopDims.x, -desktopDims.z, 0.0f) - camPosition, referenceDirection); if (angle < backRightAngle) { return 2; } else if (angle >= backRightAngle && angle < backLeftAngle) { return 1; } else if (angle >= backLeftAngle) { return 3; } } return -1; }
//---------------------------------------------------------------------------- bool FoucaultPendulum::OnInitialize () { if (!WindowApplication3::OnInitialize()) { return false; } // Initialize the physics module. mModule.AngularSpeed = 0.0001; mModule.Latitude = 0.25*Mathd::PI; mModule.GDivL = 1.0; double time = 0.0; double deltaTime = 0.001; double theta = 0.0; double thetaDot = 0.1; double phi = 0.75; double phiDot = 0.0; mModule.Initialize(time, deltaTime, theta, phi, thetaDot, phiDot); // Set up the camera. mCamera->SetFrustum(60.0f, GetAspectRatio(), 0.1f, 100.0f); float angle = 0.1f*Mathf::PI; float cs = Mathf::Cos(angle), sn = Mathf::Sin(angle); APoint camPosition(23.0f, 0.0f, 8.0f); AVector camDVector(-cs, 0.0f, -sn); AVector camUVector(-sn, 0.0f, cs); AVector camRVector = camDVector.Cross(camUVector); mCamera->SetFrame(camPosition, camDVector, camUVector, camRVector); CreateScene(); // Initial update of objects. mScene->Update(); PhysicsTick(); // Initial culling of scene. mCuller.SetCamera(mCamera); mCuller.ComputeVisibleSet(mScene); InitializeCameraMotion(0.01f, 0.001f); InitializeObjectMotion(mScene); return true; }
//---------------------------------------------------------------------------- PlaneMeshIntersectionWindow::PlaneMeshIntersectionWindow(Parameters& parameters) : Window(parameters), mTextColor(0.0f, 0.0f, 0.0f, 1.0f) { if (!SetEnvironment() || !CreateScene()) { parameters.created = false; return; } mCamera.SetFrustum(60.0f, GetAspectRatio(), 0.1f, 100.0f); Vector4<float> camPosition(0.0f, 0.0f, -2.5f, 1.0f); Vector4<float> camDVector(0.0f, 0.0f, 1.0f, 0.0f); Vector4<float> camUVector(0.0f, 1.0f, 0.0f, 0.0f); Vector4<float> camRVector = Cross(camDVector, camUVector); mCamera.SetFrame(camPosition, camDVector, camUVector, camRVector); mPSTarget.reset(new DrawTarget(2, DF_R32G32B32A32_FLOAT, mXSize, mYSize, true, false, DF_D24_UNORM_S8_UINT, false)); mPSColor = mPSTarget->GetRTTexture(0); mPSPlaneConstant = mPSTarget->GetRTTexture(1); mScreen.reset(new Texture2(DF_R32G32B32A32_FLOAT, mXSize, mYSize)); mScreen->SetUsage(Resource::SHADER_OUTPUT); mScreen->SetCopyType(Resource::COPY_STAGING_TO_CPU); mOverlay.reset(new OverlayEffect(mXSize, mYSize, mXSize, mYSize, SamplerState::MIN_P_MAG_P_MIP_P, SamplerState::CLAMP, SamplerState::CLAMP, true)); mOverlay->SetTexture(mScreen); mEngine->SetClearColor(Vector4<float>(1.0f, 1.0f, 1.0f, std::numeric_limits<float>::max())); mDrawIntersections->Set("color", mPSColor); mDrawIntersections->Set("planeConstant", mPSPlaneConstant); mDrawIntersections->Set("output", mScreen); EnableCameraMotion(0.01f, 0.001f, 2.0f, 2.0f); EnableObjectMotion(); }
//---------------------------------------------------------------------------- bool IntersectInfiniteCylinders::OnInitialize () { if (!WindowApplication3::OnInitialize()) { return false; } mCamera->SetFrustum(60.0f, GetAspectRatio(), 1.0f, 1000.0f); APoint camPosition(0.0f, -16.0f, 0.0f); AVector camDVector(0.0f, 1.0f, 0.0f); AVector camUVector(0.0f, 0.0f, 1.0f); AVector camRVector = camDVector.Cross(camUVector); mCamera->SetFrame(camPosition, camDVector, camUVector, camRVector); CreateScene(); mScene->Update(); InitializeCameraMotion(0.01f, 0.001f); InitializeObjectMotion(mScene); return true; }
//---------------------------------------------------------------------------- StructuredBuffersWindow::StructuredBuffersWindow(Parameters& parameters) : Window(parameters), mTextColor(0.0f, 0.0f, 0.0f, 1.0f) { if (!SetEnvironment() || !CreateScene()) { parameters.created = false; return; } mCamera.SetFrustum(60.0f, GetAspectRatio(), 0.1f, 100.0f); Vector4<float> camPosition(0.0f, 0.0f, 1.25f, 1.0f); Vector4<float> camDVector(0.0f, 0.0f, -1.0f, 0.0f); Vector4<float> camUVector(0.0f, 1.0f, 0.0f, 0.0f); Vector4<float> camRVector = Cross(camDVector, camUVector); mCamera.SetFrame(camPosition, camDVector, camUVector, camRVector); EnableCameraMotion(0.001f, 0.001f, 2.0f, 2.0f); EnableObjectMotion(); UpdateCW(); }
void DemoEntityManager::RenderFrame () { dTimeTrackerEvent(__FUNCTION__); // Make context current if (m_mainWindow->m_suspendVisualUpdates) { return; } dFloat timestep = dGetElapsedSeconds(); m_mainWindow->CalculateFPS(timestep); // update the the state of all bodies in the scene unsigned64 time0 = dGetTimeInMicrosenconds (); UpdatePhysics(timestep); unsigned64 time1 = dGetTimeInMicrosenconds (); m_mainThreadPhysicsTime = dFloat ((time1 - time0) / 1000.0f); // Get the interpolated location of each body in the scene m_cameraManager->InterpolateMatrices (this, CalculateInteplationParam()); // Our shading model--Goraud (smooth). glShadeModel (GL_SMOOTH); // Culling. glCullFace (GL_BACK); glFrontFace (GL_CCW); glEnable (GL_CULL_FACE); // glEnable(GL_DITHER); // z buffer test glEnable(GL_DEPTH_TEST); glDepthFunc (GL_LEQUAL); glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST); glHint(GL_POLYGON_SMOOTH_HINT, GL_FASTEST); glClearColor (0.5f, 0.5f, 0.5f, 0.0f ); //glClear( GL_COLOR_BUFFER_BIT ); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // set default lightning // glDisable(GL_BLEND); glEnable (GL_LIGHTING); // make sure the model view matrix is set to identity before setting world space ligh sources glMatrixMode(GL_MODELVIEW); glLoadIdentity(); dFloat cubeColor[] = { 1.0f, 1.0f, 1.0f, 1.0 }; glMaterialParam(GL_FRONT, GL_SPECULAR, cubeColor); glMaterialParam(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, cubeColor); glMaterialf(GL_FRONT, GL_SHININESS, 50.0); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); // one light form the Camera eye point GLfloat lightDiffuse0[] = { 0.5f, 0.5f, 0.5f, 0.0 }; GLfloat lightAmbient0[] = { 0.0f, 0.0f, 0.0f, 0.0 }; dVector camPosition (m_cameraManager->GetCamera()->m_matrix.m_posit); GLfloat lightPosition0[] = {camPosition.m_x, camPosition.m_y, camPosition.m_z}; glLightfv(GL_LIGHT0, GL_POSITION, lightPosition0); glLightfv(GL_LIGHT0, GL_AMBIENT, lightAmbient0); glLightfv(GL_LIGHT0, GL_DIFFUSE, lightDiffuse0); glLightfv(GL_LIGHT0, GL_SPECULAR, lightDiffuse0); glEnable(GL_LIGHT0); // set just one directional light GLfloat lightDiffuse1[] = { 0.7f, 0.7f, 0.7f, 0.0 }; GLfloat lightAmbient1[] = { 0.2f, 0.2f, 0.2f, 0.0 }; GLfloat lightPosition1[] = { -500.0f, 200.0f, 500.0f, 0.0 }; glLightfv(GL_LIGHT1, GL_POSITION, lightPosition1); glLightfv(GL_LIGHT1, GL_AMBIENT, lightAmbient1); glLightfv(GL_LIGHT1, GL_DIFFUSE, lightDiffuse1); glLightfv(GL_LIGHT1, GL_SPECULAR, lightDiffuse1); glEnable(GL_LIGHT1); // update Camera m_cameraManager->GetCamera()->SetViewMatrix(GetWidth(), GetHeight()); // render all entities if (m_mainWindow->m_hideVisualMeshes) { if (m_sky) { glPushMatrix(); m_sky->Render(timestep, this); glPopMatrix(); } } else { for (dListNode* node = dList<DemoEntity*>::GetFirst(); node; node = node->GetNext()) { DemoEntity* const entity = node->GetInfo(); glPushMatrix(); entity->Render(timestep, this); glPopMatrix(); } } if (m_tranparentHeap.GetCount()) { dMatrix modelView; glGetFloat (GL_MODELVIEW_MATRIX, &modelView[0][0]); while (m_tranparentHeap.GetCount()) { const TransparentMesh& transparentMesh = m_tranparentHeap[0]; glLoadIdentity(); glLoadMatrix(&transparentMesh.m_matrix[0][0]); transparentMesh.m_mesh->RenderTransparency(); m_tranparentHeap.Pop(); } glLoadMatrix(&modelView[0][0]); } m_cameraManager->RenderPickedTarget (); if (m_mainWindow->m_showContactPoints) { RenderContactPoints (GetNewton()); } if (m_mainWindow->m_showNormalForces) { RenderNormalForces (GetNewton()); } if (m_mainWindow->m_showNormalForces) { // if (1) { // see if there is a vehicle controller and void* const vehListerNode = NewtonWorldGetPreListener(GetNewton(), VEHICLE_PLUGIN_NAME); if (vehListerNode) { CustomVehicleControllerManager* const manager = (CustomVehicleControllerManager*)NewtonWorldGetListenerUserData(GetNewton(), vehListerNode); manager->Debug(); } void* const characterListerNode = NewtonWorldGetPreListener(GetNewton(), PLAYER_PLUGIN_NAME); if (characterListerNode) { CustomPlayerControllerManager* const manager = (CustomPlayerControllerManager*)NewtonWorldGetListenerUserData(GetNewton(), characterListerNode); manager->Debug(); } } if (m_mainWindow->m_showAABB) { RenderAABB (GetNewton()); } if (m_mainWindow->m_showCenterOfMass) { RenderCenterOfMass (GetNewton()); } if (m_mainWindow->m_showJoints) { RenderJointsDebugInfo (GetNewton(), 0.5f); } DEBUG_DRAW_MODE mode = m_solid; if (m_mainWindow->m_debugDisplayMode) { mode = (m_mainWindow->m_debugDisplayMode == 1) ? m_solid : m_lines; DebugRenderWorldCollision (GetNewton(), mode); } if (m_mainWindow->m_showStatistics) { dVector color (1.0f, 1.0f, 1.0f, 0.0f); Print (color, 10, 20, "render fps: %7.2f", m_mainWindow->m_fps); Print (color, 10, 42, "physics time on main thread: %7.2f ms", GetPhysicsTime() * 1000.0f); Print (color, 10, 64, "total memory: %d kbytes", NewtonGetMemoryUsed() / (1024)); Print (color, 10, 86, "number of bodies: %d", NewtonWorldGetBodyCount(GetNewton())); Print (color, 10, 108, "number of threads: %d", NewtonGetThreadsCount(GetNewton())); Print (color, 10, 130, "auto sleep: %s", m_mainWindow->m_autoSleepState ? "on" : "off"); } int lineNumber = 130 + 22; if (m_renderHood) { // set display for 2d render mode dFloat width = GetWidth(); dFloat height = GetHeight(); glColor3f(1.0, 1.0, 1.0); glPushMatrix(); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(0, width, 0, height); glPushMatrix(); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glDisable(GL_LIGHTING); glDisable(GL_DEPTH_TEST); glEnable(GL_TEXTURE_2D); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); // render 2d display m_renderHood (this, m_renderHoodContext, lineNumber); // restore display mode glMatrixMode(GL_PROJECTION); glPopMatrix(); glMatrixMode(GL_MODELVIEW); glPopMatrix(); } // draw everything and swap the display buffer glFlush(); // Swap SwapBuffers(); }
//---------------------------------------------------------------------------- bool NonlocalBlowup::OnInitialize () { if (!WindowApplication3::OnInitialize()) { return false; } #ifdef RUN_CONSOLE RunConsole(); return false; #endif mScene = new0 Node(); mScene->LocalTransform.SetRotate(HMatrix( 0.80475128f, 0.59107417f, -0.054833174f, 0.0f, -0.17529237f, 0.32487807f, 0.92936903f, 0.0f, 0.56714010f, -0.73829913f, 0.36505684f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f)); mWireState = new0 WireState(); mRenderer->SetOverrideWireState(mWireState); VertexFormat* vformat = VertexFormat::Create(2, VertexFormat::AU_POSITION, VertexFormat::AT_FLOAT3, 0, VertexFormat::AU_TEXCOORD, VertexFormat::AT_FLOAT2, 0); TriMesh* mesh = StandardMesh(vformat).Rectangle(256, 256, 16.0f, 16.0f); mScene->AttachChild(mesh); std::string gridName = Environment::GetPathR("Grid.wmtf"); Texture2D* gridTexture = Texture2D::LoadWMTF(gridName); gridTexture->GenerateMipmaps(); Texture1D* colorTexture = new0 Texture1D(Texture::TF_A8R8G8B8, 8, 1); unsigned char* color = (unsigned char*)colorTexture->GetData(0); color[ 0] = 128; color[ 1] = 128; color[ 2] = 128; color[ 3] = 255; color[ 4] = 255; color[ 5] = 0; color[ 6] = 128; color[ 7] = 255; color[ 8] = 255; color[ 9] = 0; color[10] = 0; color[11] = 255; color[12] = 0; color[13] = 255; color[14] = 0; color[15] = 255; color[16] = 0; color[17] = 255; color[18] = 255; color[19] = 255; color[20] = 0; color[21] = 128; color[22] = 255; color[23] = 255; color[24] = 0; color[25] = 0; color[26] = 255; color[27] = 255; color[28] = 255; color[29] = 255; color[30] = 255; color[31] = 255; float dt = 0.01f, dx = 1.0f, dy = 1.0f; // Uncomment only one of these at a time. NonconvexDomain0p50(dt, dx, dy); //SquareSymmetric0p01(dt, dx, dy); //SquareSymmetric0p50(dt, dx, dy); //SquareSymmetric0p99(dt, dx, dy); //SquareGaussX0p50(dt, dx, dy); //SquareGaussXY0p50(dt, dx, dy); //SquareGaussFour0p50(dt, dx, dy); DisplacementEffect* effect = new0 DisplacementEffect(); mesh->SetEffectInstance(effect->CreateInstance(mHeightTexture, gridTexture, colorTexture, mDomainTexture)); // Set up the camera so that it looks at the graph from slightly above // the xy-plane and at a skewed angle/direction of view. mCamera->SetFrustum(60.0f, GetAspectRatio(), 1.0f, 10000.0f); APoint camPosition(0.0f, 3.46f, 42.97f); AVector camDVector(0.0f, 0.0f, -1.0f); AVector camUVector(0.0f, 1.0f, 0.0f); AVector camRVector = camDVector.Cross(camUVector); mCamera->SetFrame(camPosition, camDVector, camUVector, camRVector); // Initial update of objects. mScene->Update(); // Initial culling of scene. mCuller.SetCamera(mCamera); mCuller.ComputeVisibleSet(mScene); InitializeCameraMotion(0.01f, 0.01f); InitializeObjectMotion(mScene); return true; }
//---------------------------------------------------------------------------- bool Fluids3D::OnInitialize () { if (!WindowApplication3::OnInitialize()) { return false; } // Create the pseudocoloring for display. Vector3f key[9] = { Vector3f( 0.0f/255.0f, 0.0f/255.0f, 0.0f/255.0f), // black Vector3f(128.0f/255.0f, 64.0f/255.0f, 64.0f/255.0f), // brown Vector3f(128.0f/255.0f, 0.0f/255.0f, 255.0f/255.0f), // violet Vector3f( 0.0f/255.0f, 0.0f/255.0f, 255.0f/255.0f), // blue Vector3f( 0.0f/255.0f, 255.0f/255.0f, 0.0f/255.0f), // green Vector3f(255.0f/255.0f, 255.0f/255.0f, 0.0f/255.0f), // yellow Vector3f(255.0f/255.0f, 128.0f/255.0f, 0.0f/255.0f), // orange Vector3f(255.0f/255.0f, 0.0f/255.0f, 0.0f/255.0f), // red Vector3f(255.0f/255.0f, 255.0f/255.0f, 255.0f/255.0f) // white }; for (int i = 0, j = 0; i < 8; ++i) { for (int k = 0; k < 32; ++k, ++j) { float t = k/32.0f; float omt = 1.0f - t; mColor[j][0] = omt*key[i][0] + t*key[i+1][0]; mColor[j][1] = omt*key[i][1] + t*key[i+1][1]; mColor[j][2] = omt*key[i][2] + t*key[i+1][2]; } } // Create the fluid solver. float x0 = -0.5f, y0 = -0.5f, z0 = -0.5f; float x1 = 0.5f, y1 = 0.5f, z1 = 0.5f; float dt = 0.001f; float denViscosity = 0.0001f, velViscosity = 0.0001f; int imax = 23, jmax = 23, kmax = 23; int numGaussSeidelIterations = 16; bool densityDirichlet = true; int numVortices = 8; mSmoke = new0 Smoke3D<float>(x0, y0, z0, x1, y1, z1, dt, denViscosity, velViscosity, imax, jmax, kmax, numGaussSeidelIterations, densityDirichlet, numVortices); mSmoke->Initialize(); // Set up the camera. mCamera->SetFrustum(60.0f, GetAspectRatio(), 0.1f, 100.0f); APoint camPosition(1.0f, 0.0f, 0.0f); AVector camDVector(-1.0f, 0.0f, 0.0f); AVector camUVector(0.0f, 0.0f, 1.0f); AVector camRVector = camDVector.Cross(camUVector); mCamera->SetFrame(camPosition, camDVector, camUVector, camRVector); // Create the scene. CreateScene(); mScene->Update(); #ifdef USE_PARTICLES mCube->GenerateParticles(mCamera); #endif UpdateVertexBuffer(); UpdateIndexBuffer(); // The scene is controlled by a virtual trackball. InitializeCameraMotion(0.01f, 0.01f); InitializeObjectMotion(mScene); return true; }