From: Oliver O. <fr...@us...> - 2007-03-07 11:37:10
|
Update of /cvsroot/simspark/simspark/simulations/soccer In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv16715 Added Files: Tag: projectx Makefile.am bindings.rb simspark.cpp simspark.rb soccersim.rb Log Message: added simspark --- NEW FILE: soccersim.rb --- # # prepare soccer simulation # importBundle "soccer" # soccer namespace $soccerNameSpace = "Soccer" # register a variable in the soccer namespace def addSoccerVar(name, value) createVariable($soccerNameSpace, name, value) end # helper to get the value of a variable in the soccer namespace def getSoccerVar(name) eval <<-EOS #{$soccerNameSpace}.#{name} EOS end # set a random seed (a seed of 0 means: use a random random seed) randomServer = get($serverPath+'random') randomServer.seed(0) # the soccer field dimensions in meters addSoccerVar('FieldLength', randomServer.uniformRND(100.0,110.9).floor().to_f()) addSoccerVar('FieldWidth', randomServer.uniformRND(64.0,75.9).floor().to_f()) addSoccerVar('FieldHeight', 40.0) addSoccerVar('GoalWidth', 7.32) addSoccerVar('GoalDepth', 2.0) addSoccerVar('GoalHeight', 0.75) # FIFA: 2.44 addSoccerVar('BorderSize', 10.0) addSoccerVar('FreeKickDistance', 9.15) addSoccerVar('AutomaticKickOff', false) addSoccerVar('WaitBeforeKickOff', 2.0) # agent parameters addSoccerVar('AgentMass', 75.0) addSoccerVar('AgentRadius', 0.22) addSoccerVar('AgentMaxSpeed', 10.0) # ball parameters addSoccerVar('BallRadius', 0.7) # FIFA: 68-70 cm addSoccerVar('BallDensity',2) addSoccerVar('BallMass',0.45) # FIFA: 410-450 g # soccer rule parameters addSoccerVar('RuleGoalPauseTime',3.0) addSoccerVar('RuleKickInPauseTime',1.0) addSoccerVar('RuleHalfTime',5.0 * 60) addSoccerVar('RuleDropBallTime',30) scene = get($scenePath) scene.importScene('rsg/agent/soccer.rsg') # setup the GameControlServer gameControlServer = get($serverPath+'gamecontrol') gameControlServer.initControlAspect('GameStateAspect') gameControlServer.initControlAspect('BallStateAspect') # gameControlServer.initControlAspect('SoccerRuleAspect') # init monitorItems to transmit game state information monitorServer = get($serverPath+'monitor') monitorServer.registerMonitorItem('GameStateItem') # install the TrainerCommandParser to parse commands received from a # monitor client sparkRegisterMonitorCmdParser 'TrainerCommandParser' --- NEW FILE: simspark.cpp --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of simspark Tue May 9 2006 Copyright (C) Koblenz University, Germany University of Newcastle, Australia $Id: simspark.cpp,v 1.1.2.1 2007/03/07 11:37:06 fruit Exp $ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #ifdef HAVE_CONFIG_H #include <config.h> #endif #include <spark/spark.h> #include <oxygen/oxygen.h> #include <kerosin/kerosin.h> #include <zeitgeist/zeitgeist.h> #ifdef __APPLE__ // for WebInitForCarbon() #include <WebKit/CarbonUtils.h> #endif using namespace spark; using namespace kerosin; using namespace oxygen; using namespace zeitgeist; using namespace salt; using namespace boost; class SimSpark : public Spark { public: SimSpark(const std::string& relPathPrefix) : Spark(relPathPrefix) {}; /** called once after Spark finished it's init */ virtual bool InitApp(int argc, char** argv); /** print command line options */ void PrintHelp(); /** print a greeting */ void PrintGreeting(); /** process command line options */ bool ProcessCmdLine(int argc, char* argv[]); }; void SimSpark::PrintGreeting() { GetLog()->Normal() << "simspark, a monolithic simulator 0.1\n" << "Copyright (C) 2004 Markus Rollmann, \n" << "Universität Koblenz.\n" << "Copyright (C) 2004 - 2007" << "The RoboCup Soccer Server Maintenance Group.\n" << "\nType '--help' for further information\n\n"; } void SimSpark::PrintHelp() { GetLog()->Normal() << "\nusage: simspark [options]\n" << "\noptions:\n" << " --help\t print this message.\n" << "\n"; } bool SimSpark::ProcessCmdLine(int argc, char* argv[]) { for( int i = 0; i < argc; i++) { if( strcmp( argv[i], "--help" ) == 0 ) { PrintHelp(); return false; } } return true; } bool SimSpark::InitApp(int argc, char** argv) { GetSimulationServer()->SetSimStep(0.02); PrintGreeting(); // process command line if (! ProcessCmdLine(argc, argv)) { return false; } // run initialization scripts GetScriptServer()->Run("simspark.rb"); return true; } int main(int argc, char** argv) { #ifdef __APPLE__ WebInitForCarbon (); #endif std::cerr << "start\n"; // the spark app framework instance SimSpark spark("../../"); std::cerr << "create spark done\n"; if (! spark.Init(argc, argv)) { return 1; } std::cerr << "init spark done\n"; spark.GetSimulationServer()->Run(argc,argv); shared_ptr<RenderControl> renderCtr = spark.GetRenderControl(); if (renderCtr.get() != 0) { spark.GetLog()->Normal() << "Average FPS: " << renderCtr->GetFramesRendered() / spark.GetSimulationServer()->GetTime() << "\n"; } return 0; } --- NEW FILE: Makefile.am --- SUBDIRS = plugin noinst_PROGRAMS = simspark simspark_SOURCES = simspark.cpp all-local: app rsg rsg: $(LN_S) $(top_srcdir)/parts/rsg . app: mkdir -p $(srcdir)/simspark.app/Contents/MacOS mkdir -p $(srcdir)/simspark.app/Contents/plugins cp $(srcdir)/*.rb $(srcdir)/simspark.app/Contents/MacOS/ cp -r $(top_srcdir)/parts/rsg $(srcdir)/simspark.app/Contents/MacOS/rsg cp $(srcdir)/plugin/.libs/soccer.so $(srcdir)/simspark.app/Contents/plugins --- NEW FILE: simspark.rb --- # # simspark.rb # sparkSetupServer() sparkSetupRendering() sparkSetupInput() # let spark create a default camera sparkAddFPSCamera( $scenePath+'camera', x = -0.5, y = -20, z = 3, maxSpeed = 15.0, accel = 400.0, drag = 4, addCollider = false ) # setup default input bindings run "bindings.rb" # create custom materials material = new('kerosin/MaterialSolid', $serverPath+'material/matYellow'); material.setDiffuse(1.0,1.0,0.0,1.0) material = new('kerosin/MaterialSolid', $serverPath+'material/matOrange'); material.setDiffuse(1.0,0.3,0.0,1.0) material = new('kerosin/MaterialSolid', $serverPath+'material/matBlue'); material.setDiffuse(0.0,0.0,1.0,1.0) material = new('kerosin/MaterialSolid', $serverPath+'material/matWhite'); material.setDiffuse(1.0,1.0,1.0,1.0) material = new('kerosin/MaterialSolid', $serverPath+'material/matRed'); material.setDiffuse(1.0,0.0,0.0,1.0) material = new('kerosin/MaterialSolid', $serverPath+'material/matRedGlow'); material.setDiffuse(1.0,0.0,0.0,1.0) material.setEmission(0.5,0.0,0.0,1.0) material = new('kerosin/MaterialSolid', $serverPath+'material/matGreen'); material.setDiffuse(0.1,0.6,0.1,1.0) material.setAmbient(0.1,0.3,0.1,1.0) material = new('kerosin/MaterialSolid', $serverPath+'material/matGrey'); material.setDiffuse(0.1,0.1,0.1,1.0) material = new('kerosin/MaterialSolid', $serverPath+'material/matLightBlue'); material.setDiffuse(0.0,0.75,1.0,1.0) # # uncomment for logging setup (see spark.rb for reference) # sparkLogAllToFile('./spark.txt') sparkLogDebugToCerr() # # uncomment any of the following to run a simulation # importBundle "soccer" # create an arena with a bunch of boxes and spheres scene = get($scenePath) #scene.importScene('rsg/boxspheres/simspark.rsg') scene.importScene('rsg/agent/hoap2.rsg') # create an arena to test various joint bodies # scene = get($scenePath) #scene.importScene('rsg/jointtest/simspark.rsg') # source soccersim.rb to run the soccer simulation run "soccersim.rb" --- NEW FILE: bindings.rb --- # # bindings.rb sets up a mapping from input constants used by the # inputserver to application defined command constants. # inputServer = get('/sys/server/input'); if (inputServer == nil) print "(bindings.rb) no InputServer present\n"; else print "(bindings.rb) setting up bindings\n"; inputServer.bindCommand('axist', Command.Timer); inputServer.bindCommand('axisx', Command.MouseX); inputServer.bindCommand('axisy', Command.MouseY); inputServer.bindCommand('mouse_left', Command.Mouselook); inputServer.bindCommand('mouse_right',Command.Up); inputServer.bindCommand('pagedown', Command.Down); inputServer.bindCommand('kp_minus', Command.Down); inputServer.bindCommand('kp_plus',Command.Up); inputServer.bindCommand('pageup', Command.Up); inputServer.bindCommand('q', Command.Quit) inputServer.bindCommand('a', Command.Left) inputServer.bindCommand('left', Command.Left) inputServer.bindCommand('d', Command.Right) inputServer.bindCommand('right', Command.Right) inputServer.bindCommand('w', Command.Forward) inputServer.bindCommand('up', Command.Forward) inputServer.bindCommand('s', Command.Backward) inputServer.bindCommand('down', Command.Backward) end |