virtual void setupProjection3D( const projDef_s* pd ) { if ( pd == 0 ) { projDef.setDefaults(); } else { projDef = *pd; } if ( rf_forceZFar.getFloat() >= 0.f ) { projDef.zFar = rf_forceZFar.getFloat(); } }
void CG_RunTestEmitter() { if ( cg_testEmitter.getStr()[0] == 0 || cg_testEmitter.getStr()[0] == '0' ) { CG_FreeTestEmitter(); return; } class particleDeclAPI_i* pDecl = g_declMgr->registerParticleDecl( cg_testEmitter.getStr() ); if ( pDecl == 0 ) { CG_FreeTestEmitter(); return; } if ( cg_testEmitterInstance == 0 ) { cg_testEmitterInstance = new emitterD3_c; rf->addCustomRenderObject( cg_testEmitterInstance ); cg_testEmitterInstance->setOrigin( cg.refdefViewOrigin + cg.refdefViewAxis.getForward()*cg_testEmitter_cameraDistance.getFloat() ); } else { if ( cg_testEmitter_attachToCamera.getInt() ) { cg_testEmitterInstance->setOrigin( cg.refdefViewOrigin + cg.refdefViewAxis.getForward()*cg_testEmitter_cameraDistance.getFloat() ); } } cg_testEmitterInstance->setParticleDecl( pDecl ); }
void CG_RunViewModel() { if ( cg_printViewWeaponClipSize.getInt() ) { if ( cg.snap ) { g_core->Print( "ViewWeapon clip %i/%i\n", cg.snap->ps.viewWeaponCurClipSize, cg.snap->ps.viewWeaponMaxClipSize ); } } int viewModelEntity = cg.snap->ps.curWeaponEntNum; if ( cg_thirdPerson.integer ) { CG_FreeViewModelEntity(); if ( viewModelEntity != ENTITYNUM_NONE && cg_entities[viewModelEntity].rEnt ) { cg_entities[viewModelEntity].rEnt->showModel(); } return; } if ( viewModelEntity == ENTITYNUM_NONE ) { CG_FreeViewModelEntity(); return; } if ( cg_entities[viewModelEntity].rEnt ) { //cg_entities[viewModelEntity].rEnt->hideModel(); cg_entities[viewModelEntity].rEnt->setThirdPersonOnly( true ); } // local weapons offset (affected by cg_gunX/Y/Z cvars) vec3_c localOfs( 0, 0, 0 ); // local weapon rotation (affected by cg_gunRotX/Y/Z cvars) vec3_c localRot( 0, 0, 0 ); rModelAPI_i* viewModel; if ( cg.snap->ps.customViewRModelIndex ) { viewModel = cgs.gameModels[cg.snap->ps.customViewRModelIndex]; } else { if ( cg_entities[viewModelEntity].rEnt ) { viewModel = cg_entities[viewModelEntity].rEnt->getModel(); } else { viewModel = 0; } } if ( viewModel == 0 ) { CG_FreeViewModelEntity(); return; } // add hardcoded gun offset if ( !stricmp( viewModel->getName(), "models/weapons2/plasma/plasma.md3" ) || !stricmp( viewModel->getName(), "models/weapons2/railgun/railgun.md3" ) || !stricmp( viewModel->getName(), "models/weapons2/rocketl/rocketl.md3" ) || !stricmp( viewModel->getName(), "models/weapons2/shotgun/shotgun.md3" ) // it could be better for grenade launcher || !stricmp( viewModel->getName(), "models/weapons2/grenadel/grenadel.md3" ) ) { localOfs.set( 5, -5, -10 ); } else if ( !stricmp( viewModel->getName(), "models/weapons/w_physics.mdl" ) ) { // Half Life2 physgun (for weapon_physgun) // "w_*" is a worldmodel // set 90 yaw rotation (around Z axis) localRot.set( 0, 0, 90 ); localOfs.set( 5, -5, -10 ); } else if ( !stricmp( viewModel->getName(), "models/weapons/v_physcannon.mdl" ) ) { // "v_*" is a viewmodel #if 0 localRot.set( 0, 15, 90 ); localOfs.set( -35, 0, -50 ); #else localRot.set( 0, 0, 90 ); localOfs.set( -15, 0, -65 ); #endif } else { localRot = cg.snap->ps.viewModelAngles; localOfs = cg.snap->ps.viewModelOffset; if ( viewModel->isDeclModel() ) { localOfs += viewModel->getDeclModelAPI()->getOffset(); } } //g_core->Print("Player velocity: %f %f %f\n",cg.snap->ps.velocity.x,cg.snap->ps.velocity.y,cg.snap->ps.velocity.z); // calculate viewmodel bobbing offset based on player velocity viewModelMovement.setConfig( viewModelMovementConfig ); viewModelMovement.calcViewModelOffset( cg.snap->ps.isOnGround(), cg.snap->ps.velocity, cg.refdefViewAngles, cg.frametime * 0.001f ); const vec3_c& currentMovement = viewModelMovement.getCurrentMovement(); localOfs += currentMovement; if ( cg_printViewModelBobbingOffset.getInt() ) { g_core->Print( "Viewmodel bobbing movement: %f %f %f\n", currentMovement.x, currentMovement.y, currentMovement.z ); } if ( cg_printCurViewModelName.getInt() ) { g_core->Print( "Current viewmodel name: %s\n", viewModel->getName() ); } if ( cg_printCurViewModelAnimationCount.getInt() ) { g_core->Print( "Current viewmodel animation count: %i\n", viewModel->getNumAnims() ); } if ( cg_printCurViewModelBoneNames.getInt() ) { g_core->Print( "Current viewmodel %s bonenames:\n", viewModel->getName() ); viewModel->printBoneNames(); } CG_AllocViewModelEntity(); vec3_c origin = cg.refdefViewOrigin; vec3_c angles = cg.refdefViewAngles; // apply extra gun offset localOfs.x += cg_gunX.getFloat(); localOfs.y += cg_gunY.getFloat(); localOfs.z += cg_gunZ.getFloat(); // apply extra gun rotation localRot.x += cg_gunRotX.getFloat(); localRot.y += cg_gunRotY.getFloat(); localRot.z += cg_gunRotZ.getFloat(); if ( localRot.isNull() == false ) { matrix_c m; m.fromAngles( angles ); m.rotateX( localRot.x ); m.rotateY( localRot.y ); m.rotateZ( localRot.z ); angles = m.getAngles(); } // add local offset to hand origin origin.vectorMA( origin, cg.refdefViewAxis[0], localOfs.x ); origin.vectorMA( origin, cg.refdefViewAxis[1], localOfs.y ); origin.vectorMA( origin, cg.refdefViewAxis[2], localOfs.z ); // always update viewmodel position cg_viewModelEntity->setOrigin( origin ); cg_viewModelEntity->setAngles( angles ); cg_viewModelEntity->setFirstPersonOnly( true ); // set viewmodel model //rModelAPI_i *viewModel = rf->registerModel("models/testweapons/xrealMachinegun/machinegun_view.md5mesh"); cg_viewModelEntity->setModel( viewModel ); int viewModelAnimFlags; if ( stricmp( cg_forceViewModelAnimationFlags.getStr(), "none" ) ) { viewModelAnimFlags = cg_forceViewModelAnimationFlags.getInt(); } else { viewModelAnimFlags = cg.snap->ps.viewModelAnimFlags; } if ( stricmp( cg_forceViewModelAnimationIndex.getStr(), "none" ) ) { int index = cg_forceViewModelAnimationIndex.getInt(); cg_viewModelEntity->setDeclModelAnimLocalIndex( index, viewModelAnimFlags ); } else if ( stricmp( cg_forceViewModelAnimationName.getStr(), "none" ) ) { const char* animName = cg_forceViewModelAnimationName.getStr(); cg_viewModelEntity->setAnim( animName, viewModelAnimFlags ); } else { const char* animName = CG_ConfigString( CS_ANIMATIONS + cg.snap->ps.viewModelAnim ); if ( cg_printViewModelAnimName.getInt() ) { g_core->Print( "ViewModelAnim: %s, flags %i\n", animName, viewModelAnimFlags ); } if ( cg_viewModelEntity->hasAnim( animName ) ) { cg_viewModelEntity->setAnim( animName, viewModelAnimFlags ); } else { g_core->RedWarning( "ViewModel has no animation %s\n", animName ); } } }