void SoulLoaderSpirit::Render() { int innerAlpha = 255; int outerAlpha = 150; float spiritInnerSize = 1.0; float spiritOuterSize = 3.0; if( m_life < 10.0f ) { innerAlpha *= ( m_life / 10.0f ); outerAlpha *= ( m_life / 10.0f ); } Vector3 camUp(0,1,0); Vector3 camRight(1,0,0); float size = spiritInnerSize; glColor4ub(m_colour.r, m_colour.g, m_colour.b, innerAlpha ); glBegin( GL_QUADS ); glVertex3fv( (m_pos - camUp*size).GetData() ); glVertex3fv( (m_pos + camRight*size).GetData() ); glVertex3fv( (m_pos + camUp*size).GetData() ); glVertex3fv( (m_pos - camRight*size).GetData() ); glEnd(); size = spiritOuterSize; glColor4ub(m_colour.r, m_colour.g, m_colour.b, outerAlpha ); glBegin( GL_QUADS ); glVertex3fv( (m_pos - camUp*size).GetData() ); glVertex3fv( (m_pos + camRight*size).GetData() ); glVertex3fv( (m_pos + camUp*size).GetData() ); glVertex3fv( (m_pos - camRight*size).GetData() ); glEnd(); }
void AppMain() { Vector3 camFr(0.476459, -0.334238, 0.813186); Vector3 camUp(00.168968, 0.942489, 0.288382); Vector3 camRi = camUp ^ camFr; Vector3 camPos(-6, 10, -13); glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(50, (float)SCREEN_W / (float)SCREEN_H, // Aspect ratio 0.1, 1000); // Far plane while (!g_keys[KEY_ESC]) { glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); float camPosMag = camPos.Mag(); float moveSpeed = 0.01f * camPosMag; int velx, vely; get_mouse_mickeys(&velx, &vely); if (mouse_b & 2) { camFr.RotateAroundY((float)-velx / 100.0f); camUp.RotateAroundY((float)-velx / 100.0f); camRi = camUp ^ camFr; camFr.RotateAround(camRi, (float)vely / 100.0f); camUp.RotateAround(camRi, (float)vely / 100.0f); moveSpeed *= 3.0f; } if (key[KEY_W]) camPos += camFr * moveSpeed; if (key[KEY_S]) camPos -= camFr * moveSpeed; if (key[KEY_A]) camPos += camRi * moveSpeed; if (key[KEY_D]) camPos -= camRi * moveSpeed; if (key[KEY_Q]) camPos.y -= moveSpeed; if (key[KEY_E]) camPos.y += moveSpeed; glMatrixMode(GL_MODELVIEW); glLoadIdentity(); Vector3 lookAtPos = camPos + camFr; gluLookAt(camPos.x, camPos.y, camPos.z, lookAtPos.x, lookAtPos.y, lookAtPos.z, camUp.x, camUp.y, camUp.z); DrawGrid(camPos); // *** Do the maths we actually want to test MainUserLoop(); allegro_gl_flip(); } return 0; }
void OmniMapD3D::LoadAndPush_ProjectiveTexturing_Matricies() { D3DXMATRIX matView; D3DXVECTOR3 camPos( ProjectorPosition.pos.x, ProjectorPosition.pos.y, ProjectorPosition.pos.z ); // Camera position D3DXVECTOR3 camLookat( ProjectorPosition.lookAtpos.x, ProjectorPosition.lookAtpos.y, ProjectorPosition.lookAtpos.z ); // Look-at point D3DXVECTOR3 camUp( ProjectorPosition.headsUp.x, ProjectorPosition.headsUp.y, ProjectorPosition.headsUp.z ); // Up vector D3DXMatrixOrthoRH(&worldViewProjection, 2.0, 2.0, 0.0, 1.0f); D3DXMatrixLookAtRH( &worldView, &camPos, &camLookat, &camUp); }
// initilize scene // load obj files, set lights, camera void initScene(const std::string& textureName) { // for loading triangle mesh Matrix4x4 matrix; loadObj(objName.c_str(), vertices, normals, texcoord, mesh); matrix.m[2][3] = -9.f; matrix.m[1][3] = 0.f; Transform* tr = new Transform(matrix); trfList.push_back(tr); Mesh* newmesh = new Mesh(tr, &vertices, &normals, &mesh); objList.push_back(newmesh); // object initialize, for sphere /*Matrix4x4 mat; mat.m[2][3] = -16.f; Transform* tr2 = new Transform(mat); trfList.push_back(tr2); Sphere *sphere1 = new Sphere(tr2, 6.f); objList.push_back(sphere1);*/ // initialize image plane intensity = new float[WINX * WINY * 3]; memset(intensity, 0, WINX*WINY * 3 * sizeof(float)); // set up the camera Point camCenter, camLookAt(0.f, 0.f, -1.f); Vector camUp(0.f, 1.f, 0.f); float fovy = 60.f; camera = new PerspectiveCamera(camCenter, camLookAt, camUp, fovy); // set up the projectionLight Point e(-1.5f, 3.f, 15.f), gaze(-1.2f, 1.3f, 0.f); Vector up(0.f, 0.9f, 0.43589f); /* For sphere ray tracing test */ /*Point e(0.f, 0.f, 7.f), gaze(.0f, 0.f, -1.f); Vector up(0.f, 1.f, 0.f);*/ Transform light2world = LookAt(e, gaze, up); //string texname("grid.jpg"); float projFovy = 20.0; ProjectionLight *projector = new ProjectionLight(Inverse(light2world), textureName, projFovy); // set up the sampler sampler = new SimpleSampler(WINX, WINY); scene = new Scene(sampler, camera, &objList, projector, WINX, WINY); }
inline void flua_setCamera(float x, float y, float z, float camAngleX, float camAngleY) { glm::vec3 lookat(0, 0, 0); lookat.x = sinf(camAngleX) * cosf(camAngleY); lookat.y = sinf(camAngleY); lookat.z = -cosf(camAngleX) * cosf(camAngleY); glm::vec3 camPos(x, y, z); glm::vec3 camUp(0.0, 1.0, 0.0); #ifdef _WIN32 int nWidth = glutGet(GLUT_WINDOW_WIDTH); int nHeight = glutGet(GLUT_WINDOW_HEIGHT); if(flua_width != nWidth || flua_height != nHeight) { flua_onReshape(nWidth, nHeight); } #endif flua_viewMatrix = glm::lookAt(camPos, camPos + lookat, camUp); flua_viewAndProjectionMatrix = flua_projectionMatrix * flua_viewMatrix; }
void SeleneDev::CGame::Tick(float deltaTime) { Selene::CVirtualFileSystem* pVfs = GetSupervisor()->GetVFS(); Selene::CGraphics* pGraphics = GetSupervisor()->GetGraphics(); // test // m_ElapsedTime += deltaTime; float period = 8.0f; float phaseTime = fmodf(m_ElapsedTime, period); float phase = phaseTime / period; float radius = 10.0f; float pi = 3.141592f; Selene::Vector3 camPos(13.0f, 10.0, 4.0f); Selene::Vector3 lookAt(-1.5f, 1.0f, -5.0f); Selene::Vector3 camUp(0.0f, 1.0f, 0.0f); camPos.m_X = cosf(pi * 2.0f * phase) * radius + lookAt.m_X; camPos.m_Z = sinf(pi * 2.0f * phase) * radius + lookAt.m_Z; //pGraphics->GetActiveCamera()->Look(camPos, lookAt, camUp); m_pTestNode->Update(deltaTime); m_pFpsNode->Update(deltaTime); m_pHudNode->Update(deltaTime); }
static void _write(liqRibParticleData* pData, const structJob ¤tJob__) { CM_TRACE_FUNC("rm_writeParticleData.cpp::write("<<pData->getFullPathName().asChar()<<","<<currentJob__.name.asChar()<<",...)"); LIQDEBUGPRINTF( "-> writing particles\n"); #ifdef DEBUG RiArchiveRecord( RI_COMMENT, "Number of Valid Particles: %d", pData->m_numValidParticles ); RiArchiveRecord( RI_COMMENT, "Number of Discarded Particles: %d", pData->m_numParticles - pData->m_numValidParticles ); #endif MString notes("Make sure the particle is generated(e.g. sometimes particle is not generated, drag the time slider from frame0 to generate particles.)"); if(pData->m_numValidParticles <= 0 ){ RiArchiveRecord( RI_COMMENT, "Number of Valid Particles: %d. %s", pData->m_numValidParticles, notes.asChar() ); liquidMessage2(messageError, "%s. [%s]", notes.asChar(), pData->getFullPathName().asChar()); return; } unsigned numTokens( pData->tokenPointerArray.size() ); boost::scoped_array< RtToken > tokenArray( new RtToken[ numTokens ] ); boost::scoped_array< RtPointer > pointerArray( new RtPointer[ numTokens ] ); assignTokenArraysV( pData->tokenPointerArray, tokenArray.get(), pointerArray.get() ); switch( pData->particleType ) { case liqRibParticleData::MPTBlobbies: { // Build an array that can be given to RiBlobby std::vector< RtString > stringArray; for( int i(0); i < pData->m_stringArray.size(); i++ ) { stringArray.push_back( const_cast<char *>( pData->m_stringArray[i].c_str()) ); } RiBlobbyV( pData->m_numValidParticles, pData->m_codeArray.size(), const_cast< RtInt* >( &pData->m_codeArray[0] ), pData->m_floatArray.size(), const_cast< RtFloat* >( &pData->m_floatArray[0] ), stringArray.size(), const_cast< RtString* >( &stringArray[0] ), numTokens, tokenArray.get(), const_cast< RtPointer* >( pointerArray.get() ) ); pData->grain = 0; } break; case liqRibParticleData::MPTMultiPoint: case liqRibParticleData::MPTPoints: RiArchiveRecord( RI_COMMENT, "normal has to be reversed to show the MultiPoint/Points particles. // [10/9/2012 yaoyansi]" ); RiReverseOrientation(); #ifdef DELIGHT case liqRibParticleData::MPTSpheres: case liqRibParticleData::MPTSprites: #endif { RiPointsV( pData->m_numValidParticles * pData->m_multiCount, numTokens, tokenArray.get(), pointerArray.get() ); } break; case liqRibParticleData::MPTMultiStreak: case liqRibParticleData::MPTStreak: { unsigned nStreaks( pData->m_numValidParticles * pData->m_multiCount / 2 ); std::vector< RtInt > verts( nStreaks, 2 ); // Alternatively: // scoped_array< RtInt >verts( new RtInt[ nStreaks ] ); // fill( verts.get(), verts.get() + nStreaks, ( RtInt )2 ); // Both ways are way faster than the frickin for() lop that was here before -- Moritz RiCurvesV( "linear", nStreaks, &verts[ 0 ], "nonperiodic", numTokens, tokenArray.get(), pointerArray.get() ); } break; #ifndef DELIGHT case liqRibParticleData::MPTSpheres: { int posAttr = -1, radAttr = -1, colAttr = -1, opacAttr = -1; for ( unsigned i = 0; i < pData->tokenPointerArray.size(); i++ ) { const std::string tokenName( pData->tokenPointerArray[i].getTokenName() ); if ( "P" == tokenName ) { posAttr = i; } else if ( "radius" == tokenName ) { radAttr = i; } else if ( "Cs" == tokenName ) { colAttr = i; } else if ( "Os" == tokenName ) { opacAttr = i; } } for ( unsigned i = 0; i < pData->m_numValidParticles; i++) { RiAttributeBegin(); if ( colAttr != -1 ) { RiColor( &((RtFloat*)pointerArray[colAttr])[i*3] ); } if ( opacAttr != -1 ) { RiOpacity( &((RtFloat*)pointerArray[opacAttr])[i*3] ); } RiTransformBegin(); RiTranslate(((RtFloat*)pointerArray[posAttr])[i*3+0], ((RtFloat*)pointerArray[posAttr])[i*3+1], ((RtFloat*)pointerArray[posAttr])[i*3+2]); RtFloat radius = ((RtFloat*)pointerArray[radAttr])[i]; RiSphere(radius, -radius, radius, 360, RI_NULL); RiTransformEnd(); RiAttributeEnd(); } } break; case liqRibParticleData::MPTSprites: { int posAttr = -1, numAttr = -1, twistAttr = -1, scaleXAttr = -1, scaleYAttr = -1, colAttr = -1, opacAttr = -1; for ( unsigned i( 0 ); i < pData->tokenPointerArray.size(); i++ ) { const std::string tokenName( pData->tokenPointerArray[i].getTokenName() ); if ( "P" == tokenName ) { posAttr = i; } else if ( "spriteNum" == tokenName ) { numAttr = i; } else if ( "spriteTwist" == tokenName ) { twistAttr = i; } else if ( "spriteScaleX" == tokenName ) { scaleXAttr = i; } else if ( "spriteScaleY" == tokenName ) { scaleYAttr = i; } else if ( "Cs" == tokenName ) { colAttr = i; } else if ( "Os" == tokenName ) { opacAttr = i; } } MVector camUp( 0, 1, 0 ); MVector camRight( 1, 0, 0 ); MVector camEye( 0, 0, 1 ); camUp *= currentJob__.camera[0].mat.inverse(); camRight *= currentJob__.camera[0].mat.inverse(); camEye *= currentJob__.camera[0].mat.inverse(); for( unsigned ui( 0 ); ui < pData->m_numValidParticles; ui++ ) { MVector up( camUp ); MVector right( camRight ); float spriteRadiusX( 0.5 ); float spriteRadiusY( 0.5 ); RiAttributeBegin(); RiArchiveRecord( RI_COMMENT, "normal has to be reversed to show the Sprite particles. // [10/9/2012 yaoyansi]" ); RiReverseOrientation(); if ( -1 != colAttr ) RiColor( &( ( RtFloat* )pointerArray[ colAttr ] )[ ui * 3 ] ); if ( -1 != opacAttr ) RiOpacity( &( ( RtFloat* )pointerArray[ opacAttr ] )[ ui * 3 ] ); if ( -1 != twistAttr ) { float twist( -( ( RtFloat* )pointerArray[ twistAttr ] )[ ui ] * M_PI / 180 ); MQuaternion twistQ( twist, camEye ); right = camRight.rotateBy( twistQ ); up = camUp.rotateBy( twistQ ); } if ( scaleXAttr != -1 ) spriteRadiusX *= ( ( RtFloat* )pointerArray[ scaleXAttr ] )[ ui ]; if ( scaleYAttr != -1 ) spriteRadiusY *= ( ( RtFloat* )pointerArray[ scaleYAttr ] )[ ui ]; if ( posAttr != -1 ) { float *P( &( ( RtFloat* ) pointerArray[ posAttr ] )[ ui * 3 ] ); float spriteNumPP = 0; if ( numAttr != -1 ) spriteNumPP = ( ( RtFloat* )pointerArray[ numAttr ] )[ ui ]; float x0 = P[ 0 ] - spriteRadiusX * right[ 0 ] + spriteRadiusY * up[ 0 ]; float y0 = P[ 1 ] - spriteRadiusX * right[ 1 ] + spriteRadiusY * up[ 1 ]; float z0 = P[ 2 ] - spriteRadiusX * right[ 2 ] + spriteRadiusY * up[ 2 ]; float x1 = P[ 0 ] + spriteRadiusX * right[ 0 ] + spriteRadiusY * up[ 0 ]; float y1 = P[ 1 ] + spriteRadiusX * right[ 1 ] + spriteRadiusY * up[ 1 ]; float z1 = P[ 2 ] + spriteRadiusX * right[ 2 ] + spriteRadiusY * up[ 2 ]; float x2 = P[ 0 ] - spriteRadiusX * right[ 0 ] - spriteRadiusY * up[ 0 ]; float y2 = P[ 1 ] - spriteRadiusX * right[ 1 ] - spriteRadiusY * up[ 1 ]; float z2 = P[ 2 ] - spriteRadiusX * right[ 2 ] - spriteRadiusY * up[ 2 ]; float x3 = P[ 0 ] + spriteRadiusX * right[ 0 ] - spriteRadiusY * up[ 0 ]; float y3 = P[ 1 ] + spriteRadiusX * right[ 1 ] - spriteRadiusY * up[ 1 ]; float z3 = P[ 2 ] + spriteRadiusX * right[ 2 ] - spriteRadiusY * up[ 2 ]; float patch[ 12 ] = { x0, y0, z0, x1, y1, z1, x2, y2, z2, x3, y3, z3 }; // !!! if not GENERIC_RIBLIB use RiPatch( "bilinear", "P", &patch, "float spriteNum", &spriteNum, RI_NULL ); // RiPatch( "bilinear", "P", &patch, "float spriteNum", (RtFloat*)&spriteNumPP, RI_NULL ); // Patch "bilinear" "P" [0.446265 0.316269 -0.647637 1.27725 0.316269 -1.20393 0.615752 -0.636188 -0.39446 1.44674 -0.636188 -0.950756 ] "float spriteNum" [2 0 0 0 ] RiArchiveRecord( RI_VERBATIM, "Patch \"bilinear\" \"P\" [%f %f %f %f %f %f %f %f %f %f %f %f] \"float spriteNum\" [%f]", x0, y0, z0,x1, y1, z1, x2, y2, z2,x3, y3, z3, spriteNumPP ); } else { RiIdentity(); } RiAttributeEnd(); }//for } break; #endif // #ifndef DELIGHT case liqRibParticleData::MPTCloudy: { int posAttr = -1, radAttr = -1, colAttr = -1, opacAttr = -1, rotAttr = -1; for ( unsigned i = 0; i < pData->tokenPointerArray.size(); i++ ) { const std::string tokenName( pData->tokenPointerArray[i].getTokenName() ); if ( "P" == tokenName ) { posAttr = i; } else if ( "radius" == tokenName ) { radAttr = i; } else if ( "Cs" == tokenName ) { colAttr = i; } else if ( "Os" == tokenName ) { opacAttr = i; } else if ( "rotation" == tokenName ) { rotAttr = i; } } // Build an array that can be given to RiBlobby std::vector< RtString > stringArray; for( unsigned int i(0); i < pData->m_stringArray.size(); i++ ) { stringArray.push_back( const_cast<char *>( pData->m_stringArray[i].c_str()) ); } if(stringArray.size()==0)//added by yaoyansi, or it leads a crash on windows stringArray.push_back( "" ); boost::scoped_array< RtToken > ithTokenArray( new RtToken[ numTokens ] ); boost::scoped_array< RtPointer > ithPointerArray( new RtPointer[ numTokens ] ); for ( unsigned i = 0; i < pData->m_numValidParticles; i++) { assignIthTokenArraysV( pData->tokenPointerArray, ithTokenArray.get(), ithPointerArray.get(), i ); RiAttributeBegin(); if ( colAttr != -1 ) { RiColor( &((RtFloat*)pointerArray[colAttr])[i*3] ); } if ( opacAttr != -1 ) { RiOpacity( &((RtFloat*)pointerArray[opacAttr])[i*3] ); } RiTransformBegin(); RiTranslate(((RtFloat*)pointerArray[posAttr])[i*3+0], ((RtFloat*)pointerArray[posAttr])[i*3+1], ((RtFloat*)pointerArray[posAttr])[i*3+2]); if ( rotAttr != -1 ) { RiRotate( (( RtFloat *) pointerArray[rotAttr])[i*3] * 360.0, 1.0, 0.0, 0.0 ); RiRotate( (( RtFloat *) pointerArray[rotAttr])[i*3+1] * 360.0, 0.0, 1.0, 0.0 ); RiRotate( (( RtFloat *) pointerArray[rotAttr])[i*3+2] * 360.0, 0.0, 0.0, 1.0 ); } RtFloat radius = ((RtFloat*)pointerArray[radAttr])[i]; RiScale( radius, radius, radius ); //RiSphere(radius, -radius, radius, 360, RI_NULL); float dummy[] = { 0.0, 0.0, 0.0 }; // Worst case : three floats are needed RiBlobbyV( 1, pData->m_codeArray.size(), const_cast< RtInt* >( &pData->m_codeArray[0] ), pData->m_floatArray.size(), const_cast< RtFloat* >( &pData->m_floatArray[0] ), stringArray.size(), const_cast< RtString* >( &stringArray[0] ), numTokens, ithTokenArray.get(), ithPointerArray.get() ); // "vertex color incandescence", (RtPointer *)( dummy ), // "vertex color Cs", (RtPointer *)( dummy ), // "vertex float selfshadow", (RtPointer *)( dummy ), // RI_NULL ); RiTransformEnd(); RiAttributeEnd(); } break; } case liqRibParticleData::MPTNumeric: RiArchiveRecord( RI_COMMENT, "Numeric Particles are not supported" ); break; case liqRibParticleData::MPTTube: RiArchiveRecord( RI_COMMENT, "Tube Particles are not supported" ); break; break; } }