Skip to content

Instantly share code, notes, and snippets.

View michaliskambi's full-sized avatar

Michalis Kamburelis michaliskambi

View GitHub Profile
{ view_3d_model_basic.dpr from CGE modified to test Scene.MoveToViewpoint. }
program view_3d_model_basic;
{$ifdef MSWINDOWS} {$apptype GUI} {$endif}
uses SysUtils, Classes,
CastleWindow, CastleSceneCore, CastleScene, CastleViewport, CastleCameras, CastleVectors,
CastleUIControls, CastleKeysMouse, CastleLog, CastleStringUtils;
@michaliskambi
michaliskambi / test_winapi.dpr
Created January 9, 2022 23:13
Create a window using WinAPI (Unicode variant, W suffix) using FPC (Pascal)
uses SysUtils, Types, Windows;
function WndProc(hWnd: HWND; uMsg: UINT; wParm: WPARAM; lParm: LPARAM) :LRESULT; stdcall;
begin
// It is critical to use here DefWindowProcW, not DefWindowProc,
// otherwise CreateWindowExW expects caption using 8-bit (ANSI) encoding.
Result := DefWindowProcW(hWnd, uMsg, wParm, lParm);
end;
var
@michaliskambi
michaliskambi / gamestatemain.pas
Last active July 28, 2021 22:22
Simple code detecting double-click in CGE
{ Sample that shows how to detect double-click in CGE.
Copy this code e.g. over CGE example
examples/user_interface/state_events/code/gamestatemain.pas
to test. }
{ Main state, where most of the application logic takes place. }
unit GameStateMain;
interface
@michaliskambi
michaliskambi / gamesound.pas
Last active July 16, 2021 15:00
Sample unit to implement randomization of sounds in Castle Game Engine. See https://github.com/castle-engine/castle-engine/wiki/Upgrading-to-Castle-Game-Engine-7.0
{ Sample unit to implement randomization of sounds,
after the feature was removed from CGE sounds XML file.
See https://github.com/castle-engine/castle-engine/wiki/Upgrading-to-Castle-Game-Engine-7.0
for documentation.
Copyright 2021 Michalis Kamburelis.
License: modified BSD (3-clause), so basically reuse it freely (see
https://github.com/castle-engine/castle-engine/blob/master/doc/licenses/COPYING.BSD-3-clause.txt ).
Usage:
// -*- compile-command: "castle-engine simple-compile position_on_viewport_early.lpr && ./position_on_viewport_early" -*-
{ Reproduction for https://github.com/castle-engine/castle-engine/issues/295 . }
uses SysUtils,
CastleWindow, CastleViewport, CastleVectors, CastleFilesUtils, CastleTransform,
CastleLog, CastleKeysMouse, CastleScene;
var
Viewport: TCastleViewport;
// -*- compile-command: "castle-engine simple-compile update_texture_coords.lpr && ./update_texture_coords" -*-
{ Reproduction for https://github.com/castle-engine/castle-engine/issues/303 .
Based on https://castle-engine.io/x3d_implementation_geometry3d.php example. }
uses SysUtils,
CastleWindow, CastleScene, CastleViewport, CastleKeysMouse,
CastleColors, CastleVectors, CastleFilesUtils, X3DNodes, CastleTransform;
var
TextureCoordinate: TTextureCoordinateNode;
// -*- compile-command: "castle-engine simple-compile reload_texture.lpr && ./reload_texture" -*-
{ See https://github.com/castle-engine/castle-engine/issues/304
Pressing S or W multiple times in a row should not reload the texture.
First press of S or W should still switch the texture.
}
uses SysUtils,
// -*- compile-command: "castle-engine simple-compile transform_save.lpr" -*-
{ TransformSave example. }
uses SysUtils,
CastleVectors, CastleTransform, CastleScene, CastleComponentSerialize;
var
S: TCastleScene;
T: TCastleTransform;
begin
{ Build an IndexedFaceSet node (mesh) with Color node (colors per-vertex). }
uses SysUtils,
CastleWindow, CastleScene, CastleViewport,
CastleColors, CastleVectors, X3DNodes, CastleTransform;
function BuildRootNode: TX3DRootNode;
var
Shape: TShapeNode;
Geometry: TIndexedFaceSetNode;
@michaliskambi
michaliskambi / game.pas
Created December 9, 2019 00:08
Corrected (for Billboards) version of game.pas from Kagamma submission on https://sourceforge.net/p/castle-engine/discussion/general/thread/882ca037/
{$mode objfpc}{$H+}
unit Game;
interface
uses CastleWindowTouch;
var
Window: TCastleWindowTouch;