diff options
author | Hans Lambermont <hans@lambermont.dyndns.org> | 2002-10-12 15:37:38 +0400 |
---|---|---|
committer | Hans Lambermont <hans@lambermont.dyndns.org> | 2002-10-12 15:37:38 +0400 |
commit | 12315f4d0e0ae993805f141f64cb8c73c5297311 (patch) | |
tree | 59b45827cd8293cfb727758989c7a74b40183974 /source/gameengine/BlenderRoutines |
Initial revisionv2.25
Diffstat (limited to 'source/gameengine/BlenderRoutines')
18 files changed, 2611 insertions, 0 deletions
diff --git a/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp b/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp new file mode 100644 index 00000000000..ba0c7fa3917 --- /dev/null +++ b/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp @@ -0,0 +1,374 @@ +/** + * $Id$ + * + * ***** BEGIN GPL/BL DUAL LICENSE BLOCK ***** + * + * 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; either version 2 + * of the License, or (at your option) any later version. The Blender + * Foundation also sells licenses for use in proprietary software under + * the Blender License. See http://www.blender.org/BL/ for information + * about this. + * + * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): none yet. + * + * ***** END GPL/BL DUAL LICENSE BLOCK ***** + * Blender's Ketsji startpoint + */ + +#ifdef WIN32 +// don't show stl-warnings +#pragma warning (disable:4786) +#endif + +#include "KX_BlenderGL.h" +#include "KX_BlenderCanvas.h" +#include "KX_BlenderKeyboardDevice.h" +#include "KX_BlenderMouseDevice.h" +#include "KX_BlenderRenderTools.h" +#include "KX_BlenderSystem.h" + +#include "KX_KetsjiEngine.h" +#include "KX_BlenderSceneConverter.h" +#include "KX_PythonInit.h" +#include "KX_PyConstraintBinding.h" + +#include "RAS_OpenGLRasterizer.h" +#include "RAS_CheckVertexArrays.h" + + +#ifdef WIN32 +#include "RAS_VAOpenGLRasterizer.h" +#endif + +#include "NG_LoopBackNetworkDeviceInterface.h" +#include "SND_DeviceManager.h" + +#include "SYS_System.h" + + /***/ + +#include "DNA_view3d_types.h" +#include "DNA_screen_types.h" +#include "BKE_global.h" +#include "BIF_screen.h" +#include "BIF_scrarea.h" + +#include "BKE_main.h" +#include "BLI_blenlib.h" +#include "BLO_readfile.h" +#include "DNA_scene_types.h" + /***/ + +static BlendFileData *load_game_data(char *filename) { + BlendReadError error; + BlendFileData *bfd= BLO_read_from_file(filename, &error); + + if (!bfd) { + printf("Loading %s failed: %s\n", filename, BLO_bre_as_string(error)); + } + + return bfd; +} + +extern "C" void StartKetsjiShell(struct ScrArea *area, + char* scenename, + struct Main* maggie, + int always_use_expand_framing) +{ + int exitrequested = KX_EXIT_REQUEST_NO_REQUEST; + Main* blenderdata = maggie; + char* startscenename = scenename; + char pathname[160]; + strcpy (pathname, maggie->name); + STR_String exitstring = ""; + BlendFileData *bfd= NULL; + + do + { + View3D *v3d= (View3D*) area->spacedata.first; + + // get some preferences + SYS_SystemHandle syshandle = SYS_GetSystem(); + bool properties = (SYS_GetCommandLineInt(syshandle, "show_properties", 0) != 0); + bool usefixed = (SYS_GetCommandLineInt(syshandle, "fixedtime", 0) != 0); + bool profile = (SYS_GetCommandLineInt(syshandle, "show_profile", 0) != 0); + bool frameRate = (SYS_GetCommandLineInt(syshandle, "show_framerate", 0) != 0); + + // create the canvas, rasterizer and rendertools + RAS_ICanvas* canvas = new KX_BlenderCanvas(area); + canvas->SetMouseState(RAS_ICanvas::MOUSE_INVISIBLE); + RAS_IRenderTools* rendertools = new KX_BlenderRenderTools(); + RAS_IRasterizer* rasterizer = NULL; + + // let's see if we want to use vertexarrays or not +#ifdef WIN32 + int usevta = SYS_GetCommandLineInt(syshandle,"vertexarrays",1); + bool useVertexArrays = (usevta > 0); + + if (useVertexArrays && RAS_SystemSupportsVertexArrays()) + rasterizer = new RAS_VAOpenGLRasterizer(canvas); + else + rasterizer = new RAS_OpenGLRasterizer(canvas); +#else + rasterizer = new RAS_OpenGLRasterizer(canvas); +#endif + + // create the inputdevices + KX_BlenderKeyboardDevice* keyboarddevice = new KX_BlenderKeyboardDevice(); + KX_BlenderMouseDevice* mousedevice = new KX_BlenderMouseDevice(); + + // create a networkdevice + NG_NetworkDeviceInterface* networkdevice = new + NG_LoopBackNetworkDeviceInterface(); + + // get an audiodevice + SND_DeviceManager::Subscribe(); + SND_IAudioDevice* audiodevice = SND_DeviceManager::Instance(); + audiodevice->UseCD(); + + // create a ketsji/blendersystem (only needed for timing and stuff) + KX_BlenderSystem* kxsystem = new KX_BlenderSystem(); + + // create the ketsjiengine + KX_KetsjiEngine* ketsjiengine = new KX_KetsjiEngine(kxsystem); + + // set the devices + ketsjiengine->SetKeyboardDevice(keyboarddevice); + ketsjiengine->SetMouseDevice(mousedevice); + ketsjiengine->SetNetworkDevice(networkdevice); + ketsjiengine->SetCanvas(canvas); + ketsjiengine->SetRenderTools(rendertools); + ketsjiengine->SetRasterizer(rasterizer); + ketsjiengine->SetNetworkDevice(networkdevice); + ketsjiengine->SetAudioDevice(audiodevice); + ketsjiengine->SetUseFixedTime(usefixed); + ketsjiengine->SetTimingDisplay(frameRate, profile, properties); + + // some blender stuff + MT_CmMatrix4x4 projmat; + MT_CmMatrix4x4 viewmat; + int i; + + for (i = 0; i < 16; i++) + { + float *viewmat_linear= (float*) v3d->viewmat; + viewmat.setElem(i, viewmat_linear[i]); + } + for (i = 0; i < 16; i++) + { + float *projmat_linear = (float*) area->winmat; + projmat.setElem(i, projmat_linear[i]); + } + + float camzoom = (1.41421 + (v3d->camzoom / 50.0)); + camzoom *= camzoom; + camzoom = 4.0 / camzoom; + + ketsjiengine->SetDrawType(v3d->drawtype); + ketsjiengine->SetCameraZoom(camzoom); + + // if we got an exitcode 3 (KX_EXIT_REQUEST_START_OTHER_GAME) load a different file + if (exitrequested == KX_EXIT_REQUEST_START_OTHER_GAME || exitrequested == KX_EXIT_REQUEST_RESTART_GAME) + { + exitrequested = KX_EXIT_REQUEST_NO_REQUEST; + if (bfd) BLO_blendfiledata_free(bfd); + + char basedpath[160]; + // base the actuator filename with respect + // to the original file working directory + if (exitstring != "") + strcpy(basedpath, exitstring.Ptr()); + + BLI_convertstringcode(basedpath, pathname, 0); + bfd = load_game_data(basedpath); + + // if it wasn't loaded, try it forced relative + if (!bfd) + { + // just add "//" in front of it + char temppath[162]; + strcpy(temppath, "//"); + strcat(temppath, basedpath); + + BLI_convertstringcode(temppath, pathname, 0); + bfd = load_game_data(temppath); + } + + // if we got a loaded blendfile, proceed + if (bfd) + { + blenderdata = bfd->main; + startscenename = bfd->curscene->id.name + 2; + } + // else forget it, we can't find it + else + { + exitrequested = KX_EXIT_REQUEST_QUIT_GAME; + } + } + + if (exitrequested != KX_EXIT_REQUEST_QUIT_GAME) + { + if (v3d->persp != 2) + { + ketsjiengine->EnableCameraOverride(startscenename); + ketsjiengine->SetCameraOverrideUseOrtho((v3d->persp == 0)); + ketsjiengine->SetCameraOverrideProjectionMatrix(projmat); + ketsjiengine->SetCameraOverrideViewMatrix(viewmat); + } + + // create a scene converter, create and convert the startingscene + KX_ISceneConverter* sceneconverter = new KX_BlenderSceneConverter(blenderdata, ketsjiengine); + ketsjiengine->SetSceneConverter(sceneconverter); + + if (always_use_expand_framing) + sceneconverter->SetAlwaysUseExpandFraming(true); + + + KX_Scene* startscene = new KX_Scene(keyboarddevice, + mousedevice, + networkdevice, + audiodevice, + startscenename); + + // some python things + PyObject* dictionaryobject = initGamePythonScripting("Ketsji", psl_Lowest); + ketsjiengine->SetPythonDictionary(dictionaryobject); + initRasterizer(rasterizer, canvas); + initGameLogic(startscene); + initGameKeys(); + initPythonConstraintBinding(); + + + if (sceneconverter) + { + // convert and add scene + sceneconverter->ConvertScene( + startscenename, + startscene, + dictionaryobject, + keyboarddevice, + rendertools, + canvas); + ketsjiengine->AddScene(startscene); + + // init the rasterizer + rasterizer->Init(); + + // start the engine + ketsjiengine->StartEngine(); + + // the mainloop + while (!exitrequested) + { + // first check if we want to exit + exitrequested = ketsjiengine->GetExitCode(); + + // kick the engine + ketsjiengine->NextFrame(); + + // render the frame + ketsjiengine->Render(); + + // test for the ESC key + while (qtest()) + { + short val; + unsigned short event = extern_qread(&val); + + if (keyboarddevice->ConvertBlenderEvent(event,val)) + exitrequested = KX_EXIT_REQUEST_BLENDER_ESC; + + /* Coordinate conversion... where + * should this really be? + */ + if (event==MOUSEX) { + val = val - scrarea_get_win_x(area); + } else if (event==MOUSEY) { + val = scrarea_get_win_height(area) - (val - scrarea_get_win_y(area)) - 1; + } + + mousedevice->ConvertBlenderEvent(event,val); + } + } + exitstring = ketsjiengine->GetExitString(); + + // when exiting the mainloop + exitGamePythonScripting(); + ketsjiengine->StopEngine(); + networkdevice->Disconnect(); + } + + if (sceneconverter) + { + delete sceneconverter; + sceneconverter = NULL; + } + } + // set the cursor back to normal + canvas->SetMouseState(RAS_ICanvas::MOUSE_NORMAL); + + // clean up some stuff + audiodevice->StopCD(); + SND_DeviceManager::Unsubscribe(); + + if (ketsjiengine) + { + delete ketsjiengine; + ketsjiengine = NULL; + } + if (kxsystem) + { + delete kxsystem; + kxsystem = NULL; + } + if (networkdevice) + { + delete networkdevice; + networkdevice = NULL; + } + if (keyboarddevice) + { + delete keyboarddevice; + keyboarddevice = NULL; + } + if (mousedevice) + { + delete mousedevice; + mousedevice = NULL; + } + if (rasterizer) + { + delete rasterizer; + rasterizer = NULL; + } + if (rendertools) + { + delete rendertools; + rendertools = NULL; + } + if (canvas) + { + delete canvas; + canvas = NULL; + } + } while (exitrequested == KX_EXIT_REQUEST_RESTART_GAME || exitrequested == KX_EXIT_REQUEST_START_OTHER_GAME); + + if (bfd) BLO_blendfiledata_free(bfd); +} diff --git a/source/gameengine/BlenderRoutines/KX_BlenderCanvas.cpp b/source/gameengine/BlenderRoutines/KX_BlenderCanvas.cpp new file mode 100644 index 00000000000..3dfae217453 --- /dev/null +++ b/source/gameengine/BlenderRoutines/KX_BlenderCanvas.cpp @@ -0,0 +1,164 @@ +/** + * $Id$ + * ***** BEGIN GPL/BL DUAL LICENSE BLOCK ***** + * + * 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; either version 2 + * of the License, or (at your option) any later version. The Blender + * Foundation also sells licenses for use in proprietary software under + * the Blender License. See http://www.blender.org/BL/ for information + * about this. + * + * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): none yet. + * + * ***** END GPL/BL DUAL LICENSE BLOCK ***** + */ + +#include "BIF_scrarea.h" + + +#include "KX_BlenderCanvas.h" + + +KX_BlenderCanvas::KX_BlenderCanvas(struct ScrArea *area) : +m_area(area) +{ +} + +KX_BlenderCanvas::~KX_BlenderCanvas() +{ +} + +void KX_BlenderCanvas::Init() +{ + glDepthFunc(GL_LEQUAL); +} + + +void KX_BlenderCanvas::SwapBuffers() +{ + BL_SwapBuffers(); +} + +void KX_BlenderCanvas::BeginFrame() +{ + glEnable(GL_DEPTH_TEST); + glDepthFunc(GL_LEQUAL); + +} + + +void KX_BlenderCanvas::EndFrame() +{ + // this is needed, else blender distorts a lot + glPopAttrib(); + glPushAttrib(GL_ALL_ATTRIB_BITS); + + glDisable(GL_FOG); +} + + + +void KX_BlenderCanvas::ClearColor(float r,float g,float b,float a) +{ + glClearColor(r,g,b,a); +} + + + +void KX_BlenderCanvas::ClearBuffer(int type) +{ + int ogltype = 0; + + if (type & RAS_ICanvas::COLOR_BUFFER ) + ogltype |= GL_COLOR_BUFFER_BIT; + + if (type & RAS_ICanvas::DEPTH_BUFFER ) + ogltype |= GL_DEPTH_BUFFER_BIT; + glClear(ogltype); +} + +int KX_BlenderCanvas::GetWidth( +) const { + return scrarea_get_win_width(m_area); +} + +int KX_BlenderCanvas::GetHeight( +) const { + return scrarea_get_win_height(m_area); +} + + void +KX_BlenderCanvas:: +SetViewPort( + int x1, int y1, + int x2, int y2 +){ + int vp_width = (x2 - x1) + 1; + int vp_height = (y2 - y1) + 1; + int minx = scrarea_get_win_x(m_area); + int miny = scrarea_get_win_y(m_area); + + glViewport(minx + x1, miny + y1, vp_width, vp_height); + glScissor(minx + x1, miny + y1, vp_width, vp_height); +} + + +void KX_BlenderCanvas::SetMouseState(RAS_MouseState mousestate) +{ + switch (mousestate) + { + case MOUSE_INVISIBLE: + { + BL_HideMouse(); + break; + } + case MOUSE_WAIT: + { + BL_WaitMouse(); + break; + } + case MOUSE_NORMAL: + { + BL_NormalMouse(); + break; + } + default: + { + } + } +} + + + +// (0,0) is top left, (width,height) is bottom right +void KX_BlenderCanvas::SetMousePosition(int x,int y) +{ + int winX = scrarea_get_win_x(m_area); + int winY = scrarea_get_win_y(m_area); + int winH = scrarea_get_win_height(m_area); + + BL_warp_pointer(winX + x, winY + (winH-y-1)); +} + + + +void KX_BlenderCanvas::MakeScreenShot(const char* filename) +{ + BL_MakeScreenShot(m_area, filename); +} diff --git a/source/gameengine/BlenderRoutines/KX_BlenderCanvas.h b/source/gameengine/BlenderRoutines/KX_BlenderCanvas.h new file mode 100644 index 00000000000..85b41e37f1d --- /dev/null +++ b/source/gameengine/BlenderRoutines/KX_BlenderCanvas.h @@ -0,0 +1,165 @@ +/** + * $Id$ + * + * ***** BEGIN GPL/BL DUAL LICENSE BLOCK ***** + * + * 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; either version 2 + * of the License, or (at your option) any later version. The Blender + * Foundation also sells licenses for use in proprietary software under + * the Blender License. See http://www.blender.org/BL/ for information + * about this. + * + * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): none yet. + * + * ***** END GPL/BL DUAL LICENSE BLOCK ***** + */ +#ifndef __KX_BLENDERCANVAS +#define __KX_BLENDERCANVAS + +#ifdef WIN32 +#include <windows.h> +#endif +#include <GL/gl.h> + +#include "RAS_ICanvas.h" +#include "RAS_Rect.h" + +#include "KX_BlenderGL.h" + +struct ScrArea; + +/** + * 2D Blender device context abstraction. + * The connection from 3d rendercontext to 2d Blender surface embedding. + */ + +class KX_BlenderCanvas : public RAS_ICanvas +{ +private: + /** Rect that defines the area used for rendering, + relative to the context */ + RAS_Rect m_displayarea; + +public: + /* Construct a new canvas. + * + * @param area The Blender ScrArea to run the game within. + */ + KX_BlenderCanvas(struct ScrArea* area); + ~KX_BlenderCanvas(); + + void + Init( + ); + + void + SwapBuffers( + ); + void + Resize( + int width, + int height + ); + + void + BeginFrame( + ); + + void + EndFrame( + ); + + void + ClearColor( + float r, + float g, + float b, + float a + ); + + void + ClearBuffer( + int type + ); + + int + GetWidth( + ) const ; + + int + GetHeight( + ) const ; + + const + RAS_Rect & + GetDisplayArea( + ) const { + return m_displayarea; + }; + + RAS_Rect & + GetDisplayArea( + ) { + return m_displayarea; + }; + + void + SetViewPort( + int x1, int y1, + int x2, int y2 + ); + + void + SetMouseState( + RAS_MouseState mousestate + ); + + void + SetMousePosition( + int x, + int y + ); + + void + MakeScreenShot( + const char* filename + ); + + /** + * Nothing needs be done for BlenderCanvas + * Begin/End Draw, as the game engine GL context + * is always current/active. + */ + + bool + BeginDraw( + ) { + return true; + }; + + void + EndDraw( + ) { + }; + +private: + /** Blender area the game engine is running within */ + struct ScrArea* m_area; +}; +#endif // __KX_BLENDERCANVAS diff --git a/source/gameengine/BlenderRoutines/KX_BlenderGL.cpp b/source/gameengine/BlenderRoutines/KX_BlenderGL.cpp new file mode 100644 index 00000000000..c2b4da62ece --- /dev/null +++ b/source/gameengine/BlenderRoutines/KX_BlenderGL.cpp @@ -0,0 +1,259 @@ +/** + * $Id$ + * ***** BEGIN GPL/BL DUAL LICENSE BLOCK ***** + * + * 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; either version 2 + * of the License, or (at your option) any later version. The Blender + * Foundation also sells licenses for use in proprietary software under + * the Blender License. See http://www.blender.org/BL/ for information + * about this. + * + * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): none yet. + * + * ***** END GPL/BL DUAL LICENSE BLOCK ***** + */ + +#include "KX_BlenderGL.h" + + +/* + * This little block needed for linking to Blender... + */ +#ifdef WIN32 +#include "BLI_winstuff.h" +#endif + +#include <stdlib.h> +#include <string.h> + +#include "BMF_Api.h" + + + +/* Data types encoding the game world: */ +#include "DNA_object_types.h" +#include "DNA_scene_types.h" +#include "DNA_screen_types.h" +#include "DNA_camera_types.h" +#include "DNA_world_types.h" +#include "DNA_mesh_types.h" +#include "DNA_image_types.h" +#include "DNA_view3d_types.h" +#include "DNA_material_types.h" + +#include "BKE_global.h" +#include "BKE_bmfont.h" + +#include "BIF_gl.h" +extern "C" { +#include "BDR_drawmesh.h" +#include "BIF_mywindow.h" +#include "BIF_toolbox.h" +#include "BIF_graphics.h" /* For CURSOR_NONE CURSOR_WAIT CURSOR_STD */ + +} + +/* end of blender block */ + + +#include <GL/gl.h> + + +void BL_warp_pointer(int x,int y) +{ + warp_pointer(x,y); +} + +void BL_SwapBuffers() +{ + myswapbuffers(); +} + +void BL_RenderText(int mode,const char* textstr,int textlen,struct TFace* tface, + float v1[3],float v2[3],float v3[3],float v4[3]) +{ + Image* ima; + + if(mode & TF_BMFONT) { + //char string[MAX_PROPSTRING]; + int characters, index, character; + float centerx, centery, sizex, sizey, transx, transy, movex, movey, advance; + +// bProperty *prop; + + // string = "Frank van Beek"; + + characters = textlen; + + ima = (struct Image*) tface->tpage; + if (ima == NULL) { + characters = 0; + } + + glPushMatrix(); + for (index = 0; index < characters; index++) { + // lets calculate offset stuff + character = textstr[index]; + + // space starts at offset 1 + // character = character - ' ' + 1; + + matrixGlyph(ima->ibuf, character, & centerx, ¢ery, &sizex, &sizey, &transx, &transy, &movex, &movey, &advance); + + glBegin(GL_POLYGON); + // printf(" %c %f %f %f %f\n", character, tface->uv[0][0], tface->uv[0][1], ); + // glTexCoord2f((tface->uv[0][0] - centerx) * sizex + transx, (tface->uv[0][1] - centery) * sizey + transy); + glTexCoord2f((tface->uv[0][0] - centerx) * sizex + transx, (tface->uv[0][1] - centery) * sizey + transy); + + spack(tface->col[0]); + // glVertex3fv(v1); + glVertex3f(sizex * v1[0] + movex, sizey * v1[1] + movey, v1[2]); + + glTexCoord2f((tface->uv[1][0] - centerx) * sizex + transx, (tface->uv[1][1] - centery) * sizey + transy); + spack(tface->col[1]); + // glVertex3fv(v2); + glVertex3f(sizex * v2[0] + movex, sizey * v2[1] + movey, v2[2]); + + glTexCoord2f((tface->uv[2][0] - centerx) * sizex + transx, (tface->uv[2][1] - centery) * sizey + transy); + spack(tface->col[2]); + // glVertex3fv(v3); + glVertex3f(sizex * v3[0] + movex, sizey * v3[1] + movey, v3[2]); + + if(v4) { + // glTexCoord2f((tface->uv[3][0] - centerx) * sizex + transx, 1.0 - (1.0 - tface->uv[3][1]) * sizey - transy); + glTexCoord2f((tface->uv[3][0] - centerx) * sizex + transx, (tface->uv[3][1] - centery) * sizey + transy); + spack(tface->col[3]); + // glVertex3fv(v4); + glVertex3f(sizex * v4[0] + movex, sizey * v4[1] + movey, v4[2]); + } + glEnd(); + + glTranslatef(advance, 0.0, 0.0); + } + glPopMatrix(); + + } +} + + +void BL_print_gamedebug_line(char* text, int xco, int yco, int width, int height) +{ + /* gl prepping */ + glDisable(GL_TEXTURE_2D); + + glMatrixMode(GL_PROJECTION); + glPushMatrix(); + glLoadIdentity(); + + glOrtho(0, width, + 0, height, 0, 1); + + glMatrixMode(GL_MODELVIEW); + glPushMatrix(); + glLoadIdentity(); + glMatrixMode(GL_TEXTURE); + glPushMatrix(); + glLoadIdentity(); + + /* the actual drawing */ + glColor3ub(255, 255, 255); + glRasterPos2s(xco, height-yco); + BMF_DrawString(G.fonts, text); + + glMatrixMode(GL_TEXTURE); + glPopMatrix(); + glMatrixMode(GL_PROJECTION); + glPopMatrix(); + glMatrixMode(GL_MODELVIEW); + glPopMatrix(); + glEnable(GL_DEPTH_TEST); +} + +void BL_print_gamedebug_line_padded(char* text, int xco, int yco, int width, int height) +{ + /* This is a rather important line :( The gl-mode hasn't been left + * behind quite as neatly as we'd have wanted to. I don't know + * what cause it, though :/ .*/ + glDisable(GL_TEXTURE_2D); + + glMatrixMode(GL_PROJECTION); + glPushMatrix(); + glLoadIdentity(); + + glOrtho(0, width, + 0, height, 0, 1); + + glMatrixMode(GL_MODELVIEW); + glPushMatrix(); + glLoadIdentity(); + glMatrixMode(GL_TEXTURE); + glPushMatrix(); + glLoadIdentity(); + + /* draw in black first*/ + glColor3ub(0, 0, 0); + glRasterPos2s(xco+1, height-yco-1); + BMF_DrawString(G.fonts, text); + glColor3ub(255, 255, 255); + glRasterPos2s(xco, height-yco); + BMF_DrawString(G.fonts, text); + + glMatrixMode(GL_TEXTURE); + glPopMatrix(); + glMatrixMode(GL_PROJECTION); + glPopMatrix(); + glMatrixMode(GL_MODELVIEW); + glPopMatrix(); + glEnable(GL_DEPTH_TEST); +} + +void BL_HideMouse() +{ + set_cursor(CURSOR_NONE); +} + + +void BL_WaitMouse() +{ + set_cursor(CURSOR_WAIT); +} + + +void BL_NormalMouse() +{ + set_cursor(CURSOR_STD); +} +#define MAX_FILE_LENGTH 512 + + +void BL_MakeScreenShot(struct ScrArea *area, const char* filename) +{ + char copyfilename[MAX_FILE_LENGTH]; + strcpy(copyfilename,filename); + + // filename read - only + + /* XXX will need to change at some point */ + BIF_screendump(); +/* BIF_screendump(area); */ + + // write+read filename + write_screendump((char*) copyfilename); +} + diff --git a/source/gameengine/BlenderRoutines/KX_BlenderGL.h b/source/gameengine/BlenderRoutines/KX_BlenderGL.h new file mode 100644 index 00000000000..c3648a21810 --- /dev/null +++ b/source/gameengine/BlenderRoutines/KX_BlenderGL.h @@ -0,0 +1,66 @@ +/** + * $Id$ + * + * ***** BEGIN GPL/BL DUAL LICENSE BLOCK ***** + * + * 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; either version 2 + * of the License, or (at your option) any later version. The Blender + * Foundation also sells licenses for use in proprietary software under + * the Blender License. See http://www.blender.org/BL/ for information + * about this. + * + * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): none yet. + * + * ***** END GPL/BL DUAL LICENSE BLOCK ***** + */ +#ifndef __BLENDERGL +#define __BLENDERGL + +#ifdef __cplusplus +extern "C" { +#endif //__cplusplus + +struct ScrArea; + +// special swapbuffers, that takes care of which area (viewport) needs to be swapped +void BL_SwapBuffers(); + +void BL_warp_pointer(int x,int y); + +void BL_MakeScreenShot(struct ScrArea *area, const char* filename); + +void BL_HideMouse(); +void BL_NormalMouse(); +void BL_WaitMouse(); + +void BL_RenderText(int mode,const char* textstr,int textlen,struct TFace* tface, + float v1[3],float v2[3],float v3[3],float v4[3]); + +void BL_print_gamedebug_line(char* text, int xco, int yco, int width, int height); +void BL_print_gamedebug_line_padded(char* text, int xco, int yco, int width, int height); + + + +#ifdef __cplusplus +} +#endif //__cplusplus + + +#endif //__BLENDERGL + diff --git a/source/gameengine/BlenderRoutines/KX_BlenderInputDevice.cpp b/source/gameengine/BlenderRoutines/KX_BlenderInputDevice.cpp new file mode 100644 index 00000000000..b364d4d40dd --- /dev/null +++ b/source/gameengine/BlenderRoutines/KX_BlenderInputDevice.cpp @@ -0,0 +1,32 @@ +/** + * $Id$ + * + * ***** BEGIN GPL/BL DUAL LICENSE BLOCK ***** + * + * 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; either version 2 + * of the License, or (at your option) any later version. The Blender + * Foundation also sells licenses for use in proprietary software under + * the Blender License. See http://www.blender.org/BL/ for information + * about this. + * + * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): none yet. + * + * ***** END GPL/BL DUAL LICENSE BLOCK ***** + */ +#include "KX_BlenderInputDevice.h" diff --git a/source/gameengine/BlenderRoutines/KX_BlenderInputDevice.h b/source/gameengine/BlenderRoutines/KX_BlenderInputDevice.h new file mode 100644 index 00000000000..7a2951838fc --- /dev/null +++ b/source/gameengine/BlenderRoutines/KX_BlenderInputDevice.h @@ -0,0 +1,220 @@ +/** + * $Id$ + * + * ***** BEGIN GPL/BL DUAL LICENSE BLOCK ***** + * + * 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; either version 2 + * of the License, or (at your option) any later version. The Blender + * Foundation also sells licenses for use in proprietary software under + * the Blender License. See http://www.blender.org/BL/ for information + * about this. + * + * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): none yet. + * + * ***** END GPL/BL DUAL LICENSE BLOCK ***** + */ +#ifndef __KX_BLENDERINPUTDEVICE +#define __KX_BLENDERINPUTDEVICE + +#ifdef WIN32 +#pragma warning(disable : 4786) // shut off 255 char limit debug template warning +#endif + +/* need to be here for conversion purposes */ +#include "mydevice.h" +#include "SCA_IInputDevice.h" + +#include <map> +/** + Base Class for Blender specific inputdevices. Blender specific inputdevices are used when the gameengine is running in embedded mode instead of standalone mode. +*/ +class BL_BlenderInputDevice : public SCA_IInputDevice +{ + // this map is Blender specific: a conversion between blender and ketsji enums + std::map<int,KX_EnumInputs> m_reverseKeyTranslateTable; +public: + BL_BlenderInputDevice() + { + + /* The reverse table. In order to not confuse ourselves, we */ + /* immediately convert all events that come in to KX codes. */ + m_reverseKeyTranslateTable[LEFTMOUSE ] = KX_LEFTMOUSE ; + m_reverseKeyTranslateTable[MIDDLEMOUSE ] = KX_MIDDLEMOUSE ; + m_reverseKeyTranslateTable[RIGHTMOUSE ] = KX_RIGHTMOUSE ; + m_reverseKeyTranslateTable[MOUSEX ] = KX_MOUSEX ; + m_reverseKeyTranslateTable[MOUSEY ] = KX_MOUSEY ; + + // TIMERS + + m_reverseKeyTranslateTable[TIMER0 ] = KX_TIMER0 ; + m_reverseKeyTranslateTable[TIMER1 ] = KX_TIMER1 ; + m_reverseKeyTranslateTable[TIMER2 ] = KX_TIMER2 ; + m_reverseKeyTranslateTable[TIMER3 ] = KX_TIMER3 ; + + // SYSTEM + + m_reverseKeyTranslateTable[KEYBD ] = KX_KEYBD ; + m_reverseKeyTranslateTable[RAWKEYBD ] = KX_RAWKEYBD ; + m_reverseKeyTranslateTable[REDRAW ] = KX_REDRAW ; + m_reverseKeyTranslateTable[INPUTCHANGE ] = KX_INPUTCHANGE ; + m_reverseKeyTranslateTable[QFULL ] = KX_QFULL ; + m_reverseKeyTranslateTable[WINFREEZE ] = KX_WINFREEZE ; + m_reverseKeyTranslateTable[WINTHAW ] = KX_WINTHAW ; + m_reverseKeyTranslateTable[WINCLOSE ] = KX_WINCLOSE ; + m_reverseKeyTranslateTable[WINQUIT ] = KX_WINQUIT ; + m_reverseKeyTranslateTable[Q_FIRSTTIME ] = KX_Q_FIRSTTIME ; + + // standard keyboard + + m_reverseKeyTranslateTable[AKEY ] = KX_AKEY ; + m_reverseKeyTranslateTable[BKEY ] = KX_BKEY ; + m_reverseKeyTranslateTable[CKEY ] = KX_CKEY ; + m_reverseKeyTranslateTable[DKEY ] = KX_DKEY ; + m_reverseKeyTranslateTable[EKEY ] = KX_EKEY ; + m_reverseKeyTranslateTable[FKEY ] = KX_FKEY ; + m_reverseKeyTranslateTable[GKEY ] = KX_GKEY ; + m_reverseKeyTranslateTable[HKEY ] = KX_HKEY ; + m_reverseKeyTranslateTable[IKEY ] = KX_IKEY ; + m_reverseKeyTranslateTable[JKEY ] = KX_JKEY ; + m_reverseKeyTranslateTable[KKEY ] = KX_KKEY ; + m_reverseKeyTranslateTable[LKEY ] = KX_LKEY ; + m_reverseKeyTranslateTable[MKEY ] = KX_MKEY ; + m_reverseKeyTranslateTable[NKEY ] = KX_NKEY ; + m_reverseKeyTranslateTable[OKEY ] = KX_OKEY ; + m_reverseKeyTranslateTable[PKEY ] = KX_PKEY ; + m_reverseKeyTranslateTable[QKEY ] = KX_QKEY ; + m_reverseKeyTranslateTable[RKEY ] = KX_RKEY ; + m_reverseKeyTranslateTable[SKEY ] = KX_SKEY ; + m_reverseKeyTranslateTable[TKEY ] = KX_TKEY ; + m_reverseKeyTranslateTable[UKEY ] = KX_UKEY ; + m_reverseKeyTranslateTable[VKEY ] = KX_VKEY ; + m_reverseKeyTranslateTable[WKEY ] = KX_WKEY ; + m_reverseKeyTranslateTable[XKEY ] = KX_XKEY ; + m_reverseKeyTranslateTable[YKEY ] = KX_YKEY ; + m_reverseKeyTranslateTable[ZKEY ] = KX_ZKEY ; + + m_reverseKeyTranslateTable[ZEROKEY ] = KX_ZEROKEY ; + m_reverseKeyTranslateTable[ONEKEY ] = KX_ONEKEY ; + m_reverseKeyTranslateTable[TWOKEY ] = KX_TWOKEY ; + m_reverseKeyTranslateTable[THREEKEY ] = KX_THREEKEY ; + m_reverseKeyTranslateTable[FOURKEY ] = KX_FOURKEY ; + m_reverseKeyTranslateTable[FIVEKEY ] = KX_FIVEKEY ; + m_reverseKeyTranslateTable[SIXKEY ] = KX_SIXKEY ; + m_reverseKeyTranslateTable[SEVENKEY ] = KX_SEVENKEY ; + m_reverseKeyTranslateTable[EIGHTKEY ] = KX_EIGHTKEY ; + m_reverseKeyTranslateTable[NINEKEY ] = KX_NINEKEY ; + + m_reverseKeyTranslateTable[CAPSLOCKKEY ] = KX_CAPSLOCKKEY ; + + m_reverseKeyTranslateTable[LEFTCTRLKEY ] = KX_LEFTCTRLKEY ; + m_reverseKeyTranslateTable[LEFTALTKEY ] = KX_LEFTALTKEY ; + m_reverseKeyTranslateTable[RIGHTALTKEY ] = KX_RIGHTALTKEY ; + m_reverseKeyTranslateTable[RIGHTCTRLKEY ] = KX_RIGHTCTRLKEY ; + m_reverseKeyTranslateTable[RIGHTSHIFTKEY ] = KX_RIGHTSHIFTKEY ; + m_reverseKeyTranslateTable[LEFTSHIFTKEY ] = KX_LEFTSHIFTKEY ; + + m_reverseKeyTranslateTable[ESCKEY ] = KX_ESCKEY ; + m_reverseKeyTranslateTable[TABKEY ] = KX_TABKEY ; + m_reverseKeyTranslateTable[RETKEY ] = KX_RETKEY ; + m_reverseKeyTranslateTable[SPACEKEY ] = KX_SPACEKEY ; + m_reverseKeyTranslateTable[LINEFEEDKEY ] = KX_LINEFEEDKEY ; + m_reverseKeyTranslateTable[BACKSPACEKEY ] = KX_BACKSPACEKEY ; + m_reverseKeyTranslateTable[DELKEY ] = KX_DELKEY ; + m_reverseKeyTranslateTable[SEMICOLONKEY ] = KX_SEMICOLONKEY ; + m_reverseKeyTranslateTable[PERIODKEY ] = KX_PERIODKEY ; + m_reverseKeyTranslateTable[COMMAKEY ] = KX_COMMAKEY ; + m_reverseKeyTranslateTable[QUOTEKEY ] = KX_QUOTEKEY ; + m_reverseKeyTranslateTable[ACCENTGRAVEKEY ] = KX_ACCENTGRAVEKEY ; + m_reverseKeyTranslateTable[MINUSKEY ] = KX_MINUSKEY ; + m_reverseKeyTranslateTable[SLASHKEY ] = KX_SLASHKEY ; + m_reverseKeyTranslateTable[BACKSLASHKEY ] = KX_BACKSLASHKEY ; + m_reverseKeyTranslateTable[EQUALKEY ] = KX_EQUALKEY ; + m_reverseKeyTranslateTable[LEFTBRACKETKEY ] = KX_LEFTBRACKETKEY ; + m_reverseKeyTranslateTable[RIGHTBRACKETKEY ] = KX_RIGHTBRACKETKEY ; + + m_reverseKeyTranslateTable[LEFTARROWKEY ] = KX_LEFTARROWKEY ; + m_reverseKeyTranslateTable[DOWNARROWKEY ] = KX_DOWNARROWKEY ; + m_reverseKeyTranslateTable[RIGHTARROWKEY ] = KX_RIGHTARROWKEY ; + m_reverseKeyTranslateTable[UPARROWKEY ] = KX_UPARROWKEY ; + + m_reverseKeyTranslateTable[PAD2 ] = KX_PAD2 ; + m_reverseKeyTranslateTable[PAD4 ] = KX_PAD4 ; + m_reverseKeyTranslateTable[PAD6 ] = KX_PAD6 ; + m_reverseKeyTranslateTable[PAD8 ] = KX_PAD8 ; + + m_reverseKeyTranslateTable[PAD1 ] = KX_PAD1 ; + m_reverseKeyTranslateTable[PAD3 ] = KX_PAD3 ; + m_reverseKeyTranslateTable[PAD5 ] = KX_PAD5 ; + m_reverseKeyTranslateTable[PAD7 ] = KX_PAD7 ; + m_reverseKeyTranslateTable[PAD9 ] = KX_PAD9 ; + + m_reverseKeyTranslateTable[PADPERIOD ] = KX_PADPERIOD ; + m_reverseKeyTranslateTable[PADSLASHKEY ] = KX_PADSLASHKEY ; + m_reverseKeyTranslateTable[PADASTERKEY ] = KX_PADASTERKEY ; + + + m_reverseKeyTranslateTable[PAD0 ] = KX_PAD0 ; + m_reverseKeyTranslateTable[PADMINUS ] = KX_PADMINUS ; + m_reverseKeyTranslateTable[PADENTER ] = KX_PADENTER ; + m_reverseKeyTranslateTable[PADPLUSKEY ] = KX_PADPLUSKEY ; + + + m_reverseKeyTranslateTable[F1KEY ] = KX_F1KEY ; + m_reverseKeyTranslateTable[F2KEY ] = KX_F2KEY ; + m_reverseKeyTranslateTable[F3KEY ] = KX_F3KEY ; + m_reverseKeyTranslateTable[F4KEY ] = KX_F4KEY ; + m_reverseKeyTranslateTable[F5KEY ] = KX_F5KEY ; + m_reverseKeyTranslateTable[F6KEY ] = KX_F6KEY ; + m_reverseKeyTranslateTable[F7KEY ] = KX_F7KEY ; + m_reverseKeyTranslateTable[F8KEY ] = KX_F8KEY ; + m_reverseKeyTranslateTable[F9KEY ] = KX_F9KEY ; + m_reverseKeyTranslateTable[F10KEY ] = KX_F10KEY ; + m_reverseKeyTranslateTable[F11KEY ] = KX_F11KEY ; + m_reverseKeyTranslateTable[F12KEY ] = KX_F12KEY ; + + m_reverseKeyTranslateTable[PAUSEKEY ] = KX_PAUSEKEY ; + m_reverseKeyTranslateTable[INSERTKEY ] = KX_INSERTKEY ; + m_reverseKeyTranslateTable[HOMEKEY ] = KX_HOMEKEY ; + m_reverseKeyTranslateTable[PAGEUPKEY ] = KX_PAGEUPKEY ; + m_reverseKeyTranslateTable[PAGEDOWNKEY ] = KX_PAGEDOWNKEY ; + m_reverseKeyTranslateTable[ENDKEY ] = KX_ENDKEY ; + + + } + + virtual ~BL_BlenderInputDevice() + { + + } + + KX_EnumInputs ToNative(unsigned short incode) { + return m_reverseKeyTranslateTable[incode]; + } + + virtual bool IsPressed(SCA_IInputDevice::KX_EnumInputs inputcode)=0; +// virtual const SCA_InputEvent& GetEventValue(SCA_IInputDevice::KX_EnumInputs inputcode)=0; + virtual bool ConvertBlenderEvent(unsigned short incode,short val)=0; + +}; + + + + + +#endif //__KX_BLENDERINPUTDEVICE diff --git a/source/gameengine/BlenderRoutines/KX_BlenderKeyboardDevice.cpp b/source/gameengine/BlenderRoutines/KX_BlenderKeyboardDevice.cpp new file mode 100644 index 00000000000..81f233d6433 --- /dev/null +++ b/source/gameengine/BlenderRoutines/KX_BlenderKeyboardDevice.cpp @@ -0,0 +1,161 @@ +/** + * $Id$ + * ***** BEGIN GPL/BL DUAL LICENSE BLOCK ***** + * + * 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; either version 2 + * of the License, or (at your option) any later version. The Blender + * Foundation also sells licenses for use in proprietary software under + * the Blender License. See http://www.blender.org/BL/ for information + * about this. + * + * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): none yet. + * + * ***** END GPL/BL DUAL LICENSE BLOCK ***** + */ + + +#ifdef WIN32 +// annoying warnings about truncated STL debug info +#pragma warning (disable :4786) +#endif + +#include "KX_BlenderKeyboardDevice.h" + +KX_BlenderKeyboardDevice::KX_BlenderKeyboardDevice() +{ + +} +KX_BlenderKeyboardDevice::~KX_BlenderKeyboardDevice() +{ + +} + +/** + IsPressed gives boolean information about keyboard status, true if pressed, false if not +*/ + +bool KX_BlenderKeyboardDevice::IsPressed(SCA_IInputDevice::KX_EnumInputs inputcode) +{ + const SCA_InputEvent & inevent = m_eventStatusTables[m_currentTable][inputcode]; + bool pressed = (inevent.m_status == SCA_InputEvent::KX_JUSTACTIVATED || + inevent.m_status == SCA_InputEvent::KX_ACTIVE); + return pressed; +} +/*const SCA_InputEvent& KX_BlenderKeyboardDevice::GetEventValue(SCA_IInputDevice::KX_EnumInputs inputcode) +{ + return m_eventStatusTables[m_currentTable][inputcode]; +} +*/ +/** + NextFrame toggles currentTable with previousTable, + and copy relevant event information from previous to current + (pressed keys need to be remembered) +*/ +void KX_BlenderKeyboardDevice::NextFrame() +{ + SCA_IInputDevice::NextFrame(); + + // now convert justpressed keyevents into regular (active) keyevents + int previousTable = 1-m_currentTable; + for (int keyevent= KX_BEGINKEY; keyevent< KX_ENDKEY;keyevent++) + { + SCA_InputEvent& oldevent = m_eventStatusTables[previousTable][keyevent]; + if (oldevent.m_status == SCA_InputEvent::KX_JUSTACTIVATED || + oldevent.m_status == SCA_InputEvent::KX_ACTIVE ) + { + m_eventStatusTables[m_currentTable][keyevent] = oldevent; + m_eventStatusTables[m_currentTable][keyevent].m_status = SCA_InputEvent::KX_ACTIVE; + } + } +} + +/** + ConvertBlenderEvent translates blender keyboard events into ketsji kbd events + extra event information is stored, like ramp-mode (just released/pressed) +*/ + + +bool KX_BlenderKeyboardDevice::ConvertBlenderEvent(unsigned short incode,short val) +{ + bool result = false; + + // convert event + KX_EnumInputs kxevent = this->ToNative(incode); + + // only process it, if it's a key + if (kxevent >= KX_BEGINKEY && kxevent < KX_ENDKEY) + { + int previousTable = 1-m_currentTable; + + if (val > 0) + { + if (kxevent == SCA_IInputDevice::KX_ESCKEY && val != 0) + result = true; + + // todo: convert val ?? + m_eventStatusTables[m_currentTable][kxevent].m_eventval = val ; //??? + + switch (m_eventStatusTables[previousTable][kxevent].m_status) + { + case SCA_InputEvent::KX_JUSTACTIVATED: + { + m_eventStatusTables[m_currentTable][kxevent].m_status = SCA_InputEvent::KX_ACTIVE; + break; + } + case SCA_InputEvent::KX_ACTIVE: + + { + m_eventStatusTables[m_currentTable][kxevent].m_status = SCA_InputEvent::KX_ACTIVE; + break; + } + case SCA_InputEvent::KX_NO_INPUTSTATUS: + { + m_eventStatusTables[m_currentTable][kxevent].m_status = SCA_InputEvent::KX_JUSTACTIVATED; + break; + } + default: + { + m_eventStatusTables[m_currentTable][kxevent].m_status = SCA_InputEvent::KX_JUSTACTIVATED; + } + } + + } else + { + // blender eventval == 0 + switch (m_eventStatusTables[previousTable][kxevent].m_status) + { + case SCA_InputEvent::KX_JUSTACTIVATED: + { + m_eventStatusTables[m_currentTable][kxevent].m_status = SCA_InputEvent::KX_JUSTRELEASED; + break; + } + case SCA_InputEvent::KX_ACTIVE: + { + m_eventStatusTables[m_currentTable][kxevent].m_status = SCA_InputEvent::KX_JUSTRELEASED; + break; + } + default: + { + m_eventStatusTables[m_currentTable][kxevent].m_status = SCA_InputEvent::KX_NO_INPUTSTATUS; + } + } + } + } + return result; +} diff --git a/source/gameengine/BlenderRoutines/KX_BlenderKeyboardDevice.h b/source/gameengine/BlenderRoutines/KX_BlenderKeyboardDevice.h new file mode 100644 index 00000000000..98791dba95b --- /dev/null +++ b/source/gameengine/BlenderRoutines/KX_BlenderKeyboardDevice.h @@ -0,0 +1,48 @@ +/** + * $Id$ + * + * ***** BEGIN GPL/BL DUAL LICENSE BLOCK ***** + * + * 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; either version 2 + * of the License, or (at your option) any later version. The Blender + * Foundation also sells licenses for use in proprietary software under + * the Blender License. See http://www.blender.org/BL/ for information + * about this. + * + * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): none yet. + * + * ***** END GPL/BL DUAL LICENSE BLOCK ***** + */ +#ifndef __KX_BLENDERKEYBOARDDEVICE +#define __KX_BLENDERKEYBOARDDEVICE + +#include "KX_BlenderInputDevice.h" + +class KX_BlenderKeyboardDevice : public BL_BlenderInputDevice +{ +public: + KX_BlenderKeyboardDevice(); + virtual ~KX_BlenderKeyboardDevice(); + + virtual bool IsPressed(SCA_IInputDevice::KX_EnumInputs inputcode); +// virtual const SCA_InputEvent& GetEventValue(SCA_IInputDevice::KX_EnumInputs inputcode); + virtual bool ConvertBlenderEvent(unsigned short incode,short val); + virtual void NextFrame(); +}; +#endif //__KX_BLENDERKEYBOARDDEVICE diff --git a/source/gameengine/BlenderRoutines/KX_BlenderMouseDevice.cpp b/source/gameengine/BlenderRoutines/KX_BlenderMouseDevice.cpp new file mode 100644 index 00000000000..e3d4f36cc26 --- /dev/null +++ b/source/gameengine/BlenderRoutines/KX_BlenderMouseDevice.cpp @@ -0,0 +1,177 @@ +/** + * $Id$ + * ***** BEGIN GPL/BL DUAL LICENSE BLOCK ***** + * + * 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; either version 2 + * of the License, or (at your option) any later version. The Blender + * Foundation also sells licenses for use in proprietary software under + * the Blender License. See http://www.blender.org/BL/ for information + * about this. + * + * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): none yet. + * + * ***** END GPL/BL DUAL LICENSE BLOCK ***** + */ + + +#ifdef WIN32 +// annoying warnings about truncated STL debug info +#pragma warning (disable :4786) +#endif + +#include "KX_BlenderMouseDevice.h" + +KX_BlenderMouseDevice::KX_BlenderMouseDevice() +{ + +} +KX_BlenderMouseDevice::~KX_BlenderMouseDevice() +{ + +} + +/** + IsPressed gives boolean information about mouse status, true if pressed, false if not +*/ + +bool KX_BlenderMouseDevice::IsPressed(SCA_IInputDevice::KX_EnumInputs inputcode) +{ + const SCA_InputEvent & inevent = m_eventStatusTables[m_currentTable][inputcode]; + bool pressed = (inevent.m_status == SCA_InputEvent::KX_JUSTACTIVATED || + inevent.m_status == SCA_InputEvent::KX_ACTIVE); + return pressed; +} +/*const SCA_InputEvent& KX_BlenderMouseDevice::GetEventValue(SCA_IInputDevice::KX_EnumInputs inputcode) +{ + return m_eventStatusTables[m_currentTable][inputcode]; +} +*/ + +/** + NextFrame toggles currentTable with previousTable, + and copy relevant event information from previous to current + (pressed keys need to be remembered) +*/ +void KX_BlenderMouseDevice::NextFrame() +{ + SCA_IInputDevice::NextFrame(); + + // now convert justpressed keyevents into regular (active) keyevents + int previousTable = 1-m_currentTable; + for (int mouseevent= KX_BEGINMOUSE; mouseevent< KX_ENDMOUSEBUTTONS;mouseevent++) + { + SCA_InputEvent& oldevent = m_eventStatusTables[previousTable][mouseevent]; + if (oldevent.m_status == SCA_InputEvent::KX_JUSTACTIVATED || + oldevent.m_status == SCA_InputEvent::KX_ACTIVE ) + { + m_eventStatusTables[m_currentTable][mouseevent] = oldevent; + m_eventStatusTables[m_currentTable][mouseevent].m_status = SCA_InputEvent::KX_ACTIVE; + } + } + for (int mousemove= KX_ENDMOUSEBUTTONS; mousemove< KX_ENDMOUSE;mousemove++) + { + SCA_InputEvent& oldevent = m_eventStatusTables[previousTable][mousemove]; + m_eventStatusTables[m_currentTable][mousemove] = oldevent; + if (oldevent.m_status == SCA_InputEvent::KX_JUSTACTIVATED || + oldevent.m_status == SCA_InputEvent::KX_ACTIVE ) + { + + m_eventStatusTables[m_currentTable][mousemove].m_status = SCA_InputEvent::KX_JUSTRELEASED; + } else + { + if (oldevent.m_status == SCA_InputEvent::KX_JUSTRELEASED) + { + + m_eventStatusTables[m_currentTable][mousemove].m_status = SCA_InputEvent::KX_NO_INPUTSTATUS ; + } + } + } +} + + +/** + ConvertBlenderEvent translates blender mouse events into ketsji kbd events + extra event information is stored, like ramp-mode (just released/pressed) +*/ + + +bool KX_BlenderMouseDevice::ConvertBlenderEvent(unsigned short incode,short val) +{ + bool result = false; + + // convert event + KX_EnumInputs kxevent = this->ToNative(incode); + + // only process it, if it's a key + if (kxevent > KX_BEGINMOUSE && kxevent < KX_ENDMOUSE) + { + int previousTable = 1-m_currentTable; + + + if (val > 0) + { + m_eventStatusTables[m_currentTable][kxevent].m_eventval = val ; //??? + + switch (m_eventStatusTables[previousTable][kxevent].m_status) + { + + case SCA_InputEvent::KX_ACTIVE: + case SCA_InputEvent::KX_JUSTACTIVATED: + { + m_eventStatusTables[m_currentTable][kxevent].m_status = SCA_InputEvent::KX_ACTIVE; + break; + } + case SCA_InputEvent::KX_JUSTRELEASED: + { + if ( kxevent > KX_BEGINMOUSEBUTTONS && kxevent < KX_ENDMOUSEBUTTONS) + { + m_eventStatusTables[m_currentTable][kxevent].m_status = SCA_InputEvent::KX_JUSTACTIVATED; + } else + { + m_eventStatusTables[m_currentTable][kxevent].m_status = SCA_InputEvent::KX_ACTIVE; + + } + break; + } + default: + { + m_eventStatusTables[m_currentTable][kxevent].m_status = SCA_InputEvent::KX_JUSTACTIVATED; + } + } + + } else + { + // blender eventval == 0 + switch (m_eventStatusTables[previousTable][kxevent].m_status) + { + case SCA_InputEvent::KX_JUSTACTIVATED: + case SCA_InputEvent::KX_ACTIVE: + { + m_eventStatusTables[m_currentTable][kxevent].m_status = SCA_InputEvent::KX_JUSTRELEASED; + break; + } + default: + { + m_eventStatusTables[m_currentTable][kxevent].m_status = SCA_InputEvent::KX_NO_INPUTSTATUS; + } + } + } + } + return result; +} diff --git a/source/gameengine/BlenderRoutines/KX_BlenderMouseDevice.h b/source/gameengine/BlenderRoutines/KX_BlenderMouseDevice.h new file mode 100644 index 00000000000..6eb02622f9b --- /dev/null +++ b/source/gameengine/BlenderRoutines/KX_BlenderMouseDevice.h @@ -0,0 +1,48 @@ +/** + * $Id$ + * + * ***** BEGIN GPL/BL DUAL LICENSE BLOCK ***** + * + * 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; either version 2 + * of the License, or (at your option) any later version. The Blender + * Foundation also sells licenses for use in proprietary software under + * the Blender License. See http://www.blender.org/BL/ for information + * about this. + * + * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): none yet. + * + * ***** END GPL/BL DUAL LICENSE BLOCK ***** + */ +#ifndef __KX_BLENDERMOUSEDEVICE +#define __KX_BLENDERMOUSEDEVICE + +#include "KX_BlenderInputDevice.h" + +class KX_BlenderMouseDevice : public BL_BlenderInputDevice +{ +public: + KX_BlenderMouseDevice(); + virtual ~KX_BlenderMouseDevice(); + + virtual bool IsPressed(SCA_IInputDevice::KX_EnumInputs inputcode); +// virtual const SCA_InputEvent& GetEventValue(SCA_IInputDevice::KX_EnumInputs inputcode); + virtual bool ConvertBlenderEvent(unsigned short incode,short val); + virtual void NextFrame(); +}; +#endif //__KX_BLENDERMOUSEDEVICE diff --git a/source/gameengine/BlenderRoutines/KX_BlenderPolyMaterial.cpp b/source/gameengine/BlenderRoutines/KX_BlenderPolyMaterial.cpp new file mode 100644 index 00000000000..fc7eb3a6c7f --- /dev/null +++ b/source/gameengine/BlenderRoutines/KX_BlenderPolyMaterial.cpp @@ -0,0 +1,106 @@ +/** + * $Id$ + * ***** BEGIN GPL/BL DUAL LICENSE BLOCK ***** + * + * 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; either version 2 + * of the License, or (at your option) any later version. The Blender + * Foundation also sells licenses for use in proprietary software under + * the Blender License. See http://www.blender.org/BL/ for information + * about this. + * + * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): none yet. + * + * ***** END GPL/BL DUAL LICENSE BLOCK ***** + */ + + +#include "KX_BlenderPolyMaterial.h" +#include "BKE_mesh.h" + +KX_BlenderPolyMaterial::KX_BlenderPolyMaterial(const STR_String &texname, + bool ba, + const STR_String& matname, + int tile, + int tilexrep, + int tileyrep, + int mode, + int transparant, + int lightlayer, + bool bIsTriangle, + void* clientobject, + struct TFace* tface) + : RAS_IPolyMaterial(texname, + false, + matname, + tile, + tilexrep, + tileyrep, + mode, + transparant, + lightlayer, + bIsTriangle, + clientobject), + m_tface(tface) +{ +} + + +void KX_BlenderPolyMaterial::Activate(RAS_IRasterizer* rasty, TCachingInfo& cachingInfo) const +{ + + + if (GetCachingInfo() != cachingInfo) + { + if (!cachingInfo) + { + set_tpage(NULL); + } + cachingInfo = GetCachingInfo(); + + if ((m_drawingmode & 4)&& (rasty->GetDrawingMode() == RAS_IRasterizer::KX_TEXTURED)) + { + update_realtime_texture((struct TFace*) m_tface, rasty->GetTime()); + set_tpage(m_tface); + rasty->EnableTextures(true); + } + else + { + set_tpage(NULL); + rasty->EnableTextures(false); + } + + //TF_TWOSIDE == 512, todo, make this a ketsji enum + if(m_drawingmode & 512) + { + rasty->SetCullFace(false); + } + else + { + rasty->SetCullFace(true); + } + } + + rasty->SetSpecularity(m_specular[0],m_specular[1],m_specular[2],m_specularity); + rasty->SetShinyness(m_shininess); + rasty->SetDiffuse(m_diffuse[0], m_diffuse[1],m_diffuse[2], 1.0); +} + + + + diff --git a/source/gameengine/BlenderRoutines/KX_BlenderPolyMaterial.h b/source/gameengine/BlenderRoutines/KX_BlenderPolyMaterial.h new file mode 100644 index 00000000000..3513765410f --- /dev/null +++ b/source/gameengine/BlenderRoutines/KX_BlenderPolyMaterial.h @@ -0,0 +1,98 @@ +/** + * $Id$ + * + * ***** BEGIN GPL/BL DUAL LICENSE BLOCK ***** + * + * 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; either version 2 + * of the License, or (at your option) any later version. The Blender + * Foundation also sells licenses for use in proprietary software under + * the Blender License. See http://www.blender.org/BL/ for information + * about this. + * + * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): none yet. + * + * ***** END GPL/BL DUAL LICENSE BLOCK ***** + */ +#ifndef __KX_BLENDERPOLYMATERIAL +#define __KX_BLENDERPOLYMATERIAL + +#include "RAS_MaterialBucket.h" +#include "RAS_IRasterizer.h" + +struct TFace; +extern "C" int set_tpage(TFace* tface); /* Worst hack ever */ + + +class KX_BlenderPolyMaterial : public RAS_IPolyMaterial +{ + /** Blender texture face structure. */ + TFace* m_tface; + +public: + + KX_BlenderPolyMaterial(const STR_String &texname, + bool ba, + const STR_String& matname, + int tile, + int tilexrep, + int tileyrep, + int mode, + int transparant, + int lightlayer, + bool bIsTriangle, + void* clientobject, + struct TFace* tface); + + /** + * Returns the caching information for this material, + * This can be used to speed up the rasterizing process. + * @return The caching information. + */ + virtual TCachingInfo GetCachingInfo(void) const; + + /** + * Activates the material in the (OpenGL) rasterizer. + * On entry, the cachingInfo contains info about the last activated material. + * On exit, the cachingInfo should contain updated info about this material. + * @param rasty The rasterizer in which the material should be active. + * @param cachingInfo The information about the material used to speed up rasterizing. + */ + virtual void Activate(RAS_IRasterizer* rasty, TCachingInfo& cachingInfo) const; + + /** + * Returns the Blender texture face structure that is used for this material. + * @return The material's texture face. + */ + TFace* GetTFace(void) const; +protected: +private: +}; + + +inline TFace* KX_BlenderPolyMaterial::GetTFace(void) const +{ + return m_tface; +} + +inline RAS_IPolyMaterial::TCachingInfo KX_BlenderPolyMaterial::GetCachingInfo(void) const +{ + return GetTFace(); +} + +#endif // __KX_BLENDERPOLYMATERIAL diff --git a/source/gameengine/BlenderRoutines/KX_BlenderRenderTools.cpp b/source/gameengine/BlenderRoutines/KX_BlenderRenderTools.cpp new file mode 100644 index 00000000000..4fdb9aafc33 --- /dev/null +++ b/source/gameengine/BlenderRoutines/KX_BlenderRenderTools.cpp @@ -0,0 +1,411 @@ +/** + * $Id$ + * ***** BEGIN GPL/BL DUAL LICENSE BLOCK ***** + * + * 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; either version 2 + * of the License, or (at your option) any later version. The Blender + * Foundation also sells licenses for use in proprietary software under + * the Blender License. See http://www.blender.org/BL/ for information + * about this. + * + * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): none yet. + * + * ***** END GPL/BL DUAL LICENSE BLOCK ***** + */ + +#include "KX_BlenderRenderTools.h" + +#ifdef WIN32 +// OpenGL gl.h needs 'windows.h' on windows platforms +#include <windows.h> +#endif //WIN32 +#include "GL/gl.h" + +#include "RAS_IRenderTools.h" +#include "RAS_IRasterizer.h" +#include "RAS_LightObject.h" +#include "RAS_ICanvas.h" + + +// next two includes/dependencies come from the shadow feature +// it needs the gameobject and the sumo physics scene for a raycast +#include "KX_GameObject.h" + +#include "KX_BlenderPolyMaterial.h" +#include "Value.h" + +#include "KX_BlenderGL.h" // for text printing +#include "STR_String.h" +#include "RAS_BucketManager.h" // for polymaterial (needed for textprinting) + +KX_BlenderRenderTools::KX_BlenderRenderTools() +{ +} + +/** +ProcessLighting performs lighting on objects. the layer is a bitfield that contains layer information. +There are 20 'official' layers in blender. +A light is applied on an object only when they are in the same layer. +OpenGL has a maximum of 8 lights (simultaneous), so 20 * 8 lights are possible in a scene. +*/ + +int KX_BlenderRenderTools::ProcessLighting(int layer) +{ + + int result = false; + + if (layer < 0) + { + DisableOpenGLLights(); + result = false; + } else + { + if (m_clientobject) + { + + + if (applyLights(layer)) + { + EnableOpenGLLights(); + result = true; + } else + { + DisableOpenGLLights(); + result = false; + } + + + } + } + return result; + + +} + + +void KX_BlenderRenderTools::BeginFrame(RAS_IRasterizer* rasty) +{ + m_clientobject = NULL; + m_lastblenderobject = NULL; + m_lastblenderlights = false; + m_lastlayer = -1; + m_lastlighting = false; + m_modified = true; + DisableOpenGLLights(); + + +} + + +void KX_BlenderRenderTools::applyTransform(RAS_IRasterizer* rasty,double* oglmatrix,int objectdrawmode ) +{ + if (objectdrawmode & RAS_IPolyMaterial::BILLBOARD_SCREENALIGNED || + objectdrawmode & RAS_IPolyMaterial::BILLBOARD_AXISALIGNED) + { + // rotate the billboard/halo + //page 360/361 3D Game Engine Design, David Eberly for a discussion + // on screen aligned and axis aligned billboards + // assumed is that the preprocessor transformed all billboard polygons + // so that their normal points into the positive x direction (1.0 , 0.0 , 0.0) + // when new parenting for objects is done, this rotation + // will be moved into the object + + MT_Point3 objpos (oglmatrix[12],oglmatrix[13],oglmatrix[14]); + MT_Point3 campos = rasty->GetCameraPosition(); + MT_Vector3 dir = (campos - objpos).safe_normalized(); + MT_Vector3 up(0,0,1.0); + + KX_GameObject* gameobj = (KX_GameObject*) this->m_clientobject; + // get scaling of halo object + MT_Vector3 size = gameobj->GetSGNode()->GetLocalScale(); + + bool screenaligned = (objectdrawmode & RAS_IPolyMaterial::BILLBOARD_SCREENALIGNED)!=0;//false; //either screen or axisaligned + if (screenaligned) + { + up = (up - up.dot(dir) * dir).safe_normalized(); + } else + { + dir = (dir - up.dot(dir)*up).safe_normalized(); + } + + MT_Vector3 left = dir.normalized(); + dir = (left.cross(up)).normalized(); + + // we have calculated the row vectors, now we keep + // local scaling into account: + + left *= size[0]; + dir *= size[1]; + up *= size[2]; + double maat[16]={ + left[0], left[1],left[2], 0, + dir[0], dir[1],dir[2],0, + up[0],up[1],up[2],0, + 0,0,0,1}; + glTranslated(objpos[0],objpos[1],objpos[2]); + glMultMatrixd(maat); + + } else + { + if (objectdrawmode & RAS_IPolyMaterial::SHADOW) + { + // shadow must be cast to the ground, physics system needed here! + KX_GameObject* gameobj = (KX_GameObject*) this->m_clientobject; + MT_Point3 frompoint(oglmatrix[12],oglmatrix[13],oglmatrix[14]); + MT_Vector3 direction = MT_Vector3(0,0,-1); + + + direction.normalize(); + direction *= 100000; + + MT_Point3 topoint = frompoint + direction; + MT_Point3 resultpoint; + MT_Vector3 resultnormal; + + //todo: + //use physics abstraction + + + //SM_Scene* scene = (SM_Scene*) m_auxilaryClientInfo; + + //SM_Object* hitObj = scene->rayTest(gameobj->GetSumoObject(),frompoint,topoint, + // resultpoint, resultnormal); + + + if (0) //hitObj) + { + MT_Vector3 left(oglmatrix[0],oglmatrix[1],oglmatrix[2]); + MT_Vector3 dir = -(left.cross(resultnormal)).normalized(); + left = (dir.cross(resultnormal)).normalized(); + // for the up vector, we take the 'resultnormal' returned by the physics + + double maat[16]={ + left[0], left[1],left[2], 0, + dir[0], dir[1],dir[2],0, + resultnormal[0],resultnormal[1],resultnormal[2],0, + 0,0,0,1}; + glTranslated(resultpoint[0],resultpoint[1],resultpoint[2]); + glMultMatrixd(maat); + // glMultMatrixd(oglmatrix); + } else + { + glMultMatrixd(oglmatrix); + } + + + } else + { + + // 'normal' object + glMultMatrixd(oglmatrix); + } + } +} + + +/** +Render Text renders text into a (series of) polygon, using a texture font, +Each character consists of one polygon (one quad or two triangles) +*/ +void KX_BlenderRenderTools::RenderText(int mode,RAS_IPolyMaterial* polymat,float v1[3],float v2[3],float v3[3],float v4[3]) +{ + + STR_String mytext = ((CValue*)m_clientobject)->GetPropertyText("Text"); + + KX_BlenderPolyMaterial* blenderpoly = (KX_BlenderPolyMaterial*)polymat; + struct TFace* tface = blenderpoly->GetTFace(); + + BL_RenderText( mode,mytext,mytext.Length(),tface,v1,v2,v3,v4); + +} + + + +KX_BlenderRenderTools::~KX_BlenderRenderTools() +{ +}; + + +void KX_BlenderRenderTools::EndFrame(RAS_IRasterizer* rasty) +{ +} + + + +void KX_BlenderRenderTools::DisableOpenGLLights() +{ + glDisable(GL_LIGHTING); + glDisable(GL_COLOR_MATERIAL); +#ifndef SLOWPAINT + glDisableClientState(GL_NORMAL_ARRAY); +#endif //SLOWPAINT +} + + +void KX_BlenderRenderTools::EnableOpenGLLights() +{ + glEnable(GL_LIGHTING); + + glColorMaterial(GL_FRONT_AND_BACK,GL_DIFFUSE); + glEnable(GL_COLOR_MATERIAL); +#ifndef SLOWPAINT + glEnableClientState(GL_NORMAL_ARRAY); +#endif //SLOWPAINT + glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, false); +} + + +/** + * Rendering text using 2D bitmap functionality. + */ +void KX_BlenderRenderTools::RenderText2D(RAS_TEXT_RENDER_MODE mode, + const char* text, + int xco, + int yco, + int width, + int height) +{ + switch (mode) { + case RAS_IRenderTools::RAS_TEXT_PADDED: { + STR_String tmpstr(text); + BL_print_gamedebug_line_padded(tmpstr.Ptr(),xco,yco,width,height); + break; + } + default: { + STR_String tmpstr(text); + BL_print_gamedebug_line(tmpstr.Ptr(),xco,yco,width,height); + } + } +} + + + +void KX_BlenderRenderTools::PushMatrix() +{ + glPushMatrix(); +} + +void KX_BlenderRenderTools::PopMatrix() +{ + glPopMatrix(); +} + + + +int KX_BlenderRenderTools::applyLights(int objectlayer) +{ +// taken from blender source, incompatibility between Blender Object / GameObject + + int count; + float vec[4]; + + vec[3]= 1.0; + + for(count=0; count<8; count++) + glDisable((GLenum)(GL_LIGHT0+count)); + + count= 0; + + //std::vector<struct RAS_LightObject*> m_lights; + std::vector<struct RAS_LightObject*>::iterator lit = m_lights.begin(); + + + for (lit = m_lights.begin(); !(lit==m_lights.end()); ++lit) + { + RAS_LightObject* lightdata = (*lit); + if (lightdata->m_layer & objectlayer) + { + + glPushMatrix(); + glLoadMatrixf(m_viewmat); + + + vec[0] = (*(lightdata->m_worldmatrix))(0,3); + vec[1] = (*(lightdata->m_worldmatrix))(1,3); + vec[2] = (*(lightdata->m_worldmatrix))(2,3); + vec[3] = 1; + + + if(lightdata->m_type==RAS_LightObject::LIGHT_SUN) { + + vec[0] = (*(lightdata->m_worldmatrix))(0,2); + vec[1] = (*(lightdata->m_worldmatrix))(1,2); + vec[2] = (*(lightdata->m_worldmatrix))(2,2); + //vec[0]= base->object->obmat[2][0]; + //vec[1]= base->object->obmat[2][1]; + //vec[2]= base->object->obmat[2][2]; + vec[3]= 0.0; + glLightfv((GLenum)(GL_LIGHT0+count), GL_POSITION, vec); + } + else { + //vec[3]= 1.0; + glLightfv((GLenum)(GL_LIGHT0+count), GL_POSITION, vec); + glLightf((GLenum)(GL_LIGHT0+count), GL_CONSTANT_ATTENUATION, 1.0); + glLightf((GLenum)(GL_LIGHT0+count), GL_LINEAR_ATTENUATION, lightdata->m_att1/lightdata->m_distance); + // without this next line it looks backward compatible. + //attennuation still is acceptable + // glLightf((GLenum)(GL_LIGHT0+count), GL_QUADRATIC_ATTENUATION, la->att2/(la->dist*la->dist)); + + if(lightdata->m_type==RAS_LightObject::LIGHT_SPOT) { + vec[0] = -(*(lightdata->m_worldmatrix))(0,2); + vec[1] = -(*(lightdata->m_worldmatrix))(1,2); + vec[2] = -(*(lightdata->m_worldmatrix))(2,2); + //vec[0]= -base->object->obmat[2][0]; + //vec[1]= -base->object->obmat[2][1]; + //vec[2]= -base->object->obmat[2][2]; + glLightfv((GLenum)(GL_LIGHT0+count), GL_SPOT_DIRECTION, vec); + glLightf((GLenum)(GL_LIGHT0+count), GL_SPOT_CUTOFF, lightdata->m_spotsize/2.0); + glLightf((GLenum)(GL_LIGHT0+count), GL_SPOT_EXPONENT, 128.0*lightdata->m_spotblend); + } + else glLightf((GLenum)(GL_LIGHT0+count), GL_SPOT_CUTOFF, 180.0); + } + + vec[0]= lightdata->m_energy*lightdata->m_red; + vec[1]= lightdata->m_energy*lightdata->m_green; + vec[2]= lightdata->m_energy*lightdata->m_blue; + vec[3]= 1.0; + glLightfv((GLenum)(GL_LIGHT0+count), GL_DIFFUSE, vec); + glLightfv((GLenum)(GL_LIGHT0+count), GL_SPECULAR, vec); + glEnable((GLenum)(GL_LIGHT0+count)); + + glPopMatrix(); + + count++; + if(count>7) + break; + } + } + + return count; + +} + + + +RAS_IPolyMaterial* KX_BlenderRenderTools::CreateBlenderPolyMaterial( + const STR_String &texname, + bool ba,const STR_String& matname,int tile,int tilexrep,int tileyrep,int mode,int transparant,int lightlayer + ,bool bIsTriangle,void* clientobject,void* tface) +{ + return new KX_BlenderPolyMaterial( + + texname, + ba,matname,tile,tilexrep,tileyrep,mode,transparant,lightlayer + ,bIsTriangle,clientobject,(struct TFace*)tface); +} diff --git a/source/gameengine/BlenderRoutines/KX_BlenderRenderTools.h b/source/gameengine/BlenderRoutines/KX_BlenderRenderTools.h new file mode 100644 index 00000000000..fb4c5a6f2ba --- /dev/null +++ b/source/gameengine/BlenderRoutines/KX_BlenderRenderTools.h @@ -0,0 +1,100 @@ +/** + * $Id$ + * + * ***** BEGIN GPL/BL DUAL LICENSE BLOCK ***** + * + * 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; either version 2 + * of the License, or (at your option) any later version. The Blender + * Foundation also sells licenses for use in proprietary software under + * the Blender License. See http://www.blender.org/BL/ for information + * about this. + * + * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): none yet. + * + * ***** END GPL/BL DUAL LICENSE BLOCK ***** + */ +#ifndef __KX_BLENDERRENDERTOOLS +#define __KX_BLENDERRENDERTOOLS + +#ifdef WIN32 +// don't show stl-warnings +#pragma warning (disable:4786) +#endif + +#include "RAS_IRenderTools.h" + +/** +BlenderRenderTools are a set of tools to apply 2D/3D graphics effects, which are not +part of the (polygon) Rasterizer. +Effects like 2D text, 3D (polygon) text, lighting. +*/ + +class KX_BlenderRenderTools : public RAS_IRenderTools +{ + bool m_lastblenderlights; + void* m_lastblenderobject; + int m_lastlayer; + bool m_lastlighting; + +public: + + KX_BlenderRenderTools(); + virtual ~KX_BlenderRenderTools(); + + virtual void EndFrame(class RAS_IRasterizer* rasty); + virtual void BeginFrame(class RAS_IRasterizer* rasty); + void DisableOpenGLLights(); + void EnableOpenGLLights(); + int ProcessLighting(int layer); + + virtual void RenderText2D(RAS_TEXT_RENDER_MODE mode, + const char* text, + int xco, + int yco, + int width, + int height); + virtual void RenderText(int mode, + class RAS_IPolyMaterial* polymat, + float v1[3], + float v2[3], + float v3[3], + float v4[3]); + void applyTransform(class RAS_IRasterizer* rasty, + double* oglmatrix, + int objectdrawmode ); + int applyLights(int objectlayer); + virtual void PushMatrix(); + virtual void PopMatrix(); + + virtual class RAS_IPolyMaterial* CreateBlenderPolyMaterial(const STR_String &texname, + bool ba, + const STR_String& matname, + int tile, + int tilexrep, + int tileyrep, + int mode, + int transparant, + int lightlayer, + bool bIsTriangle, + void* clientobject, + void* tface); +}; + + +#endif //__KX_BLENDERRENDERTOOLS diff --git a/source/gameengine/BlenderRoutines/KX_BlenderSystem.cpp b/source/gameengine/BlenderRoutines/KX_BlenderSystem.cpp new file mode 100644 index 00000000000..f690f7c74e2 --- /dev/null +++ b/source/gameengine/BlenderRoutines/KX_BlenderSystem.cpp @@ -0,0 +1,56 @@ +/** + * $Id$ + * ***** BEGIN GPL/BL DUAL LICENSE BLOCK ***** + * + * 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; either version 2 + * of the License, or (at your option) any later version. The Blender + * Foundation also sells licenses for use in proprietary software under + * the Blender License. See http://www.blender.org/BL/ for information + * about this. + * + * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): none yet. + * + * ***** END GPL/BL DUAL LICENSE BLOCK ***** + */ + +#include "KX_ISystem.h" + + +#ifdef WIN32 +#pragma warning (disable :4786) +#include <windows.h> +#endif //WIN32 + +#include <iostream> +#include <stdio.h> +#include "KX_BlenderInputDevice.h" +#include "KX_BlenderSystem.h" + +#include "PIL_time.h" + +KX_BlenderSystem::KX_BlenderSystem() +: KX_ISystem() +{ + m_starttime = PIL_check_seconds_timer(); +} + +double KX_BlenderSystem::GetTimeInSeconds() +{ + return PIL_check_seconds_timer() - m_starttime; +} diff --git a/source/gameengine/BlenderRoutines/KX_BlenderSystem.h b/source/gameengine/BlenderRoutines/KX_BlenderSystem.h new file mode 100644 index 00000000000..68db3194b0a --- /dev/null +++ b/source/gameengine/BlenderRoutines/KX_BlenderSystem.h @@ -0,0 +1,51 @@ +/** + * $Id$ + * + * ***** BEGIN GPL/BL DUAL LICENSE BLOCK ***** + * + * 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; either version 2 + * of the License, or (at your option) any later version. The Blender + * Foundation also sells licenses for use in proprietary software under + * the Blender License. See http://www.blender.org/BL/ for information + * about this. + * + * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): none yet. + * + * ***** END GPL/BL DUAL LICENSE BLOCK ***** + */ +#ifndef __KX_BLENDERSYSTEM +#define __KX_BLENDERSYSTEM + +#include "blendertimer.h" + +/** + * Blender System embedding. Needed when gameengine runs embedded within Blender. + */ +#include "KX_ISystem.h" + +class KX_BlenderSystem : public KX_ISystem +{ + double m_starttime; + +public: + KX_BlenderSystem(); + virtual ~KX_BlenderSystem() {}; + virtual double GetTimeInSeconds(); +}; +#endif //__KX_BLENDERSYSTEM diff --git a/source/gameengine/BlenderRoutines/Makefile b/source/gameengine/BlenderRoutines/Makefile new file mode 100644 index 00000000000..9a4ba217ac7 --- /dev/null +++ b/source/gameengine/BlenderRoutines/Makefile @@ -0,0 +1,75 @@ +# +# $Id$ +# +# ***** BEGIN GPL/BL DUAL LICENSE BLOCK ***** +# +# 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; either version 2 +# of the License, or (at your option) any later version. The Blender +# Foundation also sells licenses for use in proprietary software under +# the Blender License. See http://www.blender.org/BL/ for information +# about this. +# +# 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# +# The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. +# All rights reserved. +# +# The Original Code is: all of this file. +# +# Contributor(s): none yet. +# +# ***** END GPL/BL DUAL LICENSE BLOCK ***** +# +# + +LIBNAME = bloutines +DIR = $(OCGDIR)/gameengine/$(LIBNAME) + +include nan_compile.mk + +CCFLAGS += $(LEVEL_1_CPP_WARNINGS) + +CPPFLAGS += -I$(OPENGL_HEADERS) +CPPFLAGS += -I$(NAN_SUMO)/include +CPPFLAGS += -I$(NAN_STRING)/include +CPPFLAGS += -I$(NAN_MOTO)/include +CPPFLAGS += -I$(NAN_BMFONT)/include +CPPFLAGS += -I$(NAN_FUZZICS)/include +# because of kernel dependency on makesdna +CPPFLAGS += -I../../blender/makesdna +CPPFLAGS += -I../../blender/include +# timer stuff +CPPFLAGS += -I../../blender/misc +# because of kernel dependency on imbuf +CPPFLAGS += -I../../blender/imbuf +CPPFLAGS += -I../../blender/blenlib +CPPFLAGS += -I../../blender/blenkernel +CPPFLAGS += -I../../blender/render/extern/include +CPPFLAGS += -I../../blender/blenloader +CPPFLAGS += -I../../blender/blenkernel +CPPFLAGS += -I../Converter +CPPFLAGS += -I../Expressions +CPPFLAGS += -I../GameLogic +CPPFLAGS += -I../Ketsji +CPPFLAGS += -I../Rasterizer +CPPFLAGS += -I../Rasterizer/RAS_OpenGLRasterizer +CPPFLAGS += -I../SceneGraph +CPPFLAGS += -I../SoundSystem +CPPFLAGS += -I../../kernel/gen_system +CPPFLAGS += -I../Network +CPPFLAGS += -I../Network/LoopBackNetwork +ifeq ($(OS),windows) + CPPFLAGS += -I../../blender +endif + +CPPFLAGS += -I$(NAN_PYTHON)/include/python$(NAN_PYTHON_VERSION) + |