From: Markus R. <rol...@us...> - 2005-12-25 15:06:37
|
Update of /cvsroot/simspark/simspark/contrib/rsgedit In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3496/rsgedit Added Files: Makefile.am main.cpp main.h mainframe.cpp mainframe.h rsgedit.rb simspark.cpp simspark.h sparkglcanvas.cpp sparkglcanvas.h sparkglrender.cpp sparkglrender.h Log Message: - setup a build environment in simspark/contrib - primordial version of rsgedit added to cvs --- NEW FILE: main.cpp --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2003 Koblenz University $Id: main.cpp,v 1.1 2005/12/25 15:06:28 rollmark 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. */ #if defined(__GNUG__) && !defined(__APPLE__) #pragma implementation #pragma interface #endif // For compilers that support precompilation, includes "wx.h". #include "wx/wxprec.h" #ifdef __BORLANDC__ #pragma hdrstop #endif #ifndef WX_PRECOMP #include "wx/wx.h" #endif #if !wxUSE_GLCANVAS #error "OpenGL required: set wxUSE_GLCANVAS to 1 and rebuild the library" #endif #include "main.h" #include "mainframe.h" #include "sparkglcanvas.h" #include "simspark.h" IMPLEMENT_APP(RsgEditApp) using namespace boost; bool RsgEditApp::OnInit() { mSpark = shared_ptr<SimSpark>(new SimSpark("../../")); if (! mSpark->Init(argc, argv)) { return false; } MainFrame *frame = new MainFrame (NULL, "RSG-Edit", wxDefaultPosition,wxSize(400, 300)); wxMenu *winMenu = new wxMenu; winMenu->Append(wxID_EXIT, _T("&Close")); wxMenuBar *menuBar = new wxMenuBar; menuBar->Append(winMenu, _T("&Window")); frame->SetMenuBar(menuBar); frame->m_canvas = new SparkGLCanvas (frame, wxID_ANY, wxDefaultPosition, wxDefaultSize); // Show the frame frame->Show(true); SetTopWindow(frame); return true; } shared_ptr<SimSpark> RsgEditApp::GetSpark() { return mSpark; } --- NEW FILE: sparkglrender.h --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2003 Koblenz University $Id: sparkglrender.h,v 1.1 2005/12/25 15:06:28 rollmark 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. */ #ifndef SPARKGLRENDER_H__ #define SPARKGLRENDER_H__ #include <boost/shared_ptr.hpp> class SimSpark; namespace oxygen { class Camera; class SceneServer; } namespace kerosin { class RenderServer; } class SparkGLRender { public: SparkGLRender(); virtual ~SparkGLRender(); void Init(boost::shared_ptr<SimSpark> spark); void Render(int width, int height); void AdvanceTime(); protected: boost::shared_ptr<SimSpark> mSpark; boost::shared_ptr<oxygen::Camera> mCamera; boost::shared_ptr<oxygen::SceneServer> mSceneServer; boost::shared_ptr<kerosin::RenderServer> mRenderServer; }; #endif // SPARKGLRENDER_H__ --- NEW FILE: sparkglrender.cpp --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2003 Koblenz University $Id: sparkglrender.cpp,v 1.1 2005/12/25 15:06:28 rollmark 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. */ #include "sparkglrender.h" #include <zeitgeist/logserver/logserver.h> #include <oxygen/sceneserver/camera.h> #include <oxygen/sceneserver/sceneserver.h> #include <kerosin/renderserver/renderserver.h> #include "simspark.h" using namespace boost; using namespace zeitgeist; using namespace oxygen; using namespace kerosin; SparkGLRender::SparkGLRender() { } SparkGLRender::~SparkGLRender() { } void SparkGLRender::Init(shared_ptr<SimSpark> spark) { mCamera.reset(); mRenderServer.reset(); mSpark = spark; if (mSpark.get() == 0) { return; } mCamera = shared_dynamic_cast<Camera> (mSpark->GetCore()->Get("/usr/scene/camera/camera")); if (mCamera.get() == 0) { mSpark->GetLog()->Error() << "(SparkGLRender) ERROR: camera node not found\n"; } mRenderServer = shared_dynamic_cast<RenderServer> (mSpark->GetCore()->Get("/sys/server/render")); if (mRenderServer.get() == 0) { mSpark->GetLog()->Error() << "(SparkGLRender) ERROR: RenderServer not found\n"; } mSceneServer = shared_dynamic_cast<SceneServer> (mSpark->GetCore()->Get("/sys/server/scene")); if (mSceneServer.get() == 0) { mSpark->GetLog()->Error() << "(SparkGLRender) ERROR: SceneServer not found\n"; } } void SparkGLRender::Render(int width, int height) { if ( (mCamera.get() == 0) || (mRenderServer.get() == 0) ) { return; } mCamera->SetViewport(0,0,width,height); mRenderServer->Render(); } void SparkGLRender::AdvanceTime() { if (mSceneServer.get() == 0) { return; } mSceneServer->Update(0.1); } --- NEW FILE: sparkglcanvas.cpp --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2003 Koblenz University $Id: sparkglcanvas.cpp,v 1.1 2005/12/25 15:06:28 rollmark 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. */ #include <wx/dcclient.h> #include "main.h" #include "sparkglcanvas.h" BEGIN_EVENT_TABLE(SparkGLCanvas, wxGLCanvas) EVT_SIZE(SparkGLCanvas::OnSize) EVT_PAINT(SparkGLCanvas::OnPaint) EVT_ERASE_BACKGROUND(SparkGLCanvas::OnEraseBackground) EVT_ENTER_WINDOW( SparkGLCanvas::OnEnterWindow ) END_EVENT_TABLE() SparkGLCanvas::SparkGLCanvas(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, const wxString& name) : wxGLCanvas(parent, (wxGLCanvas*) NULL, id, pos, size, style|wxFULL_REPAINT_ON_RESIZE , name ) { mInit = false; } SparkGLCanvas::SparkGLCanvas(wxWindow *parent, const SparkGLCanvas *other, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, const wxString& name ) : wxGLCanvas(parent, other->GetContext(), id, pos, size, style|wxFULL_REPAINT_ON_RESIZE , name) { mInit = false; } SparkGLCanvas::~SparkGLCanvas() { } void SparkGLCanvas::Render() { wxPaintDC dc(this); #ifndef __WXMOTIF__ if (!GetContext()) return; #endif SetCurrent(); // Init OpenGL once, but after SetCurrent if (!mInit) { InitGL(); mInit = true; } int w, h; GetClientSize(&w, &h); mRender.Render(w,h); glFlush(); SwapBuffers(); } void SparkGLCanvas::OnPaint( wxPaintEvent& WXUNUSED(event) ) { Render(); } void SparkGLCanvas::OnSize(wxSizeEvent& event) { // this is also necessary to update the context on some platforms wxGLCanvas::OnSize(event); } void SparkGLCanvas::OnEraseBackground(wxEraseEvent& WXUNUSED(event)) { // Do nothing, to avoid flashing. } void SparkGLCanvas::OnEnterWindow( wxMouseEvent& WXUNUSED(event) ) { SetFocus(); } bool SparkGLCanvas::InitGL() { mRender.Init(wxGetApp().GetSpark()); return true; } void SparkGLCanvas::AdvanceTime() { mRender.AdvanceTime(); } --- NEW FILE: simspark.cpp --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2003 Koblenz University $Id: simspark.cpp,v 1.1 2005/12/25 15:06:28 rollmark 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. */ #include "simspark.h" #include <zeitgeist/scriptserver/scriptserver.h> #include <oxygen/simulationserver/simulationserver.h> using namespace std; using namespace boost; using namespace spark; SimSpark::SimSpark(const string& relPathPrefix) : Spark(relPathPrefix) { } 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("rsgedit.rb"); return true; } void SimSpark::PrintHelp() { } void SimSpark::PrintGreeting() { } bool SimSpark::ProcessCmdLine(int /*argc*/, char* /*argv*/[]) { return true; } --- NEW FILE: mainframe.h --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2003 Koblenz University $Id: mainframe.h,v 1.1 2005/12/25 15:06:28 rollmark 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. */ #ifndef MAINFRAME_H__ #define MAINFRAME_H__ #include <wx/frame.h> #include <wx/timer.h> class SparkGLCanvas; class MainFrame: public wxFrame { public: void OnExit(wxCommandEvent& event); void OnNewWindow(wxCommandEvent& event); MainFrame(wxWindow *parent, const wxString& title, const wxPoint& pos, const wxSize& size, long style = wxDEFAULT_FRAME_STYLE); protected: void OnTimer(wxTimerEvent& event); DECLARE_EVENT_TABLE() public: SparkGLCanvas* m_canvas; protected: wxTimer mTimer; }; #endif // MAINFRAME_H__ --- NEW FILE: rsgedit.rb --- # # rsgedit.rb # sparkSetupServer() # setup rendering using no OpenGLSystem- the wxWidgets GL canvas takes # care of OpenGL setup sparkSetupRendering('') # sparkSetupInput() # let spark create a default camera sparkAddFPSCamera( $scenePath+'camera', x = -5, y = -40, z = 2, 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.5,0.1,1.0) material.setAmbient(0.1,0.4,0.1,1.0) material = new('kerosin/MaterialSolid', $serverPath+'material/matGrey'); material.setDiffuse(0.1,0.1,0.1,1.0) # # uncomment any of the following to run a simulation # scene = get($scenePath) scene.importScene('rsg/boxspheres/simspark.rsg') # create an arena to test various joint bodies # scene = get($scenePath) # scene.importScene('rsg/jointtest/simspark.rsg') --- NEW FILE: mainframe.cpp --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2003 Koblenz University $Id: mainframe.cpp,v 1.1 2005/12/25 15:06:28 rollmark 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. */ #include "mainframe.h" #include "sparkglcanvas.h" BEGIN_EVENT_TABLE(MainFrame, wxFrame) EVT_MENU(wxID_EXIT, MainFrame::OnExit) EVT_TIMER(1, MainFrame::OnTimer) END_EVENT_TABLE() // My frame constructor MainFrame::MainFrame(wxWindow *parent, const wxString& title, const wxPoint& pos, const wxSize& size, long style) : wxFrame(parent, wxID_ANY, title, pos, size, style), mTimer(this,1) { m_canvas = NULL; mTimer.Start(100); } // Intercept menu commands void MainFrame::OnExit( wxCommandEvent& WXUNUSED(event) ) { // true is to force the frame to close Close(true); } void MainFrame::OnTimer(wxTimerEvent& /*event*/) { if (m_canvas == 0) { return; } m_canvas->AdvanceTime(); Refresh(); } --- NEW FILE: main.h --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2003 Koblenz University $Id: main.h,v 1.1 2005/12/25 15:06:28 rollmark 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. */ #ifndef MAIN_H__ #define MAIN_H__ #include <wx/glcanvas.h> #include <wx/app.h> #include <boost/shared_ptr.hpp> class SimSpark; class RsgEditApp: public wxApp { public: bool OnInit(); boost::shared_ptr<SimSpark> GetSpark(); protected: boost::shared_ptr<SimSpark> mSpark; }; DECLARE_APP(RsgEditApp) #endif // MAIN_H__ --- NEW FILE: sparkglcanvas.h --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2003 Koblenz University $Id: sparkglcanvas.h,v 1.1 2005/12/25 15:06:28 rollmark 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. */ #ifndef SPARKGLCANVAS_H__ #define SPARKGLCANVAS_H__ #include <wx/glcanvas.h> #include "sparkglrender.h" class SparkGLCanvas: public wxGLCanvas { public: SparkGLCanvas( wxWindow *parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = 0, const wxString& name = _T("SparkGLCanvas") ); SparkGLCanvas( wxWindow *parent, const SparkGLCanvas *other, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = 0, const wxString& name = _T("SparkGLCanvas") ); virtual ~SparkGLCanvas(); void OnPaint(wxPaintEvent& event); void OnSize(wxSizeEvent& event); void OnEraseBackground(wxEraseEvent& event); void OnEnterWindow(wxMouseEvent& event); void AdvanceTime(); void Render(); bool InitGL(); protected: bool mInit; SparkGLRender mRender; private: DECLARE_EVENT_TABLE() }; #endif // SPARKGLCANVAS_H__ --- NEW FILE: simspark.h --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2003 Koblenz University $Id: simspark.h,v 1.1 2005/12/25 15:06:28 rollmark 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. */ #ifndef SIMSPARK_H__ #define SIMSPARK_H__ #include <spark/spark.h> class SimSpark : public spark::Spark { public: SimSpark(const std::string& 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[]); }; #endif // SIMSPARK_H__ --- NEW FILE: Makefile.am --- bin_PROGRAMS = rsgedit AM_CPPFLAGS = -I${top_srcdir}\ @RUBY_CPPFLAGS@\ @WXWIDGETS_CPPFLAGS@\ @SALT_CPPFLAGS@\ @ZEITGEIST_CPPFLAGS@\ @OXYGEN_CPPFLAGS@\ @KEROSIN_CPPFLAGS@\ @SPARK_CPPFLAGS@ AM_LDFLAGS = @SPARK_LIBADD@\ @KEROSIN_LIBADD@\ @OXYGEN_LIBADD@\ @ZEITGEIST_LIBADD@\ @SALT_LIBADD@\ @WXWIDGETS_LIBADD@ rsgedit_SOURCES = \ main.cpp\ mainframe.cpp\ sparkglcanvas.cpp\ simspark.cpp\ sparkglrender.cpp |