//弾生成 int CharacterScriptInterface::BulletGenerate( lua_State * l_) { //printf("aaaa\n"); Character* character = static_cast< Character* >( lua_touserdata( l_, 1 ) ); float spx = lua_tonumber(l_, 2); float spy = lua_tonumber(l_, 3); float svx= lua_tonumber(l_, 4); float svy= lua_tonumber(l_, 5); int da = lua_tonumber(l_, 6); u32 ra = lua_tonumber(l_, 7); u32 cr = lua_tonumber(l_, 8); float bvx = lua_tonumber(l_, 9); float bvy = lua_tonumber(l_, 10); u32 sf = lua_tonumber(l_, 11); u32 lf = lua_tonumber(l_, 12); int vol = lua_tonumber(l_, 13); Bullet *bul; bul = new Bullet(); bul->Initialize(); bul->setGeneObjType(character->getObjType()); bul->setPosition(LVector3(spx,spy,0)); bul->setVelocity(LVector3(svx,svy,0)); bul->setDirection(character->getDirection()); bul->setAttackParam(da,ra,cr,LVector3(bvx,bvy,0),sf); bul->setLifeFrame(lf); bul->setSeVol(vol); return 0; }
void clFightingChessPositioner::Update( float dt ) { float S = GetSpeed( dt ); if ( Env->Console->IsKeyPressed( LK_A ) ) { FPan -= 90.0f * dt; } if ( Env->Console->IsKeyPressed( LK_Z ) ) { FPan += 90.0f * dt; } if ( Env->Console->IsKeyPressed( LK_1 ) ) { FPosition.Z += S; } if ( Env->Console->IsKeyPressed( LK_2 ) ) { FPosition.Z -= S; } if ( Env->Console->IsKeyPressed( LK_LEFT ) ) { FPitch -= 90.0f * dt; } if ( Env->Console->IsKeyPressed( LK_RIGHT ) ) { FPitch += 90.0f * dt; } LMatrix4 PitchMtx; PitchMtx.IdentityMatrix(); PitchMtx.RotateMatrixAxis( Linderdaum::Math::DegToRad( FPitch ), LVector3( 0, 0, 1 ) ); LVector3 ViewDir = LVector3( PitchMtx[0][1], PitchMtx[1][1], PitchMtx[2][1] ); if ( Env->Console->IsKeyPressed( LK_UP ) ) { FPosition += ViewDir * S; } if ( Env->Console->IsKeyPressed( LK_DOWN ) ) { FPosition += -ViewDir * S; } clStdCameraPositioner::Update( dt ); }
int CharacterScriptInterface::SummonSoul(lua_State *l_) { Character* character = static_cast< Character* >( lua_touserdata( l_, 1 ) ); float x= lua_tonumber(l_,2); float y= lua_tonumber(l_, 3); ValfirleToken::CreateData data; data.Position = LVector3(x,y,1.f); data.WeaponLevel = 1; int temp =rand()%3; switch(temp) { case 0: data.WeaponType =WEAPON_BOSS_TAEKWONDO; break; case 1: data.WeaponType = WEAPON_BOSS_KNIFE; break; case 2: data.WeaponType = WEAPON_BOSS_KATANA; break; } //data.WeaponType = WEAPON_VALFIRLE_TOKEN; ValfirleToken *pBoss = ValfirleToken::create(&data); pBoss->setDirection(character->getDirection()); //pBoss->setVelocity(LVector3(5,4,1.f)); pBoss->setInvincibleFrame(180); pBoss->setDefPosition(character->getPosition()); pBoss->setScore(1); pBoss->setLife(1); pBoss->setOpacity(0.6); pBoss->setDefPosition(LVector3(x-80,y,1.f)); return 0; }
void clStandartPositioner::AfterConstruction() { /// 1. max-like clPanOrbitPositioner* Cam = Env->Linker->Instantiate( "clPanOrbitPositioner" ); Cam->FUpVector = LVector3( 0, 0, 1 ); /// 2. orbiting clTrajectoryPositioner* Traj = Env->Linker->Instantiate( "clTrajectoryPositioner" ); Traj->ResetTime(); Traj->FSpeedFactor = 3.0f; Traj->FUpVector = LVector3( 0, 0, 1 ); // 3. old "rail" positioner clRailPositioner* Rail = Env->Linker->Instantiate( "clRailPositioner" ); Rail->FDirVector = LVector3( 0, 1, 0 ); Rail->FUpVector = LVector3( 0, 0, 1 ); Rail->FPosition = LVector3( 0, 0, 200 ); Rail->FPan = +45.0f; FPositioners.push_back( Cam ); FPositioners.push_back( Traj ); FPositioners.push_back( Rail ); SetMode( 0 ); }
//--------------------------------------------------------------------------- bool BottomWall::Update() { ++this->m_nFrame; this->mPanel->SetPosition(this->mPosition); //発動条件(適当)//上下差が200以下 かつ 左右差が10以下 const int y = 150; const int x = 100; LVector3 myPos = this->mPosition; myPos.x += 50; myPos.y -= 100; if(abs(myPos.y - GameManager::getInstance()->getPlayer()->getPosition().y) <= y && abs(myPos.x - GameManager::getInstance()->getPlayer()->getPosition().x) <= x && this->m_bActive && !this->m_bStart) { GameAudio::PlaySE("./Data/Sound/SE/don01.wav",0.75,1.00); GameAudio::PlaySE("./Data/Sound/SE/don01.wav",0.90,0.70); GameAudio::PlaySE("./Data/Sound/SE/don01.wav",0.90,0.60); this->m_bStart = true; } if(this->m_bActive) { if(this->m_bStart) { //窓アニメーション if(!(this->m_nFrame % 2)) { if(this->m_nAnime < 8) { this->m_nAnime++; this->mPanel->SetSrcRect(LRect(this->m_nAnime * 160.0f,0,160.0f,160.0f)); } } //敵出現 if(!(this->m_nFrame % 6)) //2フレームに1回 { if(this->m_nEnemyNum) { Enemy* pEnemy = Enemy::createRandom(); pEnemy->setPosition(LVector3(this->mPosition.x + 65,this->mPosition.y - 130,this->mPosition.z)); pEnemy->setDefPosition(LVector3(this->mPosition.x + 65,this->mPosition.y - 130,this->mPosition.z)); pEnemy->setVelocity(LVector3(::rand() % 10 - 5,0,0)); this->m_nEnemyNum -= 1; } } } } return true; }
//--------------------------------------------------------------------------- bool Fort::Initialize() { this->Release(); this->mLife = scg_nFortLife[GameManager::getInstance()->getRank()]; this->m_nFrame = 0; this->mScore = 500; this->m_nAttackFrame = 0; this->m_nShootFrame = 0; this->m_nShootNum = 0; this->m_eAction = FORT_ACT_WAIT; this->setAttackedGroup( ATKGROUP_ENEMY ); this->mColRect.Set( mPosition.x+11, mPosition.y-7, 18*mScale.x, 33*mScale.y ); this->mPanel = Sprite3D::Create(60.0f,60.0f);//,LN_PANELDIR_UPPER_REFT); this->mPanel->SetCenter(-30, 30, 0); this->mPanel->SetTexture(Assets::LoadTexture(g_szFortFilePath/*,0xffffffff*/)); this->mPanel->SetPosition(this->mPosition); this->mPanel->SetVisible(true); this->mPanel->SetCenter(17.0f,20.0f,0.0f); this->mPanel2 = Sprite3D::Create(20.0f,20.0f);//,LN_PANELDIR_UPPER_REFT); this->mPanel2->SetCenter(-10, 10, 0); this->mPanel2->SetTexture(Assets::LoadTexture(g_szFortFilePath2)); this->mPanel2->SetPosition(LVector3(this->mPosition.x,this->mPosition.y,0)); this->mPanel2->SetVisible(true); return true; }
void clASELoader::ASE_ReadVertexList( iIStream* FStream, clVAMender* Mender ) { guard(); #ifdef ASE_HEAVY_DEBUG Env->Logger->Log( L_DEBUG, "Reading vertex list..." ); #endif char Keyword[32]; int Index; float X, Y, Z; while ( !FStream->Eof() ) { LString Line( FStream->ReadLineTrimLeadSpaces() ); if ( LStr::StartsWith( Line, ASE_MeshVertex ) ) { sscanf( Line.c_str(), "%s %d %f %f %f", Keyword, &Index, &X, &Y, &Z ); Mender->EmitVertex( Index, LVector3( X, Y, Z ), -1, -1 ); } else if ( LStr::ContainsSubStr( Line, "}" ) ) { break; } else { FATAL_MSG( "Unexpected token in " + ASE_MeshVertexList + " : " + Line ); } } unguard(); }
void clASELoader::ASE_ReadTVertexList( iIStream* FStream, clVAMender* Mender ) { guard(); #ifdef ASE_HEAVY_DEBUG Env->Logger->Log( L_DEBUG, "Reading Tvertex list..." ); #endif char Keyword[32]; while ( !FStream->Eof() ) { LString Line = FStream->ReadLineTrimLeadSpaces(); if ( LStr::ContainsSubStr( Line, "}" ) ) { break; } else if ( LStr::StartsWith( Line, ASE_MeshTVertex ) ) { int Index; float U, V, W; sscanf( Line.c_str(), "%s %d %f %f %f", Keyword, &Index, &U, &V, &W ); Mender->EmitTextureVertex( Index, LVector3( U, 1.0f - V, W ) ); } else { FATAL_MSG( "Unexpected token in " + ASE_MeshTVertexList + " : " + Line ); } } unguard(); }
//Generate camera_000nnn.rib void generateRIBCamera(unsigned int idFrame) { char bufferFileNumber[10]; sprintf(bufferFileNumber, "%05d", idFrame); std::stringstream fileName; fileName << "rib_scene" FILE_SEPARATOR_CHAR "cameras" FILE_SEPARATOR_CHAR "camera_" << bufferFileNumber << ".rib"; FILE* oFile = fopen(fileName.str().c_str(), "w"); fprintf(oFile, "## Camera frame: %s\n\n", bufferFileNumber); //fprintf(oFile, "Translate 0 -15 70\n"); //fprintf(oFile, "Rotate -30 1 0 0\n"); //fprintf(oFile, "Rotate 45 0 1 0\n\n"); Camera camera = loadCamera(idFrame); if (camera.eyePosition == LVector3(0.0, 0.0, 0.0)) { fprintf(oFile, "Translate 0 -3 40\n"); fprintf(oFile, "Rotate -15 1 0 0\n"); fprintf(oFile, "Rotate 45 0 1 0\n\n"); } else { //Camera with position and lookat float tEyeX = camera.eyePosition.x - camera.lookAt.x; float tEyeY = camera.eyePosition.y - camera.lookAt.y; float tEyeZ = camera.eyePosition.z - camera.lookAt.z; float rc = sqrt(tEyeX*tEyeX + tEyeY*tEyeY + tEyeZ*tEyeZ); float tc = acos(tEyeY / rc) * 180.0 / CONV_PI - 90; float pc = - atan2(tEyeZ , tEyeX) * 180.0 / CONV_PI + 90; fprintf(oFile, "Rotate %f 1 0 0 #Camera lookat tilt\n", tc); fprintf(oFile, "Rotate %f 0 1 0 #Camera lookat rotate\n", pc); fprintf(oFile, "Translate %f %f %f #Camera position\n", -camera.eyePosition.x, -camera.eyePosition.y, camera.eyePosition.z); fprintf(oFile, "Scale 1 1 -1 #Right-hand Coordinate System\n"); /* //Camera position with lookat at origin (0,0,0) float r = sqrt(camera.eyePosition.x*camera.eyePosition.x + camera.eyePosition.y*camera.eyePosition.y + camera.eyePosition.z*camera.eyePosition.z); float t = acos(camera.eyePosition.y / r) * 180.0 / CONV_PI - 90; float p = - atan2(camera.eyePosition.z , camera.eyePosition.x) * 180.0 / CONV_PI + 90; fprintf(oFile, "Translate 0 0 %f #Camera position\n", r); fprintf(oFile, "Rotate %f 1 0 0 #Camera tilt\n", t); fprintf(oFile, "Rotate %f 0 1 0 #Camera rotate\n", p); fprintf(oFile, "Scale 1 1 -1 #Right-hand Coordinate System\n"); */ } //For Dragon shatter animation //fprintf(oFile, "Rotate -18 1 0 0\n"); //fprintf(oFile, "Translate 0 -15 48\n"); //fprintf(oFile, "Rotate -30 0 1 0\n\n"); fclose (oFile); }
int CharacterScriptInterface::setAccel(lua_State *l_) { Character* character = static_cast< Character* >( lua_touserdata( l_, 1 ) ); float x= lua_tonumber(l_,2); float y= lua_tonumber(l_, 3); character->setAccel(LVector3(x,y,0)); return 0; }
int CharacterScriptInterface:: Division(lua_State * l_) { Character* character = static_cast< Character* >( lua_touserdata( l_, 1 ) ); float x= lua_tonumber(l_,2); float y= lua_tonumber(l_, 3); ValfirleToken::CreateData data; data.Position = LVector3(x,y,1.f); data.WeaponLevel = 1; data.WeaponType = WEAPON_VALFIRLE_TOKEN; ValfirleToken *pBoss = ValfirleToken::create(&data); pBoss->setDirection(character->getDirection()); //pBoss->setVelocity(LVector3(5,4,1.f)); pBoss->setInvincibleFrame(50); pBoss->setScore(1); pBoss->setLife(100); pBoss->setDefPosition(LVector3(x,y,1.f)); // printf("分裂\n"); return 0; }
// Vertices - source vertex array, Center - center of the box, Axes - box axes, A - box extents void BuildBoundingBox( int NumPts, const LVector3* Vertices, LVector3& Center, LVector3* Axes, float* A ) { if ( NumPts <= 0 ) { return; } int i, j, p; // indices Center = LVector3( 0, 0, 0 ); // 1. determine geometric center float Denom = 1.0f / static_cast<float>( NumPts ); for ( p = 0 ; p < NumPts ; p++ ) { Center += Vertices[p] * Denom; } // 2. calculate covariance matrix LMatrix3 Cov; // variations for ( p = 0 ; p < NumPts ; p++ ) { LVector3 D = Vertices[p] - Center; for ( i = 0 ; i < 3 ; i++ ) for ( j = 0 ; j < 3 ; j++ ) { Cov[i][j] += ( D[i] * D[j] ) * Denom; } } // substract squared expectation for ( i = 0 ; i < 3 ; i++ ) for ( j = 0 ; j < 3 ; j++ ) { Cov[i][j] -= Center[i] * Center[j]; } // 3. eigenvectors of the covariance matrix are the axes of the bbox Cov.CalculateEigenVectors( Axes, A ); // 4. calculate box extents along each axis for ( i = 0 ; i < 3 ; i++ ) { A[i] = -1.0f; } for ( p = 0 ; p < NumPts ; p++ ) for ( i = 0 ; i < 3 ; i++ ) { float l = fabs( ( Vertices[p] - Center ).Dot( Axes[i] ) ); if ( l > A[i] ) { A[i] = l; } } }
Camera loadCamera(const char * filename) { std::cout << "loadCamera in file: " << filename << std::endl; Camera camera; std::ifstream fileOut(filename, std::ios::in | std::ios::binary); if (!fileOut.good()) { std::cout << "loadCamera not found: " << filename << std::endl; camera.idFrame = 0; camera.eyePosition = LVector3(0.0, 0.0, 0.0); camera.lookAt = LVector3(0.0, 0.0, 0.0); camera.keyframe = false; } else { boost::archive::binary_iarchive ia(fileOut); ia & camera; fileOut.close(); } return camera; }
//グレネード生成 int CharacterScriptInterface::GrenadeGenerate( lua_State * l_) { Character* character = static_cast< Character* >( lua_touserdata( l_, 1 ) ); //printf("aaaa\n"); float spx = lua_tonumber(l_, 2); float spy = lua_tonumber(l_, 3); float svx= lua_tonumber(l_, 4); float svy= lua_tonumber(l_, 5); float fs = lua_tonumber(l_, 6); int da = lua_tonumber(l_, 7); u32 ra = lua_tonumber(l_, 8); u32 cr = lua_tonumber(l_, 9); float bvx = lua_tonumber(l_, 10); float bvy = lua_tonumber(l_, 11); u32 sf = lua_tonumber(l_, 12); int rbx = lua_tonumber(l_, 13); int rby = lua_tonumber(l_, 14); u32 rs = lua_tonumber(l_, 15); Grenade *gre; gre = new Grenade(); gre->Initialize(); gre->setGeneObjType(character->getObjType()); gre->setPosition(LVector3(spx,spy,0)); gre->setVelocity(LVector3(svx,svy,0)); gre->setFallSpeed(fs); gre->setDirection(character->getDirection()); gre->setAttackParam(da,ra,cr,LVector3(bvx,bvy,0),sf); gre->setRandBrow(rbx,rby); gre->setRandStun(rs); return 0; }
void clVAMender::EmitTextureFace( int FaceIndex, int A, int B, int C ) { size_t NewSize = static_cast<size_t>( FaceIndex ) + 1; if ( NewSize > FTextureFaces.size() ) { // FTextureFaces.reserve( NewSize * 2 ); FTextureFaces.resize( NewSize ); } FTextureFaces[FaceIndex] = LVector3( static_cast<float>( A ), static_cast<float>( B ), static_cast<float>( C ) ); }
int CharacterScriptInterface:: SummonEnemy(lua_State *l_) { Weapon::CreateData wdata; wdata.Data.WeaponType = static_cast<WeaponType>(::rand() % (WEAPON_NORMAL_MAX_NUM - 1) + 1); wdata.Data.UseCount = gWeaponBaseData[wdata.Data.WeaponType].UseCount; LVector3 v ; v.set(900,1000,0); v.x += ::rand() % 300 - 150; v.y += 180; wdata.Position = v; Weapon::create( &wdata ); Enemy* mEnemy1 = Enemy::createRandom(); mEnemy1->setPosition(LVector3(700,1000,1)); mEnemy1->setDefPosition(LVector3(700,1000,1)); mEnemy1->setScore(1); Enemy* mEnemy = Enemy::createRandom(); mEnemy->setPosition(LVector3(1200,1000,1)); mEnemy->setDefPosition(LVector3(1200,1000,1)); mEnemy->setScore(1); return 0; }
//--------------------------------------------------------------------- // ● 攻撃効果の適用 (対象を攻撃する) //--------------------------------------------------------------------- int CharacterScriptInterface::attackEffect( lua_State *l_ ) { Character* character = static_cast< Character* >( lua_touserdata( l_, 1 ) ); AttackedObject* obj = static_cast< AttackedObject* >( lua_touserdata( l_, 2 ) ); obj->attackEffect( character, static_cast< int >( lua_tonumber( l_, 3 ) ), static_cast< u32 >( lua_tonumber( l_, 4 ) ), static_cast< u32 >( lua_tonumber( l_, 5 ) ), LVector3( static_cast< float >( lua_tonumber( l_, 6 ) ), static_cast< float >( lua_tonumber( l_, 7 ) ), 0 ), static_cast< float >( lua_tonumber( l_, 8 ) ) ); lua_pop( l_, lua_gettop( l_ ) ); return 0; }
//--------------------------------------------------------------------------- // ● オブジェクトをランダムで作成する //--------------------------------------------------------------------------- Valfirle* Valfirle::createRandom() { Valfirle::CreateData data; data.Position = LVector3(0,0,0); data.WeaponLevel = 1; data.WeaponType = WEAPON_NON; for(int i = 0;i < WEAPON_MAX_NUM;++i) { if(!(::rand() % gWeaponBaseData[i].Rate)) { data.WeaponType = static_cast<WeaponType>(i); break; } } data.WeaponType = static_cast<WeaponType>(::rand() % WEAPON_NORMAL_MAX_NUM); //data.WeaponType = WEAPON_KATANA; Valfirle* pEnemy = Valfirle::create( &data ); return pEnemy; }
void clGUIColorDial::SetAlpha( const LVector2& Pnt ) { LVector2 dP = Screen2Local( Pnt ); dP = LVector2( dP.X / GetWidth(), dP.Y / GetHeight() ); float nx = ( dP.X - 0.5f ) * 2.0f; float ny = ( dP.Y - 0.5f ) * 2.0f; float r = sqrt( nx * nx + ny * ny ); float r_min = FRMin; LVector2 p_color = -Math::ToPolar( r_min, FAlpha ); LVector2 p_white = -Math::ToPolar( r_min, FAlpha + 120.0f ); LVector2 p_black = -Math::ToPolar( r_min, FAlpha + 240.0f ); LVector3 Mark = LVector3( FMousePoint.X * p_black + FMousePoint.Y * p_white + FMousePoint.Z * p_color, 1.0f ); DialSP->BindUniforms(); DialSP->SetUniformVec3Array( FMousePtUniform, 1, Mark ); if ( r < FRMax && r > FRMin ) { FAlpha = 180.0f + Linderdaum::Math::RadToDeg( atan2( ny, nx ) ); DialSP->SetUniformFloat( FAlphaUniform, FAlpha ); } else { LVector3 NewB = Math::Barycentric2D( nx, ny, p_black.X, p_black.Y, p_white.X, p_white.Y, p_color.X, p_color.Y ); if ( NewB.X >= 0 && NewB.X <= 1 && NewB.Y >= 0 && NewB.Y <= 1 && NewB.Z >= 0 && NewB.Z <= 1 ) { FMousePoint = NewB; } } LVector3 CC = FMousePoint.X * LC_Black.ToVector3() + FMousePoint.Y * LC_White.ToVector3() + FMousePoint.Z * Math::ColorFromAngle( FAlpha ); Env->Console->GetVar( FOutVarName )->SetVector4( LVector4( CC, 1.0f ) ); }
void clParticleEmitter_Box::EmitParticles( const clPtr<clParticleSystem>& PS, float DeltaTime ) const { FAccumulatedTime += DeltaTime; while ( FAccumulatedTime > 1.0f / FEmissionRate && PS->GetParticles().size() < FMaxParticles ) { FAccumulatedTime -= 1.0f / FEmissionRate; sParticle P; P.FPosition = Math::RandomVector3InRange( FPosMin, FPosMax ); P.FVelocity = Math::RandomVector3InRange( FVelMin, FVelMax ); P.FAcceleration = LVector3( 0.0f ); P.FTTL = Math::RandomInRange( FLifetimeMin, FLifetimeMax ); P.FLifeTime = P.FTTL; P.FRGBA = Math::RandomVector4InRange( FColorMin, FColorMax ); P.FRGBA.w = 1.0f; P.FSize = Math::RandomInRange( FSizeMin, FSizeMax ); PS->AddParticle( P ); } }
void clVAMender::EmitFace( int FaceIndex, int A, int B, int C, int SubMaterialIndex, int SmoothingGroup ) { size_t NewSize = static_cast<size_t>( FaceIndex ) + 1; if ( NewSize > FFaces.size() ) { // FFaces.reserve( NewSize * 2 ); // FFacesSubMaterial.reserve( NewSize * 2 ); // FFacesSmoothingGroup.reserve( NewSize * 2 ); FFaces.resize( NewSize ); FFacesSubMaterial.resize( NewSize ); FFacesSmoothingGroup.resize( NewSize ); } FFaces[FaceIndex] = LVector3( static_cast<float>( A ), static_cast<float>( B ), static_cast<float>( C ) ); FFacesSubMaterial[FaceIndex] = SubMaterialIndex; FFacesSmoothingGroup[FaceIndex] = SmoothingGroup + 1; }
void StaticObject::calculateVolumeMassInertia() { std::vector<double> volumeInertia; if (isConvex) { //The object is convex so we can use the tetrahedras build with the mesh triangles and the origin volumeInertia = internalVolumeAndInertiaMeshConvex(meshData.first.first, Point(0.0, 0.0, 0.0)); } else { //The object is not-convex so we have to use the volume Tetrahedralization. // Call 2 times internalVolumeAndInertiaMesh using for each time a smallest facetDistance if the return volume is 0.0 double minBBDimension = minimumBoundingDimension(meshData.first.first); unsigned int numCycle = 0; int multipleValue = 1; do { std::cout << "StaticObject::calculateVolumeMassInertia: using facetDistance:" << (ConfigManager::facet_distance_coef * multipleValue) << std::endl; volumeInertia = internalVolumeAndInertiaMesh(meshData.first.first, minBBDimension / (ConfigManager::facet_distance_coef * multipleValue)); numCycle++; multipleValue *= 10; } while ((volumeInertia.at(0) == 0.0) && (numCycle < 2)); //If the volume is still < 0.05 we use the internalVolumeAndInertiaMeshConvex that can approximate the non-convex object volume and inertia if (volumeInertia.at(0) < 0.05) { volumeInertia = internalVolumeAndInertiaMeshConvex(meshData.first.first, Point(0.0, 0.0, 0.0)); } } //TODO: fix for nan number //Populate the object properties: volume, inertia and mass volume = volumeInertia.at(0); inertia = LVector3(volumeInertia.at(1) * density, volumeInertia.at(2) * density, volumeInertia.at(3) * density); mass = volume * density; }
//void clASELoader::ASE_ReadMaterial(int MaterialIndex, int SubMaterialIndex, int SubMaterialNesting) sASEMaterial clASELoader::ASE_ReadMaterial( iIStream* FStream, int SubMaterialNesting ) { guard(); sASEMaterial Material; while ( !FStream->Eof() ) { LString Line = FStream->ReadLineTrimLeadSpaces(); if ( LStr::ContainsSubStr( Line, "}" ) ) { break; } else if ( LStr::StartsWith( Line, ASE_MaterialName ) ) { // size_t TotalMTLSlots = FMaterialList.size(); //FATAL( MaterialIndex >= static_cast<int>( TotalMTLSlots ), //"Number of reserved material slots exceeded. Check for "+ASE_MaterialCount+" value in ASE file: " + FMesh->GetFileName() + "(reserved: "+LStr::ToStr( TotalMTLSlots ) + ", requested: "+LStr::ToStr(MaterialIndex)+")" ); Material.FName = LStr::GetToken( Line, 2 ); #ifdef ASE_HEAVY_DEBUG Env->Logger->Log( L_DEBUG, "Reading material: " + Material.FName ); #endif } else if ( LStr::StartsWith( Line, ASE_MaterialClass ) ) { Material.FClass = LStr::GetToken( Line, 2 ); } else if ( LStr::StartsWith( Line, ASE_MaterialAmbient ) ) { Material.FAmbient = LVector3( LStr::ToFloat( LStr::GetToken( Line, 2 ) ), LStr::ToFloat( LStr::GetToken( Line, 3 ) ), LStr::ToFloat( LStr::GetToken( Line, 4 ) ) ); } else if ( LStr::StartsWith( Line, ASE_MaterialDiffuse ) ) { Material.FDiffuse = LVector3( LStr::ToFloat( LStr::GetToken( Line, 2 ) ), LStr::ToFloat( LStr::GetToken( Line, 3 ) ), LStr::ToFloat( LStr::GetToken( Line, 4 ) ) ); } else if ( LStr::StartsWith( Line, ASE_MaterialSpecular ) ) { Material.FSpecular = LVector3( LStr::ToFloat( LStr::GetToken( Line, 2 ) ), LStr::ToFloat( LStr::GetToken( Line, 3 ) ), LStr::ToFloat( LStr::GetToken( Line, 4 ) ) ); } else if ( LStr::StartsWith( Line, ASE_MaterialShine ) ) { Material.FShine = LStr::ToFloat( LStr::GetToken( Line, 2 ) ); } else if ( LStr::StartsWith( Line, ASE_MaterialShineStrength ) ) { Material.FShineStrength = LStr::ToFloat( LStr::GetToken( Line, 2 ) ); } else if ( LStr::StartsWith( Line, ASE_MaterialTransparency ) ) { Material.FTransparency = LStr::ToFloat( LStr::GetToken( Line, 2 ) ); } else if ( LStr::StartsWith( Line, ASE_MaterialWireSize ) ) { Material.FWireSize = LStr::ToFloat( LStr::GetToken( Line, 2 ) ); } else if ( LStr::StartsWith( Line, ASE_MaterialShading ) ) { Material.FShading = LStr::GetToken( Line, 2 ); } else if ( LStr::StartsWith( Line, ASE_MaterialXPFalloff ) ) { Material.FXPFallOff = LStr::ToFloat( LStr::GetToken( Line, 2 ) ); } else if ( LStr::StartsWith( Line, ASE_MaterialSelfIllum ) ) { Material.FSelfIllum = LStr::ToFloat( LStr::GetToken( Line, 2 ) ); } else if ( LStr::StartsWith( Line, ASE_MaterialFalloff ) ) { Material.FFallOff = LStr::GetToken( Line, 2 ); } else if ( LStr::StartsWith( Line, ASE_MaterialXPType ) ) { Material.FXPType = LStr::GetToken( Line, 2 ); } else if ( LStr::StartsWith( Line, ASE_SubMaterialCount ) ) { int SubMaterialCount = LStr::ToInt( LStr::GetToken( Line, 2 ) ); if ( Material.FSubMaterials.size() == 0 ) { // don't redefine submaterials Material.FSubMaterials.resize( SubMaterialCount ); } } else if ( LStr::StartsWith( Line, ASE_SubMaterial ) ) { int SubMaterialIndex = LStr::ToInt( LStr::GetToken( Line, 2 ) ); #ifdef ASE_HEAVY_DEBUG Env->Logger->Log( L_NOTICE, "Found submaterial:" + LStr::ToStr( SubMaterialIndex ) ); #endif // if ( SubMaterialNesting < 1 ) // don't read sub-submaterials... Material.FSubMaterials[ SubMaterialIndex ] = ASE_ReadMaterial( FStream, SubMaterialNesting + 1 ); } else if ( LStr::StartsWith( Line, ASE_MaterialMapAmbient ) ) { ASE_ReadMap( FStream, &Material.FAmbientMap ); } else if ( LStr::StartsWith( Line, ASE_MaterialMapDiffuse ) ) { ASE_ReadMap( FStream, &Material.FDiffuseMap ); } else if ( LStr::StartsWith( Line, ASE_MaterialMapSpecular ) ) { ASE_ReadMap( FStream, &Material.FSpecularMap ); } else if ( LStr::StartsWith( Line, ASE_MaterialMapBump ) ) { ASE_ReadMap( FStream, &Material.FBumpMap ); } else { ASE_SkipBlock( FStream, Line ); } } /* // add to list if ( SubMaterialIndex == -1 ) { Env->Logger->Log( L_NOTICE, "Material:" + LString( Material.FName ) ); FMaterialList[ MaterialIndex ].FDefaultMeterial = Material; } else { Env->Logger->Log( L_NOTICE, "SubMaterial:" + LString( Material.FName ) ); size_t TotalMTLSlots = FMaterialList[ MaterialIndex ].FSubMaterials.size(); FATAL( SubMaterialIndex >= static_cast<int>( TotalMTLSlots ), "Number of reserved submaterial slots exceeded. Check for "+ASE_SubMaterialCount+" value in ASE file. " + "(reserved: "+LStr::ToStr( TotalMTLSlots ) + ", requested: "+LStr::ToStr(SubMaterialIndex)+")" ); FMaterialList[ MaterialIndex ].FSubMaterials[ SubMaterialIndex ] = Material; }*/ return Material; unguard(); }
clVertexAttribs* clVAMender::CreateVertexAttribs( int ForSubMaterial ) { if ( FFaces.size() == 0 ) { FLastError = "Unable to create vertex array: FFaces.size() = 0"; return NULL; } // FATAL( FFaces.size() == 0, "Unable to create vertex array: FFaces.size() = 0" ); size_t SubMaterialFaces = 0; // calculate number of faces for this submaterial (immutable per frame) for ( size_t i = 0; i != FFaces.size(); ++i ) { if ( FFacesSubMaterial[i] == ForSubMaterial ) { SubMaterialFaces++; } } if ( !SubMaterialFaces ) { return NULL; } clVertexAttribs* VA = clVertexAttribs::CreateEmpty(); // SubMaterialFaces * 3, L_TEXCOORDS_BIT | L_NORMALS_BIT ); for ( size_t i = 0; i != FJointsFrames.size(); ++i ) { VA->AddSkeletonFrame( *FJointsFrames[i] ); } if ( FWeights.size() > 0 ) { VA->FWeights.FStream.resize( FWeights.size() ); sWeight* Weights = VA->FWeights.GetPtr(); for ( size_t i = 0; i != FWeights.size(); ++i ) { Weights[ i ] = FWeights[ i ]; } } FVerticesSmoothingGroup.clear(); FVerticesSmoothingGroup.reserve( SubMaterialFaces * 3 ); VA->Restart( L_PT_TRIANGLE, SubMaterialFaces * 3, L_TEXCOORDS_BIT | L_NORMALS_BIT | L_BONES_BIT ); for ( size_t i = 0; i != FFaces.size(); ++i ) { if ( FFacesSubMaterial[i] != ForSubMaterial ) { continue; } int CurrentSG = FFacesSmoothingGroup[i]; // for each apex of the face for ( int Apex = 0; Apex != 3; ++Apex ) { int VertexIndex = static_cast<int>( FFaces[i][Apex] ); FIXME( "think about this" ) LVector3 Normal = LVector3( 0, 0, 0 ); if ( FFacesNormals.size() > 0 ) { Normal = FFacesNormals[i].FVertexNormal[Apex]; } else if ( FNormals.size() > 0 ) { Normal = FNormals[VertexIndex]; } // Normal = FNormals[VertexIndex]; VA->SetNormalV( Normal ); if ( FTextureFaces.size() > 0 ) { int TextureIndex = static_cast<int>( FTextureFaces[i][Apex] ); VA->SetTexCoord( FTextureVertices[TextureIndex].X, FTextureVertices[TextureIndex].Y, FTextureVertices[TextureIndex].Z ); } VA->EmitVertexV( FVertices[VertexIndex], FWeightIndex[VertexIndex], FWeightCount[VertexIndex] ); FVerticesSmoothingGroup.push_back( CurrentSG ); } } if ( FNormals.empty() ) { BuildSGNMap( ForSubMaterial ); CalculateTBN( VA, ForSubMaterial ); } return VA; }
void clVAMender::BuildSGNMap( int ForSubMaterial ) { std::vector<int> AlreadyAddedToSG; // indexed by input vertex index size_t MaxNumVtx = 3 * FFaces.size(); FSplitVertexToSGVertex_SGNum.clear(); FSplitVertexToSGVertex_SGNum.resize( MaxNumVtx ); FSplitVertexToSGVertex_VIndex.clear(); FSplitVertexToSGVertex_VIndex.resize( MaxNumVtx ); AlreadyAddedToSG.clear(); AlreadyAddedToSG.resize( MaxNumVtx ); // clear flags for ( size_t i = 0; i != MaxNumVtx ; ++i ) { AlreadyAddedToSG[i] = 0; } FSGN.clear(); FSplitMap.clear(); int MaxSmoothingGroupIdx = 0; // prepare SGN data structure for ( size_t i = 0; i != FFaces.size(); ++i ) { //if ( FFacesSubMaterial[i] != ForSubMaterial ) continue; if ( MaxSmoothingGroupIdx < FFacesSmoothingGroup[i] ) { MaxSmoothingGroupIdx = FFacesSmoothingGroup[i]; } while ( FFacesSmoothingGroup[i] >= static_cast<int>( FSGN.size() ) ) { clVectorsList NormalsList; clIntsList IntsList; IntsList.resize( FVertices.size() ); FSGN.push_back( NormalsList ); FSplitMap.push_back( IntsList ); } } // Env->Logger->Log( L_DEBUG, "MaxSmoothingGroupIdx = "+LStr::ToStr(MaxSmoothingGroupIdx) ); // create mapping for every SG int Idx = 0; for ( size_t i = 0; i != FFaces.size(); ++i ) { // if ( FFacesSubMaterial[i] != ForSubMaterial ) continue; int SG = FFacesSmoothingGroup[i]; for ( int Apex = 0; Apex != 3; ++Apex ) { int VertexIndex = static_cast<int>( FFaces[i][Apex] ); int OutputVertex = 3 * Idx + Apex; FSplitVertexToSGVertex_SGNum[ OutputVertex ] = SG; if ( !Math::IsBitSet( AlreadyAddedToSG[VertexIndex], SG ) ) { // dump // Env->Logger->Log( L_DEBUG, "SGN: "+LStr::ToStr(SG)+" VertexIndex: "+LStr::ToStr(VertexIndex) ); AlreadyAddedToSG[VertexIndex] = Math::SetBit( AlreadyAddedToSG[VertexIndex], SG ); FSplitVertexToSGVertex_VIndex[ OutputVertex ] = ( int )FSGN[SG].size(); FSplitMap[SG][VertexIndex] = ( int )FSGN[SG].size(); FSGN[SG].push_back( LVector3( 0, 0, 0 ) ); // add empty normal } else { FSplitVertexToSGVertex_VIndex[ OutputVertex ] = FSplitMap[SG][ VertexIndex ]; } } Idx++; } }
void clPanOrbitPositioner::MakeStep( float dt ) { /// zoom/pan faster when we are farther away float PanVelocity = FDefaultPanningVelocity * FViewDistance; PanVelocity = std::max( FMinPanningVelocity, PanVelocity ); float ZoomVelocity = FDefaultZoomVelocity * FViewDistance; ZoomVelocity = std::max( FMinZoomingVelocity, ZoomVelocity ); /// use supplied input values float PanHorz = -FPanDelta.X; float PanVert = -FPanDelta.Y; float LookHorz = -FOrbitDelta.X; float LookVert = +FOrbitDelta.Y; float Zoom = FZoomIn + FZoomOut; if ( FOrbiting ) { LookHorz += FMouseDelta.X; LookVert += FMouseDelta.Y; } if ( FPanning ) { PanHorz += FMouseDelta.X; PanVert -= FMouseDelta.Y; } if ( FZooming ) { Zoom += -FMouseDelta.X + FMouseDelta.Y; } float MoveFactorH = PanHorz * PanVelocity * dt; float MoveFactorV = PanVert * PanVelocity * dt; // TODO : use Up/ViewDir here LVector3 HorzMove = LVector3( FCurrentTransform[0][0], FCurrentTransform[1][0], FCurrentTransform[2][0] ) * MoveFactorH; LVector3 VertMove = LVector3( FCurrentTransform[0][1], FCurrentTransform[1][1], FCurrentTransform[2][1] ) * MoveFactorV; FTarget += HorzMove + VertMove; // if ( FZoomingIn ) { Zoom -= 1.0f; } // if ( FZoomingOut ) { Zoom += 1.0f; } FViewDistance += Zoom * ZoomVelocity * dt; /// handle orbiting FSphericalCoords.Z += LookVert * FDefaultOrbitingVelocity * dt; FSphericalCoords.Y += LookHorz * FDefaultOrbitingVelocity * dt; /// avoid that the camera slips past the center of interest if ( FViewDistance < FMinDistance ) { FViewDistance = FMinDistance; FTarget -= vec3( FCurrentTransform[0][2], FCurrentTransform[1][2], FCurrentTransform[2][2] ) * FViewDistance; } /// get polar vector in cartesian space // LMatrix4 ViewTrans = LMatrix4::GetTranslateMatrix( -FUpVector * FViewDistance ); LMatrix4 ViewTrans = LMatrix4::GetTranslateMatrix( vec3( 0.0f, 0.0f, -FViewDistance ) ); float Angle2 = Math::DegToRad( FSphericalCoords.Z ); float Angle1 = Math::DegToRad( FSphericalCoords.Y - 90.0f ); LMatrix4 RotY = LMatrix4::GetRotateMatrixAxis( Angle2, vec3( 1, 0, 0 ) ); LMatrix4 RotZ = LMatrix4::GetRotateMatrixAxis( Angle1, FUpVector ); LMatrix4 m = RotZ * RotY * ViewTrans; FCurrentTransform = LMatrix4::GetTranslateMatrix( FTarget ) * m; // Flip the Y axis. TODO: figure out the transform // mtx4 Refl = LMatrix4::GetDiagonalMatrixV(LVector4(1,1,-1,1)); // FCurrentTransform = Refl * FCurrentTransform; DecomposeCameraTransformation( FCurrentTransform, FViewerPosition, m ); }
// set projection Projection = Math::Perspective( 45.0f, Env->Viewport->GetAspectRatio(), 0.4f, 2000.0f ); // receive events from the Engine Camera = Env->Linker->Instantiate( "clGameCamera" ); Camera->GetCamera().SetPosition( LVector3(0,-10,10) ); CONNECTOBJ( L_EVENT_TIMER, &clGameCamera::Event_TIMER, Camera ); Env->Connect( L_EVENT_DRAWOVERLAY, Utils::Bind( &DrawOverlay ) ); Env->Connect( L_EVENT_TIMER, Utils::Bind( &Update ) ); // create scene Scene = Env->Linker->Instantiate("clScene"); // add geom object to the scene int ID = Scene->AddGeom( Env->Resources->CreateIcosahedron( 3.0f, LVector3(0) ) ); // set material clMaterial* Mtl = Env->Resources->CreateMaterial(); Mtl->SetPropertyValue( "DiffuseColor", "1.0 0.0 0.0 0" ); Mtl->SetPropertyValue( "CastShadow", "false" ); Scene->SetMtl( ID, Mtl ); // set position of the object Scene->SetLocalTransform( ID, LMatrix4::GetTranslateMatrix( LVector3( 0.0f, 0.0f, 0.0f ) ) );
//Generate objects/mesh_nnn.rib void generateRIBMesh(StaticObject &staticObject) { unsigned int idObj = staticObject.idObj; std::stringstream fileName; fileName << "rib_scene" FILE_SEPARATOR_CHAR "objects" FILE_SEPARATOR_CHAR "mesh_" << idObj << ".rib"; FILE* oFile = fopen(fileName.str().c_str(), "w"); fprintf(oFile, "# Object id: %d\n\n", idObj); //CUTTERMESHER_TRIANGLE_NO_CUTTED fprintf(oFile, "# CUTTERMESHER_TRIANGLE_NO_CUTTED, CUTTERMESHER_TRIANGLE_CUTTED\n"); fprintf(oFile, "AttributeBegin\n"); fprintf(oFile, "ReadArchive \"surfaces/surface_1.rib\"\n"); TrianglesList::iterator triangleIter; TrianglesInfoList::iterator triangleInfoIter; for(triangleIter = staticObject.meshData.first.first.begin(), triangleInfoIter = staticObject.meshData.first.second.begin(); triangleIter != staticObject.meshData.first.first.end() && triangleInfoIter != staticObject.meshData.first.second.end(); ++triangleIter, ++triangleInfoIter) { Triangle t = *triangleIter; TriangleInfo ti = *triangleInfoIter; if ((ti.cutType == CUTTERMESHER_TRIANGLE_NO_CUTTED) || (ti.cutType == CUTTERMESHER_TRIANGLE_CUTTED)) { LVector3 tbtv[3]; for (int i = 0; i < 3; ++i) { Point tv = t.vertex(i); double tx = CGAL::to_double(tv.x()); double ty = CGAL::to_double(tv.y()); double tz = CGAL::to_double(tv.z()); tbtv[i] = LVector3(tx, ty, tz); } fprintf(oFile, "Polygon \"P\" [ "); fprintf(oFile, "%f %f %f %f %f %f %f %f %f", tbtv[0].x, tbtv[0].y, tbtv[0].z, tbtv[1].x, tbtv[1].y, tbtv[1].z, tbtv[2].x, tbtv[2].y, tbtv[2].z); fprintf(oFile, " ]\n"); } } fprintf(oFile, "AttributeEnd\n\n"); //CUTTERMESHER_TRIANGLE_IN_CUT_PLANE fprintf(oFile, "# CUTTERMESHER_TRIANGLE_IN_CUT_PLANE\n"); fprintf(oFile, "AttributeBegin\n"); fprintf(oFile, "ReadArchive \"surfaces/surface_2.rib\"\n"); for(triangleIter = staticObject.meshData.first.first.begin(), triangleInfoIter = staticObject.meshData.first.second.begin(); triangleIter != staticObject.meshData.first.first.end() && triangleInfoIter != staticObject.meshData.first.second.end(); ++triangleIter, ++triangleInfoIter) { Triangle t = *triangleIter; TriangleInfo ti = *triangleInfoIter; if (ti.cutType == CUTTERMESHER_TRIANGLE_IN_CUT_PLANE) { LVector3 tbtv[3]; for (int i = 0; i < 3; ++i) { Point tv = t.vertex(i); double tx = CGAL::to_double(tv.x()); double ty = CGAL::to_double(tv.y()); double tz = CGAL::to_double(tv.z()); tbtv[i] = LVector3(tx, ty, tz); } fprintf(oFile, "Polygon \"P\" [ "); fprintf(oFile, "%f %f %f %f %f %f %f %f %f", tbtv[0].x, tbtv[0].y, tbtv[0].z, tbtv[1].x, tbtv[1].y, tbtv[1].z, tbtv[2].x, tbtv[2].y, tbtv[2].z); fprintf(oFile, " ]\n"); } } fprintf(oFile, "AttributeEnd\n\n"); fclose (oFile); }
void clASELoader::ASE_ReadNormals( iIStream* FStream, clVAMender* Mender ) { guard(); #ifdef ASE_HEAVY_DEBUG Env->Logger->Log( L_DEBUG, "Reading normals..." ); #endif int CurrentFace = -1; int VertexIndex = 0; sFaceNormal FaceNormal; LStr::clStringsVector Tokens( 6 ); while ( !FStream->Eof() ) { LString Line = FStream->ReadLineTrimLeadSpaces(); if ( LStr::ContainsSubStr( Line, "}" ) ) { break; } else if ( LStr::StartsWith( Line, ASE_MeshFaceNormal ) ) { if ( CurrentFace > -1 ) { Mender->EmitFaceNormal( CurrentFace, FaceNormal ); } LStr::FastSplitLine( 1, 5, Line, Tokens, true ); CurrentFace = LStr::ToInt( Tokens[2] ); float X = LStr::ToFloat( Tokens[3] ); float Y = LStr::ToFloat( Tokens[4] ); float Z = LStr::ToFloat( Tokens[5] ); VertexIndex = 0; FaceNormal.FFaceNormal = LVector3( X, Y, Z ); } else if ( LStr::StartsWith( Line, ASE_MeshVertexNormal ) ) { LStr::FastSplitLine( 1, 5, Line, Tokens, true ); int Index = LStr::ToInt( Tokens[2] ); float X = LStr::ToFloat( Tokens[3] ); float Y = LStr::ToFloat( Tokens[4] ); float Z = LStr::ToFloat( Tokens[5] ); LVector3 Vec( X, Y, Z ); Mender->EmitNormal( Index, Vec ); FaceNormal.FVertexNormal[ VertexIndex++ ] = Vec; } else { FATAL_MSG( "Unexpected token in " + ASE_MeshNormals + " : " + Line ); } } if ( CurrentFace > -1 ) { Mender->EmitFaceNormal( CurrentFace, FaceNormal ); } unguard(); }
Near.z = ( N.z > 0.0f ) ? bMin.z : bMax.z; /// If the near extreme point is outside, then the AABB is totally outside the frustum if ( N.Dot( Near ) + Plane->W > 0.0f ) { return false; } Plane++; } return true; } // indices of the plane-defining corner points LVector3 FrustumPlanePoints[] = { // PLANE_LEFT LVector3( FRUSTUM_ntl, FRUSTUM_nbl, FRUSTUM_fbl ), // PLANE_RIGHT LVector3( FRUSTUM_nbr, FRUSTUM_ntr, FRUSTUM_fbr ), // PLANE_TOP LVector3( FRUSTUM_ntr, FRUSTUM_ntl, FRUSTUM_ftl ), // PLANE_BOTTOM LVector3( FRUSTUM_nbl, FRUSTUM_nbr, FRUSTUM_fbr ), // PLANE_NEAR LVector3( FRUSTUM_ntl, FRUSTUM_ntr, FRUSTUM_nbr ), // PLANE_FAR LVector3( FRUSTUM_ftr, FRUSTUM_ftl, FRUSTUM_fbl ) }; void LFrustum::CalcFrustumInBasis( const LVector3& Pos, const LVector3& To, const LVector3& Up, float fw, float fh, float nw, float nh ) { LVector3 Z = Pos - To;