Matrix HaloRenderingThread::getOrientationMatrix(CrystalDescriptor::OrientationType orientation) { Matrix m; switch (orientation) { case CrystalDescriptor::OT_RANDOM: { /* First rotate the crystal around the Z axis:*/ Matrix zRot = createRotationMatrix(Vector3(0, 0, 1), randFloat(-3.14159265, 3.14159265)); /* Then rotate the Z axis into an uniformly distributed position*/ const Vector3 newAxis = getRandomVector(); Vector3 rotAxis = Vector3(0, 0, 1) % newAxis; Matrix axisRot = getIdentityMatrix(); if (rotAxis * rotAxis != 0) { rotAxis /= ~rotAxis; double rotAngle = acos(Vector3(0, 0, 1) * newAxis); axisRot = createRotationMatrix(rotAxis, rotAngle); } return zRot % axisRot; } break; case CrystalDescriptor::OT_PARRY: { /* For hexagonal prisms, one side face is horizontal. */ m = createRotationMatrix(Vector3(0, 1, 0), randFloat(0, 3.1415926536)); } break; case CrystalDescriptor::OT_COLUMN: { /* Main axis horizontal. */ Matrix n = createRotationMatrix(Vector3(0, 0, 1), randFloat(0, 3.1415926536)); Matrix o = createRotationMatrix(Vector3(0, 1, 0), randFloat(0, 3.1415926536)); m = n % o; } break; case CrystalDescriptor::OT_PLATE: { /* Main axis vertical. */ m = createRotationMatrix(Vector3(1, 0, 0), 3.14159265636 * 0.5) % createRotationMatrix(Vector3(0, 1, 0), randFloat(0, 3.1415926536)); } break; case CrystalDescriptor::OT_LOWITZ: { /* Rotation around a diagonal axis. The axis is horizontal.*/ m = createRotationMatrix(Vector3(1, 0, 0), 3.14159265636 * randFloat(-3.1415 * 0.5, 3.1415 * 0.5)) % createRotationMatrix(Vector3(0, 1, 0), randFloat(0, 3.1415926536)); } break; default: { sendNotifyString(wxT("Invalid orientation type."), 1); } } return m; }
int main(){ clock_t startTime; clock_t endTime; double elapsedTime; int maxValue = 10000000; int n=500000; cout << n << " elements per set with max value of " << maxValue << endl; vector<int>* vectorOfIntegers1 = getRandomVector(n, maxValue); vector<int>* vectorOfIntegers2 = getRandomVector(n, maxValue); set<int>* setOfIntegers1 = new set<int>; setOfIntegers1->insert(vectorOfIntegers1->begin(), vectorOfIntegers1->end() ); set<int>* setOfIntegers2 = new set<int>; setOfIntegers2->insert(vectorOfIntegers2->begin(), vectorOfIntegers2->end() ); //printData(vectorOfIntegers1, vectorOfIntegers2, //setOfIntegers1, setOfIntegers2); cout << endl; //unionExample(vectorOfIntegers1, vectorOfIntegers2, // setOfIntegers1, setOfIntegers2); cout << endl; intersectionExample(vectorOfIntegers1, vectorOfIntegers2, setOfIntegers1, setOfIntegers2); cout << endl; delete vectorOfIntegers1; delete setOfIntegers1; delete vectorOfIntegers2; delete setOfIntegers2; return 0; }
void test(){ for( int i = 0 ; i < 32 * 1024 ; ++ i ){ std::vector< int > v1 = getRandomVector(); std::vector< int > v2 = v1; int const pivot = rand() % v1.size(); rotate_cxx11( v1.begin(), v1.begin() + pivot, v1.end() ); std::rotate( v2.begin(), v2.begin() + pivot, v2.end() ); assert( v1 == v2 ); } }
void benchmarkHVE(Hve08 & hve, ofstream & outfile1, ofstream & outfile2, int vectorSize, int iterationCount, CharmListStr & decryptResults) { Benchmark benchT, benchD; CharmList pk, msk, CT, sk; CharmListInt S; GT M, newM; int n = vectorSize; CharmListInt xVector, yVector; getRandomVector(yVector, vectorSize); xVector = yVector; // int _vectorX[] = {1, 1, 0, 1}; // int _vectorY[] = {1, 1, 0, 1}; // xVector.init(_vectorX, 4); // generate randomly // yVector.init(_vectorY, 4); hve.setup(n, pk, msk); // cout << "pk: " << pk << endl; // cout << "msk: " << msk << endl; hve.keygen(pk, msk, yVector, sk); M = hve.group.random(GT_t); hve.encrypt(M, xVector, pk, CT); // cout << "ct :=\n" << CT << endl; double de_in_ms; stringstream s1, s2; for(int i = 0; i < iterationCount; i++) { benchD.start(); hve.decrypt(CT, sk, newM); benchD.stop(); de_in_ms = benchD.computeTimeInMilliseconds(); } cout << "Decrypt avg: " << benchD.getAverage() << " ms" << endl; s2 << vectorSize << " " << benchD.getAverage() << endl; outfile2 << s2.str(); decryptResults[0] = benchD.getRawResultString(); //cout << convert_str(M) << endl; //cout << convert_str(newM) << endl; if(M == newM) { cout << "Successful Decryption!" << endl; } else { cout << "FAILED Decryption." << endl; } }
/// /// \brief ParticleSystem::addParticle /// Create and add a particle to the system /// Positions are the Particle System position for now /// Velocities are random and following a cone shaped area /// StartTime is now /// void ParticleSystem::addParticle() { Particle* particle; if(m_TabParticle.size() >= m_nbMax){ m_TabParticle.pop_front(); } particle = new Particle(); particle->position = m_position; particle->velocity = getRandomVector(); particle->startTime = Clock::now(); m_TabParticle.push_back(particle); }
void getOrthoNormalBasisVector(Point3 i_up, Point3 &o_out_vector /*U*/, Point3& o_vector_right /*v*/) { Point3 randomVectorW; //bool foundRandomVector = false; while (true) { randomVectorW = getRandomVector(); if ( fabs(i_up.Dot(randomVectorW)) < RANDOMCOSINEANGLE) { o_out_vector = i_up.Cross(randomVectorW); o_vector_right = i_up.Cross(o_out_vector).GetNormalized(); o_out_vector.Normalize(); break; } } }
// Return time of tape recording for TapeDouble. double TapeDoubleTapePerformance() { std::vector<cl::TapeDouble> CppVec = vectorCast<cl::TapeDouble>(getRandomVector(dimension)); cl::TapeDouble CppResult = 0; cl::Independent(CppVec); boost::timer timer; for (cl::TapeDouble item : CppVec) { CppResult += std::sin(item * std::pow(CppResult, std::sqrt(std::pow(item, 2.0) * std::exp(std::cos(CppResult * std::tan(item)))))) + std::cos(std::log(std::exp(item * std::cos(CppResult)) + std::atan2(CppResult, item))); } cl::TapeFunction<double> f(CppVec, std::vector<cl::TapeDouble>({ CppResult })); return timer.elapsed(); }
// Return time of tape recording for AD<double>. double ADTapePerformance() { std::vector<CppAD::AD<double>> ADvec = vectorCast<CppAD::AD<double>>(getRandomVector(dimension)); CppAD::AD<double> ADResult = 0; CppAD::Independent(ADvec); boost::timer timer; for (CppAD::AD<double> item : ADvec) { ADResult += CppAD::sin(item * CppAD::pow(ADResult, CppAD::sqrt(CppAD::pow(item, 2.0) * CppAD::exp(CppAD::cos(ADResult * CppAD::tan(item)))))) + CppAD::cos(CppAD::log(CppAD::exp(item * CppAD::cos(ADResult)) + CppAD::atan2(ADResult, item))); } CppAD::ADFun<double> f(ADvec, std::vector<CppAD::AD<double>>({ ADResult })); return timer.elapsed(); }
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ #include <boost/test/unit_test.hpp> #include <boost/timer.hpp> #include <cl/tape/tape.hpp> #include <cl/tape/tests/testutil.hpp> static int dimension = (int)1e+7; static std::vector<double> leftVector = getRandomVector(dimension); static std::vector<double> rightVector = getRandomVector(dimension); // Returns dot product of two vectors. template <typename ResultType, typename LType, typename RType > inline ResultType dotProduct(std::vector<LType> const& lhs, std::vector<RType> const& rhs) { ResultType result = 0.0; typename std::vector<RType>::const_iterator begin = rhs.begin(); for (LType const& lh : lhs) { result += lh * *begin; ++begin; }
wxThread::ExitCode HaloRenderingThread::Entry() { wxCommandEvent evt(wxEVT_HALO_RENDERING_THREAD_NOTIFY, wxID_ANY); setupStruct.resultValid = false; setupStruct.imageBuffer = 0; setupStruct.rayPaths = new map<RayPathId, RayPathDescriptor>; if (setupStruct.crystals.size() == 0) { evt.SetString(wxT("No crystal population set up.")); evt.SetInt(1); setupStruct.notifee->AddPendingEvent(evt); return 0; } // Cast rays on crystals and refracted rays will form a pixel. int crystalTypeIndex = 0; CrystalDescriptor *currentDescriptor = &setupStruct.crystals[0]; const int N_CRYSTAL_TYPES = setupStruct.crystals.size(); int crystalsRemaining = currentDescriptor->populationWeight; Mesh currentMesh; size_t percentStep = setupStruct.crystalCount / 100; if (percentStep < 1) percentStep = 1; Vector3 sunPos(0, 0, -100000); rotate2d(sunPos.y, sunPos.z, setupStruct.solarAltitude * 3.14159265636 / 180.0); // Two prependicular vector Vector3 prepX = sunPos % Vector3(0, 1, 0); // FIXME: Sun on the zenith Vector3 prepY = sunPos % prepX; prepX /= ~prepX; prepY /= ~prepY; setupStruct.deleteBuffer = freeBuffer; setupStruct.deleteMap = freeMap; size_t size = setupStruct.imageSize; setupStruct.imageBuffer = new uint32_t[size * size * 6]; memset(setupStruct.imageBuffer, 0, size * size * 6 * sizeof(uint32_t)); uint32_t *leftPlane = setupStruct.imageBuffer; // 0th plane uint32_t *rightPlane = setupStruct.imageBuffer + size * size; // 1st plane uint32_t *topPlane = setupStruct.imageBuffer + 2 * size * size; // 2nd plane uint32_t *bottomPlane = setupStruct.imageBuffer + 3 * size * size; // 3rd plane uint32_t *backPlane = setupStruct.imageBuffer + 4 * size * size; // 4th plane uint32_t *frontPlane = setupStruct.imageBuffer + 5 * size * size; // 5th plane double halfImageSize = size * 0.5; int maxRays = (setupStruct.maxRayCastInfoSize * 1000000) / (sizeof(RayPathDescriptor) + sizeof(RayPathId)); if (maxRays == 0) maxRays = 1; int recordRayModulus = setupStruct.crystalCount / maxRays; if (!recordRayModulus) recordRayModulus = 1; struct RefractionColor { int rgb; double refractionIndex; }; RefractionColor colors[] = { { 0x0000FF, 1.3072 }, { 0x0080FF, 1.3094 }, { 0x00FFFF, 1.31 }, { 0x00FF80, 1.3107 }, { 0x00FF00, 1.3114 }, { 0x80FF00, 1.3125 }, { 0xFFFF00, 1.3136 }, { 0xFF8000, 1.3147 }, { 0xFF0000, 1.3158 }, { 0xFF0040, 1.3172 }, { 0xFF0080, 1.32 }, }; const int N_COLORS = sizeof(colors) / sizeof(colors[0]); // Cast many rays. for (size_t i = 0; i < setupStruct.crystalCount; i++) { if (setupStruct.cancelled) { // If the user shut the rendering down... delete[] setupStruct.imageBuffer; setupStruct.imageBuffer = 0; return 0; } if (!crystalsRemaining) { // We iterate through the crystals based on their population weights. crystalTypeIndex++; if (crystalTypeIndex >= N_CRYSTAL_TYPES) crystalTypeIndex = 0; currentDescriptor = &setupStruct.crystals[crystalTypeIndex]; crystalsRemaining = currentDescriptor->populationWeight; } // Get the raw mesh currentMesh = currentDescriptor->mesh; // Rotate it according to the orientation. Matrix orientationMatrix = getOrientationMatrix(currentDescriptor->orientation); // Apply wobbliness Vector3 wobbleRotationAxis(1, 0, 0); rotate2d(wobbleRotationAxis.x, wobbleRotationAxis.z, randFloat(0, 3.1415)); double wobblinessLimit = currentDescriptor->wobbliness * 3.1415 / 180.0; Matrix wobbleMatrix = createRotationMatrix( wobbleRotationAxis, randFloatNormal( 0, wobblinessLimit ) ); Matrix transformation = orientationMatrix % wobbleMatrix; transformMesh(currentMesh, transformation); // Crystal created, now cast a ray on it. Vector3 offset = prepX * randFloat(-1, 1) + prepY * randFloat(-1, 1); vector<RayPath> rayPaths; // Compute color here double colorCode = randFloat(0, N_COLORS - 1); RefractionColor prev = colors[(int)(floor(colorCode))]; RefractionColor next = colors[(int)(ceil(colorCode))]; double kColor = colorCode - floor(colorCode); RefractionColor currentColor; currentColor.rgb = prev.rgb; currentColor.refractionIndex = (1 - kColor) * prev.refractionIndex + kColor * next.refractionIndex; // Compute real poisition of the ray (Sun is a disk) Vector3 realSunPos = sunPos; Vector3 rayRotVector; double rayRotVectorLength; do { rayRotVector = realSunPos % getRandomVector(); rayRotVectorLength = ~rayRotVector; } while (rayRotVectorLength == 0); rayRotVector /= rayRotVectorLength; realSunPos = transformVector( createRotationMatrix( rayRotVector, randFloat( 0, setupStruct.solarDiskRadius * 3.1415926536 / 180.0 ) ), realSunPos ); computeRayPathInGlassMesh(currentMesh, currentColor.refractionIndex, realSunPos + offset, -realSunPos, 0.01, rayPaths); /* Project rays on the six planes. */ for (size_t j = 0; j < rayPaths.size(); j++) { RayPath ¤t = rayPaths[j]; size_t pathLength = current.size(); Vector3 exitDir = current[pathLength - 1].first - current[pathLength - 2].first; Vector3 projectionDir = -exitDir; double xPos, yPos; // select the plane to project on. uint32_t *plane; double xm = 1, ym = 1; int planeId; if ((fabs(projectionDir.x) > fabs(projectionDir.y)) && (fabs(projectionDir.x) > fabs(projectionDir.z))) { if (projectionDir.x < 0) { plane = leftPlane; planeId = 0; xm = -1; } else { plane = rightPlane; planeId = 1; } xPos = xm * projectionDir.z / fabs(projectionDir.x) * halfImageSize + halfImageSize; yPos = -ym * projectionDir.y / fabs(projectionDir.x) * halfImageSize + halfImageSize; } if ((fabs(projectionDir.y) > fabs(projectionDir.x)) && (fabs(projectionDir.y) > fabs(projectionDir.z))) { if (projectionDir.y < 0) { plane = bottomPlane; planeId = 3; ym = -1; } else { plane = topPlane; planeId = 2; } xPos = xm * projectionDir.x / fabs(projectionDir.y) * halfImageSize + halfImageSize; yPos = -ym * projectionDir.z / fabs(projectionDir.y) * halfImageSize + halfImageSize; } if ((fabs(projectionDir.z) > fabs(projectionDir.x)) && (fabs(projectionDir.z) > fabs(projectionDir.y))) { if (projectionDir.z < 0) { plane = frontPlane; planeId = 5; } else { plane = backPlane; planeId = 4; xm = -1; } xPos = xm * projectionDir.x / fabs(projectionDir.z) * halfImageSize + halfImageSize; yPos = -ym * projectionDir.y / fabs(projectionDir.z) * halfImageSize + halfImageSize; } // Calculate the new intensity of the pixel. xPos = clampInInt(xPos, 0, size - 1); yPos = clampInInt(yPos, 0, size - 1); int prevPixel = plane[(int)(yPos) * size + (int)(xPos)]; int nextPixel = 0; double intensity = current[pathLength - 2].second * 20; for (int j = 0; j < 3; j++) { int currentSaturation = (prevPixel >> (8 * j)) & 0xFF; int toAdd = (int)(((currentColor.rgb >> (8 * j)) & 0xFF) * intensity) >> 8; int nextSaturation; if (currentSaturation + toAdd > 255) nextSaturation = 255; else nextSaturation = currentSaturation + toAdd; nextPixel += (1 << (8 * j)) * nextSaturation * setupStruct.pixelIntensity; } plane[(int)(yPos) * size + (int)(xPos)] = nextPixel; // Record the ray if needed if (!(i % recordRayModulus)) { RayPathId pixelId(planeId, (int)xPos, (int)yPos); RayPathDescriptor theDescriptor( ¤tDescriptor->mesh, transformation, realSunPos + offset, -realSunPos, intensity ); map<RayPathId, RayPathDescriptor>::iterator it = setupStruct.rayPaths->find(pixelId); if (it == setupStruct.rayPaths->end()) { // If not found, insert it as new setupStruct.rayPaths->insert( make_pair( pixelId, theDescriptor ) ); } else if (it->second.intensity < intensity) { // If found, update it if the current ray is more intense it->second = theDescriptor; } } } if (i % percentStep == 0) { sendNotifyString(wxString::Format(wxT("Casting rays: %d%%"), i / percentStep)); } crystalsRemaining--; } evt.SetString(wxT("Completed.")); evt.SetInt(1); //< 1 means the operation is finished. setupStruct.resultValid = true; setupStruct.notifee->AddPendingEvent(evt); return 0; }
//----------------------------------------------------------------------------- // Name: Update() // Desc: //----------------------------------------------------------------------------- HRESULT CParticleSystem::Update( FLOAT fElpasedTime ) { Particle *pParticle; Particle **ppParticle; Plane *pPlane; Plane **ppPlane; D3DXVECTOR3 vOldPosition; m_fCurrentTime += fElpasedTime; // Update our particle system timer... ppParticle = &m_pActiveList; // Start at the head of the active list while( *ppParticle ) { pParticle = *ppParticle; // Set a pointer to the head // Calculate new position float fTimePassed = m_fCurrentTime - pParticle->m_fInitTime; if( fTimePassed >= m_fLifeCycle ) { // Time is up, put the particle back on the free list... *ppParticle = pParticle->m_pNext; pParticle->m_pNext = m_pFreeList; m_pFreeList = pParticle; --m_dwActiveCount; } else { // Update particle position and velocity // Update velocity with respect to Gravity (Constant Acceleration) pParticle->m_vCurVel += m_vGravity * fElpasedTime; // Update velocity with respect to Wind (Acceleration based on // difference of vectors) if( m_bAirResistence == true ) pParticle->m_vCurVel += (m_vWind - pParticle->m_vCurVel) * fElpasedTime; // Finally, update position with respect to velocity vOldPosition = pParticle->m_vCurPos; pParticle->m_vCurPos += pParticle->m_vCurVel * fElpasedTime - m_vDiff; //----------------------------------------------------------------- // BEGIN Checking the particle against each plane that was set up ppPlane = &m_pPlanes; // Set a pointer to the head while( *ppPlane ) { pPlane = *ppPlane; int result = classifyPoint( &pParticle->m_vCurPos, pPlane ); if( result == CP_BACK /*|| result == CP_ONPLANE */ ) { if( pPlane->m_nCollisionResult == CR_BOUNCE ) { pParticle->m_vCurPos = vOldPosition; //----------------------------------------------------------------- // // The new velocity vector of a particle that is bouncing off // a plane is computed as follows: // // Vn = (N.V) * N // Vt = V - Vn // Vp = Vt - Kr * Vn // // Where: // // . = Dot product operation // N = The normal of the plane from which we bounced // V = Velocity vector prior to bounce // Vn = Normal force // Kr = The coefficient of restitution ( Ex. 1 = Full Bounce, // 0 = Particle Sticks ) // Vp = New velocity vector after bounce // //----------------------------------------------------------------- float Kr = pPlane->m_fBounceFactor; D3DXVECTOR3 Vn = D3DXVec3Dot( &pPlane->m_vNormal, &pParticle->m_vCurVel ) * pPlane->m_vNormal; D3DXVECTOR3 Vt = pParticle->m_vCurVel - Vn; D3DXVECTOR3 Vp = Vt - Kr * Vn; pParticle->m_vCurVel = Vp; } else if( pPlane->m_nCollisionResult == CR_RECYCLE ) { pParticle->m_fInitTime -= m_fLifeCycle; } else if( pPlane->m_nCollisionResult == CR_STICK ) { pParticle->m_vCurPos = vOldPosition; pParticle->m_vCurVel = D3DXVECTOR3(0.0f,0.0f,0.0f); } } ppPlane = &pPlane->m_pNext; } // END Plane Checking //----------------------------------------------------------------- ppParticle = &pParticle->m_pNext; } } //------------------------------------------------------------------------- // Emit new particles in accordance to the flow rate... // // NOTE: The system operates with a finite number of particles. // New particles will be created until the max amount has // been reached, after that, only old particles that have // been recycled can be reintialized and used again. //------------------------------------------------------------------------- if( m_fCurrentTime - m_fLastUpdate > m_fReleaseInterval ) { // Reset update timing... m_fLastUpdate = m_fCurrentTime; // Emit new particles at specified flow rate... for( DWORD i = 0; i < m_dwNumToRelease; ++i ) { // Do we have any free particles to put back to work? if( m_pFreeList ) { // If so, hand over the first free one to be reused. pParticle = m_pFreeList; // Then make the next free particle in the list next to go! m_pFreeList = pParticle->m_pNext; } else { // There are no free particles to recycle... // We'll have to create a new one from scratch! if( m_dwActiveCount < m_dwMaxParticles ) { if( NULL == ( pParticle = new Particle ) ) return E_OUTOFMEMORY; } } if( m_dwActiveCount < m_dwMaxParticles ) { pParticle->m_pNext = m_pActiveList; // Make it the new head... m_pActiveList = pParticle; // Set the attributes for our new particle... pParticle->m_vCurVel = m_vVelocity; if( m_fVelocityVar != 0.0f ) { D3DXVECTOR3 vRandomVec = getRandomVector(); pParticle->m_vCurVel += vRandomVec * m_fVelocityVar; } pParticle->m_fInitTime = m_fCurrentTime; pParticle->m_vCurPos = m_vPosition; ++m_dwActiveCount; } } } return S_OK; }
void benchmarkHVE(Hve08 & hve, ofstream & outfile1, ofstream & outfile2, int vectorSize, int iterationCount, CharmListStr & transformResults, CharmListStr & decoutResults) { Benchmark benchT, benchD; CharmList pk, msk, CT, skBlinded, transformOutputList; CharmMetaListG1 skComplete; CharmListInt S; int receivers[] = {1, 3, 5, 12, 14}; S.init(receivers, 5); GT M, newM; ZR uf1; int n = vectorSize; CharmListInt xVector, yVector; getRandomVector(yVector, vectorSize); xVector = yVector; // int _vectorX[] = {1, 1, 0, 1}; // int _vectorY[] = {1, 1, 0, 1}; // xVector.init(_vectorX, 4); // generate randomly // yVector.init(_vectorY, 4); hve.setup(n, pk, msk); // cout << "pk: " << pk << endl; // cout << "msk: " << msk << endl; hve.keygen(pk, msk, yVector, uf1, skBlinded); M = hve.group.random(GT_t); hve.encrypt(M, xVector, pk, CT); // cout << "ct :=\n" << CT << endl; double tf_in_ms, de_in_ms; stringstream s1, s2; for(int i = 0; i < iterationCount; i++) { benchT.start(); hve.transform(CT, skBlinded, transformOutputList); benchT.stop(); tf_in_ms = benchT.computeTimeInMilliseconds(); benchD.start(); hve.decout(transformOutputList, uf1, newM); benchD.stop(); de_in_ms = benchD.computeTimeInMilliseconds(); } cout << "Transform avg: " << benchT.getAverage() << " ms" << endl; s1 << vectorSize << " " << benchT.getAverage() << endl; outfile1 << s1.str(); transformResults[0] = benchT.getRawResultString(); cout << "Decout avg: " << benchD.getAverage() << " ms" << endl; s2 << vectorSize << " " << benchD.getAverage() << endl; outfile2 << s2.str(); decoutResults[0] = benchD.getRawResultString(); cout << convert_str(M) << endl; cout << convert_str(newM) << endl; if(M == newM) { cout << "Successful Decryption!" << endl; } else { cout << "FAILED Decryption." << endl; } }
/** * CParticleEffect::initParticle * @date Modified June 01, 2006 */ void CParticleEffect::initParticle(CParticleManager::SParticle* pParticle, D3DXMATRIX* mOffset) { D3DXMATRIX mPosOffset, mOrientation = *mOffset; D3DXMatrixIdentity(&mPosOffset); mPosOffset._41 = mOffset->_41; mPosOffset._42 = mOffset->_42; mPosOffset._43 = mOffset->_43; mOrientation._41 = mOrientation._42 = mOrientation._43 = 0.0f; mOrientation._44 = 1.0f; float fMinVel, fMaxVel; D3DXVec3Normalize(&fMinVel, &m_vMinVelocity, &m_vMinVelocity); D3DXVec3Normalize(&fMaxVel, &m_vMaxVelocity, &m_vMaxVelocity); D3DXVec3TransformCoord(&m_vMinVelocityTrans, &m_vMinVelocity, &mOrientation); D3DXVec3TransformCoord(&m_vMaxVelocityTrans, &m_vMaxVelocity, &mOrientation); m_vMinVelocity *= fMinVel; m_vMaxVelocity *= fMaxVel; // Update attributes BYTE cR = GET_RED(pParticle->Color), cG = GET_GREEN(pParticle->Color), cB = GET_BLUE(pParticle->Color), cA = GET_ALPHA(pParticle->Color); for(size_t j = 0; j < m_vAttributes.size(); ++j) { float fScale = m_vAttributes[j]->getValue(0.0f); switch(m_vAttributes[j]->getType()) { case CParticleAttribute::ATR_COLORRED: cR = (BYTE)(fScale * 255.0f); break; case CParticleAttribute::ATR_COLORGREEN: cG = (BYTE)(fScale * 255.0f); break; case CParticleAttribute::ATR_COLORBLUE: cB = (BYTE)(fScale * 255.0f); break; case CParticleAttribute::ATR_COLORALPHA: cA = (BYTE)(fScale * 255.0f); break; case CParticleAttribute::ATR_SIZE: pParticle->Size = fScale; break; case CParticleAttribute::ATR_ROTATION: pParticle->Rotation = degreesToRadians(fScale); break; case CParticleAttribute::ATR_ACCELX: pParticle->Acceleration.x = fScale; break; case CParticleAttribute::ATR_ACCELY: pParticle->Acceleration.y = fScale; break; case CParticleAttribute::ATR_ACCELZ: pParticle->Acceleration.z = fScale; break; } } pParticle->Color = D3DCOLOR_ARGB(cA, cR, cG, cB); getRandomVector(&pParticle->Velocity, &m_vMinVelocityTrans, &m_vMaxVelocityTrans); pParticle->Velocity *= getRandomFloat(fMinVel, fMaxVel); m_vMinVelocityTrans *= fMinVel; m_vMaxVelocityTrans *= fMaxVel; D3DXVECTOR3 vMin(0.0f, 0.0f, 0.0f), vMax(0.0f, 0.0f, 0.0f); switch(m_eSpawnShape) { case SH_CUBE: vMin.x = -m_vSpawnRadius.x; vMin.y = -m_vSpawnRadius.y; vMin.z = -m_vSpawnRadius.z; getRandomVector(&pParticle->Position, &vMin, &m_vSpawnRadius); break; case SH_SQUARE: vMin.x = -m_vSpawnRadius.x; vMin.z = -m_vSpawnRadius.z; vMax.x = m_vSpawnRadius.x; vMax.z = m_vSpawnRadius.z; getRandomVector(&pParticle->Position, &vMin, &vMax); break; case SH_SPHERE: getRandomVector(&vMin, -1.0f, 1.0f); D3DXVec3Normalize(&vMin, &vMin); pParticle->Position.x = vMin.x * m_vSpawnRadius.x; pParticle->Position.y = vMin.y * m_vSpawnRadius.x; pParticle->Position.z = vMin.z * m_vSpawnRadius.x; break; case SH_CIRCLE: getRandomVector(&vMin, -1.0f, 1.0f); D3DXVec3Normalize(&vMin, &vMin); pParticle->Position.x = vMin.x * m_vSpawnRadius.x; pParticle->Position.y = 0.0f; pParticle->Position.z = vMin.z * m_vSpawnRadius.x; break; } D3DXVec3TransformCoord(&pParticle->Position, &pParticle->Position, &mPosOffset); }
/// Standard C-style entry point int main(int argc, char* args[]) { SDL_Event event; /// An SDL Event object SDL_TimerID timer; srand((unsigned)time(NULL)); // seed the rand function // logging date and time when the application was executed time_t rawtime; struct tm now; time(&rawtime); localtime_s(&now, &rawtime); std::fstream log; log.open("log.txt", std::ios::app); log << "Ball Simulation Initialized at: " << (now.tm_year + 1900) << '-' << (now.tm_mon + 1) << '-' << (now.tm_mday) << '@' << (now.tm_hour) << ':' << (now.tm_min) << "\n"; log.close(); std::string errors; win = new GameBoard(1360, 720, 10, 10); int ballType; for (int i = 0, x = 1; i < numberOfBalls; i++, x++) { ballType = (rand() % 2) + 1; try { if (ballType == 1) { balls[i] = new Ball((win->convertToScreenCoordinates(x, 9)), getRandomVector(250, 1)); } else if (ballType == 2) { balls[i] = new cannonBall(win->convertToScreenCoordinates(x, 7), getRandomVector(500, 200)); } } catch (std::string se) { errors += "Content Load Exception: " + se + "for ball " + std::to_string(i) + "\n"; } } // append any errors to the file log.open("log.txt", std::ios::app); log << errors; log.close(); std::cout << errors; timer = SDL_AddTimer(16, handleTimer, NULL); /// Check for an input event while (SDL_WaitEvent(&event)) { if (event.type == SDL_KEYDOWN && (event.key.keysym.sym == SDLK_ESCAPE || event.key.keysym.sym == SDLK_SPACE)){ exit(0); } } /// Kill the window SDL_DestroyWindow(win->getWindow()); for (int i = 0; i < numberOfBalls; i++) { delete balls[i]; } delete[] balls; delete win; ///Exit the SDL subsystems SDL_Quit(); exit(0); }
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ #include <boost/test/unit_test.hpp> #include <boost/timer.hpp> #include <cl/tape/tape.hpp> #include <cl/tape/tests/testutil.hpp> static int dimension = (int)1e+7; static std::vector<double> doubleVector = getRandomVector(dimension); // Return time of tape recording for AD<double>. double ADTapePerformance() { std::vector<CppAD::AD<double>> ADvec = vectorCast<CppAD::AD<double>>(getRandomVector(dimension)); CppAD::AD<double> ADResult = 0; CppAD::Independent(ADvec); boost::timer timer; for (CppAD::AD<double> item : ADvec) { ADResult += CppAD::sin(item * CppAD::pow(ADResult, CppAD::sqrt(CppAD::pow(item, 2.0) * CppAD::exp(CppAD::cos(ADResult * CppAD::tan(item))))))