dVector CustomPlayerController::CalculateDesiredVelocity (dFloat forwardSpeed, dFloat lateralSpeed, dFloat verticalSpeed, const dVector& gravity, dFloat timestep) const { dMatrix matrix; NewtonBodyGetMatrix(m_body, &matrix[0][0]); dVector updir (matrix.RotateVector(m_upVector)); dVector frontDir (matrix.RotateVector(m_frontVector)); dVector rightDir (frontDir * updir); dVector veloc (0.0f, 0.0f, 0.0f, 0.0f); if ((verticalSpeed <= 0.0f) && (m_groundPlane % m_groundPlane) > 0.0f) { // plane is supported by a ground plane, apply the player input velocity if ((m_groundPlane % updir) >= m_maxSlope) { // player is in a legal slope, he is in full control of his movement dVector bodyVeloc; NewtonBodyGetVelocity(m_body, &bodyVeloc[0]); veloc = updir.Scale(bodyVeloc % updir) + gravity.Scale (timestep) + frontDir.Scale (forwardSpeed) + rightDir.Scale (lateralSpeed) + updir.Scale(verticalSpeed); veloc += (m_groundVelocity - updir.Scale (updir % m_groundVelocity)); dFloat speedLimitMag2 = forwardSpeed * forwardSpeed + lateralSpeed * lateralSpeed + verticalSpeed * verticalSpeed + m_groundVelocity % m_groundVelocity + 0.1f; dFloat speedMag2 = veloc % veloc; if (speedMag2 > speedLimitMag2) { veloc = veloc.Scale (dSqrt (speedLimitMag2 / speedMag2)); } dFloat normalVeloc = m_groundPlane % (veloc - m_groundVelocity); if (normalVeloc < 0.0f) { veloc -= m_groundPlane.Scale (normalVeloc); } } else { // player is in an illegal ramp, he slides down hill an loses control of his movement NewtonBodyGetVelocity(m_body, &veloc[0]); veloc += updir.Scale(verticalSpeed); veloc += gravity.Scale (timestep); dFloat normalVeloc = m_groundPlane % (veloc - m_groundVelocity); if (normalVeloc < 0.0f) { veloc -= m_groundPlane.Scale (normalVeloc); } } } else { // player is on free fall, only apply the gravity NewtonBodyGetVelocity(m_body, &veloc[0]); veloc += updir.Scale(verticalSpeed); veloc += gravity.Scale (timestep); } return veloc; }
glm::ivec3 LightClusters::updateClusters() { // Make sure resource are in good shape updateClusterResource(); // Clean up last info uint32_t numClusters = (uint32_t)_clusterGrid.size(); std::vector< std::vector< LightIndex > > clusterGridPoint(numClusters); std::vector< std::vector< LightIndex > > clusterGridSpot(numClusters); _clusterGrid.clear(); _clusterGrid.resize(numClusters, EMPTY_CLUSTER); uint32_t maxNumIndices = (uint32_t)_clusterContent.size(); _clusterContent.clear(); _clusterContent.resize(maxNumIndices, INVALID_LIGHT); auto theFrustumGrid(_frustumGridBuffer.get()); glm::ivec3 gridPosToOffset(1, theFrustumGrid.dims.x, theFrustumGrid.dims.x * theFrustumGrid.dims.y); uint32_t numClusterTouched = 0; uint32_t numLightsIn = _visibleLightIndices[0]; uint32_t numClusteredLights = 0; for (size_t lightNum = 1; lightNum < _visibleLightIndices.size(); ++lightNum) { auto lightId = _visibleLightIndices[lightNum]; auto light = _lightStage->getLight(lightId); if (!light) { continue; } auto worldOri = light->getPosition(); auto radius = light->getMaximumRadius(); bool isSpot = light->isSpot(); // Bring into frustum eye space auto eyeOri = theFrustumGrid.frustumGrid_worldToEye(glm::vec4(worldOri, 1.0f)); // Remove light that slipped through and is not in the z range float eyeZMax = eyeOri.z - radius; if (eyeZMax > -theFrustumGrid.rangeNear) { continue; } float eyeZMin = eyeOri.z + radius; bool beyondFar = false; if (eyeZMin < -theFrustumGrid.rangeFar) { beyondFar = true; } // Get z slices int zMin = theFrustumGrid.frustumGrid_eyeDepthToClusterLayer(eyeZMin); int zMax = theFrustumGrid.frustumGrid_eyeDepthToClusterLayer(eyeZMax); // That should never happen if (zMin == -2 && zMax == -2) { continue; } // Before Range NEar just apss, range neatr == true near for now if ((zMin == -1) && (zMax == -1)) { continue; } // CLamp the z range zMin = std::max(0, zMin); auto xLeftDistance = radius - distanceToPlane(eyeOri, _gridPlanes[0][0]); auto xRightDistance = radius + distanceToPlane(eyeOri, _gridPlanes[0].back()); auto yBottomDistance = radius - distanceToPlane(eyeOri, _gridPlanes[1][0]); auto yTopDistance = radius + distanceToPlane(eyeOri, _gridPlanes[1].back()); if ((xLeftDistance < 0.f) || (xRightDistance < 0.f) || (yBottomDistance < 0.f) || (yTopDistance < 0.f)) { continue; } // find 2D corners of the sphere in grid int xMin { 0 }; int xMax { theFrustumGrid.dims.x - 1 }; int yMin { 0 }; int yMax { theFrustumGrid.dims.y - 1 }; float radius2 = radius * radius; auto eyeOriH = glm::vec3(eyeOri); auto eyeOriV = glm::vec3(eyeOri); eyeOriH.y = 0.0f; eyeOriV.x = 0.0f; float eyeOriLen2H = glm::length2(eyeOriH); float eyeOriLen2V = glm::length2(eyeOriV); if ((eyeOriLen2H > radius2)) { float eyeOriLenH = sqrt(eyeOriLen2H); auto eyeOriDirH = glm::vec3(eyeOriH) / eyeOriLenH; float eyeToTangentCircleLenH = sqrt(eyeOriLen2H - radius2); float eyeToTangentCircleCosH = eyeToTangentCircleLenH / eyeOriLenH; float eyeToTangentCircleSinH = radius / eyeOriLenH; // rotate the eyeToOriDir (H & V) in both directions glm::vec3 leftDir(eyeOriDirH.x * eyeToTangentCircleCosH + eyeOriDirH.z * eyeToTangentCircleSinH, 0.0f, eyeOriDirH.x * -eyeToTangentCircleSinH + eyeOriDirH.z * eyeToTangentCircleCosH); glm::vec3 rightDir(eyeOriDirH.x * eyeToTangentCircleCosH - eyeOriDirH.z * eyeToTangentCircleSinH, 0.0f, eyeOriDirH.x * eyeToTangentCircleSinH + eyeOriDirH.z * eyeToTangentCircleCosH); auto lc = theFrustumGrid.frustumGrid_eyeToClusterDirH(leftDir); if (lc > xMax) { lc = xMin; } auto rc = theFrustumGrid.frustumGrid_eyeToClusterDirH(rightDir); if (rc < 0) { rc = xMax; } xMin = std::max(xMin, lc); xMax = std::min(rc, xMax); assert(xMin <= xMax); } if ((eyeOriLen2V > radius2)) { float eyeOriLenV = sqrt(eyeOriLen2V); auto eyeOriDirV = glm::vec3(eyeOriV) / eyeOriLenV; float eyeToTangentCircleLenV = sqrt(eyeOriLen2V - radius2); float eyeToTangentCircleCosV = eyeToTangentCircleLenV / eyeOriLenV; float eyeToTangentCircleSinV = radius / eyeOriLenV; // rotate the eyeToOriDir (H & V) in both directions glm::vec3 bottomDir(0.0f, eyeOriDirV.y * eyeToTangentCircleCosV + eyeOriDirV.z * eyeToTangentCircleSinV, eyeOriDirV.y * -eyeToTangentCircleSinV + eyeOriDirV.z * eyeToTangentCircleCosV); glm::vec3 topDir(0.0f, eyeOriDirV.y * eyeToTangentCircleCosV - eyeOriDirV.z * eyeToTangentCircleSinV, eyeOriDirV.y * eyeToTangentCircleSinV + eyeOriDirV.z * eyeToTangentCircleCosV); auto bc = theFrustumGrid.frustumGrid_eyeToClusterDirV(bottomDir); auto tc = theFrustumGrid.frustumGrid_eyeToClusterDirV(topDir); if (bc > yMax) { bc = yMin; } if (tc < 0) { tc = yMax; } yMin = std::max(yMin, bc); yMax =std::min(tc, yMax); assert(yMin <= yMax); } // now voxelize auto& clusterGrid = (isSpot ? clusterGridSpot : clusterGridPoint); if (beyondFar) { numClusterTouched += scanLightVolumeBoxSlice(theFrustumGrid, _gridPlanes, zMin, yMin, yMax, xMin, xMax, lightId, glm::vec4(glm::vec3(eyeOri), radius), clusterGrid); } else { numClusterTouched += scanLightVolumeSphere(theFrustumGrid, _gridPlanes, zMin, zMax, yMin, yMax, xMin, xMax, lightId, glm::vec4(glm::vec3(eyeOri), radius), clusterGrid); } numClusteredLights++; } // Lights have been gathered now reexpress in terms of 2 sequential buffers // Start filling from near to far and stops if it overflows bool checkBudget = false; if (numClusterTouched > maxNumIndices) { checkBudget = true; } uint16_t indexOffset = 0; for (int i = 0; i < (int) clusterGridPoint.size(); i++) { auto& clusterPoint = clusterGridPoint[i]; auto& clusterSpot = clusterGridSpot[i]; uint8_t numLightsPoint = ((uint8_t)clusterPoint.size()); uint8_t numLightsSpot = ((uint8_t)clusterSpot.size()); uint16_t numLights = numLightsPoint + numLightsSpot; uint16_t offset = indexOffset; // Check for overflow if (checkBudget) { if ((indexOffset + numLights) > (uint16_t) maxNumIndices) { break; } } // Encode the cluster grid: [ ContentOffset - 16bits, Num Point LIghts - 8bits, Num Spot Lights - 8bits] _clusterGrid[i] = (uint32_t)((0xFF000000 & (numLightsSpot << 24)) | (0x00FF0000 & (numLightsPoint << 16)) | (0x0000FFFF & offset)); if (numLightsPoint) { memcpy(_clusterContent.data() + indexOffset, clusterPoint.data(), numLightsPoint * sizeof(LightIndex)); indexOffset += numLightsPoint; } if (numLightsSpot) { memcpy(_clusterContent.data() + indexOffset, clusterSpot.data(), numLightsSpot * sizeof(LightIndex)); indexOffset += numLightsSpot; } } // update the buffers _clusterGridBuffer._buffer->setData(_clusterGridBuffer._size, (gpu::Byte*) _clusterGrid.data()); _clusterContentBuffer._buffer->setSubData(0, indexOffset * sizeof(LightIndex), (gpu::Byte*) _clusterContent.data()); return glm::ivec3(numLightsIn, numClusteredLights, numClusterTouched); }
OvrPanoMenu::OvrPanoMenu( App * app, Oculus360Photos * photos, OvrVRMenuMgr & menuMgr, BitmapFont const & font, OvrMetaData & metaData, float fadeOutTime, float radius ) : VRMenu( MENU_NAME ) , AppPtr( app ) , MenuMgr( menuMgr ) , Font( font ) , Photos( photos ) , MetaData( metaData ) , LoadingIconHandle( 0 ) , AttributionHandle( 0 ) , BrowserButtonHandle( 0 ) , SwipeLeftIndicatorHandle( 0 ) , SwipeRightIndicatorHandle( 0 ) , Fader( 1.0f ) , FadeOutTime( fadeOutTime ) , currentFadeRate( 0.0f ) , Radius( radius ) , ButtonCoolDown( 0.0f ) { currentFadeRate = 1.0f / FadeOutTime; // Init with empty root Init( menuMgr, font, 0.0f, VRMenuFlags_t() ); // Create Attribution info view Array< VRMenuObjectParms const * > parms; Array< VRMenuComponent* > comps; VRMenuId_t attributionPanelId( ID_CENTER_ROOT.Get() + 10 ); comps.PushBack( new OvrPanoMenuRootComponent( *this ) ); Quatf rot( DOWN, 0.0f ); Vector3f dir( -FWD ); Posef panelPose( rot, dir * Radius ); Vector3f panelScale( 1.0f ); //const Posef textPose( Quatf(), Vector3f( 0.0f, 0.0f, 0.0f ) ); const VRMenuFontParms fontParms( true, true, false, false, true, 0.525f, 0.45f, 1.0f ); VRMenuObjectParms attrParms( VRMENU_STATIC, comps, VRMenuSurfaceParms(), "Attribution Panel", panelPose, panelScale, Posef(), Vector3f( 1.0f ), fontParms, attributionPanelId, VRMenuObjectFlags_t( VRMENUOBJECT_DONT_HIT_TEXT ), VRMenuObjectInitFlags_t( VRMENUOBJECT_INIT_FORCE_POSITION ) ); parms.PushBack( &attrParms ); AddItems( MenuMgr, Font, parms, GetRootHandle(), false ); parms.Clear(); comps.Clear(); AttributionHandle = HandleForId( MenuMgr, attributionPanelId ); VRMenuObject * attributionObject = MenuMgr.ToObject( AttributionHandle ); OVR_ASSERT( attributionObject != NULL ); //Browser button float const ICON_HEIGHT = 80.0f * VRMenuObject::DEFAULT_TEXEL_SCALE; Array< VRMenuSurfaceParms > surfParms; Posef browserButtonPose( Quatf( ), UP * ICON_HEIGHT * 2.0f ); comps.PushBack( new OvrDefaultComponent( Vector3f( 0.0f, 0.0f, 0.05f ), 1.05f, 0.25f, 0.0f, Vector4f( 1.0f ), Vector4f( 1.0f ) ) ); comps.PushBack( new OvrButton_OnUp( this, ID_BROWSER_BUTTON ) ); comps.PushBack( new OvrSurfaceToggleComponent( ) ); surfParms.PushBack( VRMenuSurfaceParms ( "browser", "assets/nav_home_off.png", SURFACE_TEXTURE_DIFFUSE, NULL, SURFACE_TEXTURE_MAX, NULL, SURFACE_TEXTURE_MAX ) ); surfParms.PushBack( VRMenuSurfaceParms( "browser", "assets/nav_home_on.png", SURFACE_TEXTURE_DIFFUSE, NULL, SURFACE_TEXTURE_MAX, NULL, SURFACE_TEXTURE_MAX ) ); VRMenuObjectParms browserButtonParms( VRMENU_BUTTON, comps, surfParms, "", browserButtonPose, Vector3f( 1.0f ), Posef( ), Vector3f( 1.0f ), fontParms, ID_BROWSER_BUTTON, VRMenuObjectFlags_t( VRMENUOBJECT_DONT_HIT_TEXT ), VRMenuObjectInitFlags_t( VRMENUOBJECT_INIT_FORCE_POSITION ) ); parms.PushBack( &browserButtonParms ); AddItems( MenuMgr, Font, parms, AttributionHandle, false ); parms.Clear(); comps.Clear(); surfParms.Clear(); BrowserButtonHandle = attributionObject->ChildHandleForId( MenuMgr, ID_BROWSER_BUTTON ); VRMenuObject * browserButtonObject = MenuMgr.ToObject( BrowserButtonHandle ); OVR_ASSERT( browserButtonObject != NULL ); OVR_UNUSED( browserButtonObject ); //Favorites button Posef favoritesButtonPose( Quatf( ), DOWN * ICON_HEIGHT * 2.0f ); comps.PushBack( new OvrDefaultComponent( Vector3f( 0.0f, 0.0f, 0.05f ), 1.05f, 0.25f, 0.0f, Vector4f( 1.0f ), Vector4f( 1.0f ) ) ); comps.PushBack( new OvrButton_OnUp( this, ID_FAVORITES_BUTTON ) ); comps.PushBack( new OvrSurfaceToggleComponent() ); surfParms.PushBack( VRMenuSurfaceParms( "favorites_off", "assets/nav_star_off.png", SURFACE_TEXTURE_DIFFUSE, NULL, SURFACE_TEXTURE_MAX, NULL, SURFACE_TEXTURE_MAX ) ); surfParms.PushBack( VRMenuSurfaceParms( "favorites_on", "assets/nav_star_on.png", SURFACE_TEXTURE_DIFFUSE, NULL, SURFACE_TEXTURE_MAX, NULL, SURFACE_TEXTURE_MAX ) ); surfParms.PushBack( VRMenuSurfaceParms( "favorites_active_off", "assets/nav_star_active_off.png", SURFACE_TEXTURE_DIFFUSE, NULL, SURFACE_TEXTURE_MAX, NULL, SURFACE_TEXTURE_MAX ) ); surfParms.PushBack( VRMenuSurfaceParms( "favorites_active_on", "assets/nav_star_active_on.png", SURFACE_TEXTURE_DIFFUSE, NULL, SURFACE_TEXTURE_MAX, NULL, SURFACE_TEXTURE_MAX ) ); VRMenuObjectParms favoritesButtonParms( VRMENU_BUTTON, comps, surfParms, "", favoritesButtonPose, Vector3f( 1.0f ), Posef( ), Vector3f( 1.0f ), fontParms, ID_FAVORITES_BUTTON, VRMenuObjectFlags_t( VRMENUOBJECT_DONT_HIT_TEXT ), VRMenuObjectInitFlags_t( VRMENUOBJECT_INIT_FORCE_POSITION ) ); parms.PushBack( &favoritesButtonParms ); AddItems( MenuMgr, Font, parms, AttributionHandle, false ); parms.Clear(); comps.Clear(); FavoritesButtonHandle = attributionObject->ChildHandleForId( MenuMgr, ID_FAVORITES_BUTTON ); VRMenuObject * favoritesButtonObject = MenuMgr.ToObject( FavoritesButtonHandle ); OVR_ASSERT( favoritesButtonObject != NULL ); OVR_UNUSED( favoritesButtonObject ); // Swipe icons const int numFrames = 10; const int numTrails = 3; const int numChildren = 5; const float swipeFPS = 3.0f; const float factor = 1.0f / 8.0f; // Right container VRMenuId_t swipeRightId( ID_CENTER_ROOT.Get() + 401 ); Quatf rotRight( DOWN, ( Mathf::TwoPi * factor ) ); Vector3f rightDir( -FWD * rotRight ); comps.PushBack( new OvrTrailsAnimComponent( swipeFPS, true, numFrames, numTrails, numTrails ) ); VRMenuObjectParms swipeRightRoot( VRMENU_CONTAINER, comps, VRMenuSurfaceParms( ), "", Posef( rotRight, rightDir * Radius ), Vector3f( 1.0f ), Posef( ), Vector3f( 1.0f ), fontParms, swipeRightId, VRMenuObjectFlags_t( VRMENUOBJECT_DONT_HIT_ALL ), VRMenuObjectInitFlags_t( VRMENUOBJECT_INIT_FORCE_POSITION ) ); parms.PushBack( &swipeRightRoot ); AddItems( MenuMgr, Font, parms, AttributionHandle, false ); parms.Clear(); comps.Clear(); SwipeRightIndicatorHandle = attributionObject->ChildHandleForId( MenuMgr, swipeRightId ); VRMenuObject * swipeRightRootObject = MenuMgr.ToObject( SwipeRightIndicatorHandle ); OVR_ASSERT( swipeRightRootObject != NULL ); // Left container VRMenuId_t swipeLeftId( ID_CENTER_ROOT.Get( ) + 402 ); Quatf rotLeft( DOWN, ( Mathf::TwoPi * -factor ) ); Vector3f leftDir( -FWD * rotLeft ); comps.PushBack( new OvrTrailsAnimComponent( swipeFPS, true, numFrames, numTrails, numTrails ) ); VRMenuObjectParms swipeLeftRoot( VRMENU_CONTAINER, comps, VRMenuSurfaceParms( ), "", Posef( rotLeft, leftDir * Radius ), Vector3f( 1.0f ), Posef( ), Vector3f( 1.0f ), fontParms, swipeLeftId, VRMenuObjectFlags_t( VRMENUOBJECT_DONT_HIT_ALL ), VRMenuObjectInitFlags_t( VRMENUOBJECT_INIT_FORCE_POSITION ) ); parms.PushBack( &swipeLeftRoot ); AddItems( MenuMgr, Font, parms, AttributionHandle, false ); parms.Clear(); comps.Clear(); SwipeLeftIndicatorHandle = attributionObject->ChildHandleForId( MenuMgr, swipeLeftId ); VRMenuObject * swipeLeftRootObject = MenuMgr.ToObject( SwipeLeftIndicatorHandle ); OVR_ASSERT( swipeLeftRootObject != NULL ); // Arrow frame children const char * swipeRightIcon = "assets/nav_arrow_right.png"; const char * swipeLeftIcon = "assets/nav_arrow_left.png"; VRMenuSurfaceParms rightIndicatorSurfaceParms( "swipeRightSurface", swipeRightIcon, SURFACE_TEXTURE_DIFFUSE, NULL, SURFACE_TEXTURE_MAX, NULL, SURFACE_TEXTURE_MAX ); VRMenuSurfaceParms leftIndicatorSurfaceParms( "swipeLeftSurface", swipeLeftIcon, SURFACE_TEXTURE_DIFFUSE, NULL, SURFACE_TEXTURE_MAX, NULL, SURFACE_TEXTURE_MAX ); const float surfaceWidth = 25 * VRMenuObject::DEFAULT_TEXEL_SCALE; for ( int i = 0; i < numChildren; ++i ) { //right frame const Vector3f rightPos = ( RIGHT * surfaceWidth * i ) - ( FWD * i * 0.1f ); VRMenuObjectParms swipeRightFrame( VRMENU_STATIC, Array< VRMenuComponent* >(), rightIndicatorSurfaceParms, "", Posef( Quatf( ), rightPos ), Vector3f( 1.0f ), Posef( ), Vector3f( 1.0f ), fontParms, VRMenuId_t( ), VRMenuObjectFlags_t(), VRMenuObjectInitFlags_t( VRMENUOBJECT_INIT_FORCE_POSITION ) ); parms.PushBack( &swipeRightFrame ); AddItems( MenuMgr, Font, parms, SwipeRightIndicatorHandle, false ); parms.Clear(); // left frame const Vector3f leftPos = ( (-RIGHT) * surfaceWidth * i ) - ( FWD * i * 0.1f ); VRMenuObjectParms swipeLeftFrame( VRMENU_STATIC, Array< VRMenuComponent* >(), leftIndicatorSurfaceParms, "", Posef( Quatf( ), leftPos ), Vector3f( 1.0f ), Posef( ), Vector3f( 1.0f ), fontParms, VRMenuId_t( ), VRMenuObjectFlags_t(), VRMenuObjectInitFlags_t( VRMENUOBJECT_INIT_FORCE_POSITION ) ); parms.PushBack( &swipeLeftFrame ); AddItems( MenuMgr, Font, parms, SwipeLeftIndicatorHandle, false ); parms.Clear(); } if ( OvrTrailsAnimComponent* animRightComp = swipeRightRootObject->GetComponentByName< OvrTrailsAnimComponent >( ) ) { animRightComp->Play( ); } if ( OvrTrailsAnimComponent* animLeftComp = swipeLeftRootObject->GetComponentByName< OvrTrailsAnimComponent >( ) ) { animLeftComp->Play( ); } }
void SeleneDev::CTestNode::Render() { Selene::CGraphics::SVertex pyramidVertices[3]; Selene::CGraphics::SVertex boxVertices[4]; Selene::CGraphics::SVertex squaresVertices[12]; Selene::Color pyramidColor(1.0f, 1.0f, 1.0f, 1.0f); Selene::Color boxColor(0.5f, 0.5f, 0.2f, 0.5f); Selene::Color squaresColor(1.0f, 1.0f, 1.0f, 0.5f); pyramidVertices[0].m_Color = pyramidColor; pyramidVertices[0].m_TexCoords = Selene::Vector2(0.0f, 0.0f); pyramidVertices[0].m_Coords = Selene::Vector3(0.0f, 1.0f, 0.0f); pyramidVertices[0].m_Coords += m_MoonPos; pyramidVertices[1].m_Color = pyramidColor; pyramidVertices[1].m_TexCoords = Selene::Vector2(0.0f, 1.0f); pyramidVertices[1].m_Coords = Selene::Vector3(-1.0f, -1.0f, 0.0f); pyramidVertices[1].m_Coords += m_MoonPos; pyramidVertices[2].m_Color = pyramidColor; pyramidVertices[2].m_TexCoords = Selene::Vector2(1.0f, 1.0f); pyramidVertices[2].m_Coords = Selene::Vector3(1.0f, -1.0f, 0.0f); pyramidVertices[2].m_Coords += m_MoonPos; boxVertices[0].m_Color = boxColor; boxVertices[0].m_TexCoords = Selene::Vector2(0.0f, 0.0f); boxVertices[0].m_Coords = Selene::Vector3(-1.0f, 1.0f, 0.0f); boxVertices[0].m_Coords += m_BoxPos; boxVertices[1].m_Color = boxColor; boxVertices[1].m_TexCoords = Selene::Vector2(1.0f, 0.0f); boxVertices[1].m_Coords = Selene::Vector3(1.0f, 1.0f, 0.0f); boxVertices[1].m_Coords += m_BoxPos; boxVertices[2].m_Color = boxColor; boxVertices[2].m_TexCoords = Selene::Vector2(1.0f, 1.0f); boxVertices[2].m_Coords = Selene::Vector3(1.0f, -1.0f, 0.0f); boxVertices[2].m_Coords += m_BoxPos; boxVertices[3].m_Color = boxColor; boxVertices[3].m_TexCoords = Selene::Vector2(0.0f, 1.0f); boxVertices[3].m_Coords = Selene::Vector3(-1.0f, -1.0f, 0.0f); boxVertices[3].m_Coords += m_BoxPos; Selene::Vector3 bottomOffset(0.0f, -0.5f, 0.0f); squaresVertices[0].m_Color = squaresColor; squaresVertices[0].m_TexCoords = Selene::Vector2(0.0f, 0.0f); squaresVertices[0].m_Coords = Selene::Vector3(-5.0f, 0.0f, 5.0f); squaresVertices[0].m_Coords += m_SquaresPos + bottomOffset; squaresVertices[1].m_Color = squaresColor; squaresVertices[1].m_TexCoords = Selene::Vector2(1.0f, 0.0f); squaresVertices[1].m_Coords = Selene::Vector3(5.0f, 0.0f, 5.0f); squaresVertices[1].m_Coords += m_SquaresPos + bottomOffset; squaresVertices[2].m_Color = squaresColor; squaresVertices[2].m_TexCoords = Selene::Vector2(1.0f, 1.0f); squaresVertices[2].m_Coords = Selene::Vector3(5.0f, 0.0f, -5.0f); squaresVertices[2].m_Coords += m_SquaresPos + bottomOffset; squaresVertices[3].m_Color = squaresColor; squaresVertices[3].m_TexCoords = Selene::Vector2(0.0f, 1.0f); squaresVertices[3].m_Coords = Selene::Vector3(-5.0f, 0.0f, -5.0f); squaresVertices[3].m_Coords += m_SquaresPos + bottomOffset; squaresVertices[4].m_Color = squaresColor; squaresVertices[4].m_TexCoords = Selene::Vector2(0.0f, 0.0f); squaresVertices[4].m_Coords = Selene::Vector3(-5.0f, 0.0f, -5.0f); squaresVertices[4].m_Coords += m_SquaresPos; squaresVertices[5].m_Color = squaresColor; squaresVertices[5].m_TexCoords = Selene::Vector2(1.0f, 0.0f); squaresVertices[5].m_Coords = Selene::Vector3(5.0f, 0.0f, -5.0f); squaresVertices[5].m_Coords += m_SquaresPos; squaresVertices[6].m_Color = squaresColor; squaresVertices[6].m_TexCoords = Selene::Vector2(1.0f, 1.0f); squaresVertices[6].m_Coords = Selene::Vector3(5.0f, 10.0f, -5.0f); squaresVertices[6].m_Coords += m_SquaresPos; squaresVertices[7].m_Color = squaresColor; squaresVertices[7].m_TexCoords = Selene::Vector2(0.0f, 1.0f); squaresVertices[7].m_Coords = Selene::Vector3(-5.0f, 10.0f, -5.0f); squaresVertices[7].m_Coords += m_SquaresPos; squaresVertices[8].m_Color = squaresColor; squaresVertices[8].m_TexCoords = Selene::Vector2(0.0f, 0.0f); squaresVertices[8].m_Coords = Selene::Vector3(-5.0f, 0.0f, -5.0f); squaresVertices[8].m_Coords += m_SquaresPos; squaresVertices[9].m_Color = squaresColor; squaresVertices[9].m_TexCoords = Selene::Vector2(1.0f, 0.0f); squaresVertices[9].m_Coords = Selene::Vector3(-5.0f, 10.0f, -5.0f); squaresVertices[9].m_Coords += m_SquaresPos; squaresVertices[10].m_Color = squaresColor; squaresVertices[10].m_TexCoords = Selene::Vector2(1.0f, 1.0f); squaresVertices[10].m_Coords = Selene::Vector3(-5.0f, 10.0f, 5.0f); squaresVertices[10].m_Coords += m_SquaresPos; squaresVertices[11].m_Color = squaresColor; squaresVertices[11].m_TexCoords = Selene::Vector2(0.0f, 1.0f); squaresVertices[11].m_Coords = Selene::Vector3(-5.0f, 0.0f, 5.0f); squaresVertices[11].m_Coords += m_SquaresPos; // coordinate axes Selene::CGraphics::SVertex xLineVertices[3]; Selene::CGraphics::SVertex yLineVertices[2]; Selene::CGraphics::SVertex zLineVertices[2]; xLineVertices[0].m_Color = Selene::Color(1.0f, 0.0f, 0.0f, 1.0f); xLineVertices[0].m_Coords = Selene::Vector3(0.0f, 0.0f, 0.0f); xLineVertices[1].m_Color = Selene::Color(1.0f, 0.0f, 0.0f, 1.0f); xLineVertices[1].m_Coords = Selene::Vector3(5.0f, 0.0f, 0.0f); xLineVertices[2].m_Color = Selene::Color(1.0f, 0.0f, 0.0f, 1.0f); xLineVertices[2].m_Coords = Selene::Vector3(0.0f, 0.2f, 0.0f); yLineVertices[0].m_Color = Selene::Color(0.0f, 1.0f, 0.0f, 1.0f); yLineVertices[0].m_Coords = Selene::Vector3(0.0f, 0.0f, 0.0f); yLineVertices[1].m_Color = Selene::Color(0.0f, 1.0f, 0.0f, 1.0f); yLineVertices[1].m_Coords = Selene::Vector3(0.0f, 5.0f, 0.0f); zLineVertices[0].m_Color = Selene::Color(0.0f, 0.0f, 1.0f, 1.0f); zLineVertices[0].m_Coords = Selene::Vector3(0.0f, 0.0f, 0.0f); zLineVertices[1].m_Color = Selene::Color(0.0f, 0.0f, 1.0f, 1.0f); zLineVertices[1].m_Coords = Selene::Vector3(0.0f, 0.0f, 5.0f); //glLoadIdentity(); //glTranslatef(-1.5f, 0.0f, 0.0f); //glRotatef(m_TriangleAngle, 0.0f, 1.0f, 0.0f); m_pGraphics->EnableAlphaBlend(); m_pGraphics->SetAlphaBlendMode(Selene::CGraphics::SBM_SRC_ALPHA, Selene::CGraphics::DBM_ONE_MINUS_SRC_ALPHA); m_pGraphics->SetPrimitiveMode(Selene::CGraphics::PM_TRIANGLES); //m_pGraphics->SetPrimitiveMode(Selene::CGraphics::PM_LINES); m_pGraphics->SetTexture(m_pBoxTex); m_pGraphics->StartPrimitives(); m_pGraphics->Draw(pyramidVertices, 3); m_pGraphics->EndPrimitives(); //glLoadIdentity(); //glTranslatef(1.5f, 0.0f, 0.0f); //glRotatef(m_QuadAngle, 1.0f, 1.0f, 1.0f); m_pGraphics->SetPrimitiveMode(Selene::CGraphics::PM_QUADS); //m_pGraphics->SetPrimitiveMode(Selene::CGraphics::PM_LINES); m_pGraphics->SetTexture(m_pMoonTex); m_pGraphics->StartPrimitives(); m_pGraphics->Draw(boxVertices, 4); m_pGraphics->EndPrimitives(); m_pGraphics->SetPrimitiveMode(Selene::CGraphics::PM_QUADS); m_pGraphics->SetTexture(m_pSquaresTex); // hack glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, m_pFont->GetTextureID()); glBegin(Selene::CGraphics::PM_QUADS); // end hack //m_pGraphics->StartPrimitives(); m_pGraphics->Draw(squaresVertices, 12); m_pGraphics->EndPrimitives(); //m_pGraphics->SetPrimitiveMode(Selene::CGraphics::PM_TRIANGLES); //m_pGraphics->SetTexture(NULL); //m_pGraphics->StartPrimitives(); //m_pGraphics->Draw(xLineVertices, 3); //m_pGraphics->EndPrimitives(); // object rotation test Selene::Vector3 rightDir(1.0f, 0.0f, 0.0f); Selene::Vector3 upDir(0.0f, 1.0f, 0.0f); Selene::Vector3 forwardDir(0.0f, 0.0f, 1.0f); Selene::Vector3 lookAt(0.0f, 0.0f, 1.0f); Selene::Vector3 pos(0.0f, 0.0f, 0.0f); Selene::Vector3 up(0.0f, 1.0f, 0.0f); //* lookAt = Selene::Vector3(0.0f, 0.0, 0.0f); pos = Selene::Vector3(3.0f, 0.0, 4.0f); up = Selene::Vector3(0.0f, 1.0, 0.0f); //*/ forwardDir = lookAt - pos; forwardDir *= -1.0f; forwardDir.Normalize(); rightDir = up.Cross(forwardDir); rightDir.Normalize(); upDir = forwardDir.Cross(rightDir); upDir.Normalize(); rightDir.Normalize(); upDir.Normalize(); forwardDir.Normalize(); Selene::Matrix4 rotationMatrix; //rotationMatrix.m[0][0] = rightDir.m_X; //rotationMatrix.m[0][1] = rightDir.m_Y; //rotationMatrix.m[0][2] = rightDir.m_Z; //rotationMatrix.m[0][3] = 0.0f; //rotationMatrix.m[1][0] = upDir.m_X; //rotationMatrix.m[1][1] = upDir.m_Y; //rotationMatrix.m[1][2] = upDir.m_Z; //rotationMatrix.m[1][3] = 0.0f; //rotationMatrix.m[2][0] = forwardDir.m_X; //rotationMatrix.m[2][1] = forwardDir.m_Y; //rotationMatrix.m[2][2] = forwardDir.m_Z; //rotationMatrix.m[2][3] = 0.0f; //rotationMatrix.m[3][0] = 0.0f; //rotationMatrix.m[3][1] = 0.0f; //rotationMatrix.m[3][2] = 0.0f; //rotationMatrix.m[3][3] = 1.0f; rotationMatrix.m[0][0] = rightDir.m_X; rotationMatrix.m[0][1] = upDir.m_X; rotationMatrix.m[0][2] = forwardDir.m_X; rotationMatrix.m[0][3] = 0.0f; rotationMatrix.m[1][0] = rightDir.m_Y; rotationMatrix.m[1][1] = upDir.m_Y; rotationMatrix.m[1][2] = forwardDir.m_Y; rotationMatrix.m[1][3] = 0.0f; rotationMatrix.m[2][0] = rightDir.m_Z; rotationMatrix.m[2][1] = upDir.m_Z; rotationMatrix.m[2][2] = forwardDir.m_Z; rotationMatrix.m[2][3] = 0.0f; rotationMatrix.m[3][0] = 0.0f; rotationMatrix.m[3][1] = 0.0f; rotationMatrix.m[3][2] = 0.0f; rotationMatrix.m[3][3] = 1.0f; //rotationMatrix.Transpose(); //* xLineVertices[0].m_Coords *= rotationMatrix; xLineVertices[1].m_Coords *= rotationMatrix; yLineVertices[0].m_Coords *= rotationMatrix; yLineVertices[1].m_Coords *= rotationMatrix; zLineVertices[0].m_Coords *= rotationMatrix; zLineVertices[1].m_Coords *= rotationMatrix; /*/ Selene::CCamera* pCamera = m_pGraphics->GetActiveCamera(); float dist = 3.0f; xLineVertices[1].m_Coords = pCamera->GetRightDir() * dist; yLineVertices[1].m_Coords = pCamera->GetUpDir() * dist; zLineVertices[1].m_Coords = pCamera->GetLookDir() * dist; //*/ m_pGraphics->SetPrimitiveMode(Selene::CGraphics::PM_LINES); m_pGraphics->SetTexture(NULL); m_pGraphics->StartPrimitives(); m_pGraphics->Draw(xLineVertices, 2); m_pGraphics->Draw(yLineVertices, 2); m_pGraphics->Draw(zLineVertices, 2); m_pGraphics->EndPrimitives(); CSceneNode::Render(); }