Skip to content

Instantly share code, notes, and snippets.

View tgjones's full-sized avatar

Tim Jones tgjones

View GitHub Profile
@tgjones
tgjones / gist:746405
Created December 18, 2010 11:00
No doubt we'll need a visual editor at some point, but having this kind of API for the "engine" makes rapid prototyping a breeze.
scene.Children.Add(new GameObjectBuilder()
.WithMeshSource(b => b.Mesh(new Mesh(Content, "Cube")))
.WithMeshRenderer()
.WithBoxCollider(b => b.Size(new Vector3(10, 10, 10)))
.WithRigidBody()
.Position(new Vector3(100, 50, 100))
.Rotation(Vector3.Right, MathHelper.Pi / 8.0f)
.ToGameObject());
@tgjones
tgjones / gist:751513
Created December 22, 2010 13:44
Surface shaders using StitchUp
// Normal-Diffuse.shader
surface Diffuse;
[params]
float4 Color : DIFFUSE_COLOR = float4(1, 1, 1, 1);
[textures]
Texture2D MainTex : DIFFUSE_TEXTURE;
@tgjones
tgjones / gist:822240
Created February 11, 2011 11:49
Rendering 3D images in ASP.NET
<sitdap:DynamicImage runat="server">
<Layers>
<sitdap:RenderedLayer Width="600" Height="300" SourceFileName="~/Assets/Models/3ds/85-nissan-fairlady.3ds" Zoom="1.4" Yaw="135" />
</Layers>
</sitdap:DynamicImage>
<sitdap:DynamicImage runat="server">
<Layers>
<sitdap:RenderedLayer Width="600" Height="300" BackgroundColour="LightBlue">
<Source>
@tgjones
tgjones / gist:864432
Created March 10, 2011 16:42
Example of Ormongo's GridFS wrapper class, Attachment
public class Asset : Document<Asset>
{
public string Title { get; set; }
public Attachment File { get; set; }
}
Attachment file = Attachment.Create("Files/Koala.jpg", "image/jpg");
Asset asset = new Asset
{
@tgjones
tgjones / ShaderTest.cs
Created January 5, 2014 14:27
HlslUnit prototype
[Test]
public void CanExecuteVertexShader()
{
// Arrange.
var shader = new Shader("Shaders/VS/BasicHLSL.fx", "RenderSceneVS", "vs_4_0");
shader.SetConstantBuffer("$Globals", new BasicHlsl.ConstantBufferGlobals
{
WorldViewProjection =
Matrix.LookAtRH(Vector3.UnitZ, Vector3.Zero, Vector3.UnitY) *
Matrix.PerspectiveFovRH(MathUtil.PiOverFour, 1, 1, 10)
@tgjones
tgjones / Matrix.h
Created October 20, 2014 14:51
The Matrix Inverted
#ifndef MatrixInversion_Matrix_h
#define MatrixInversion_Matrix_h
template <int Order>
class Matrix
{
public:
// Static methods
static Matrix<Order> identity();
static Matrix<Order> invert(const Matrix<Order>& m);
@tgjones
tgjones / YourProject.csproj
Last active August 17, 2021 08:43
Automatically adding MonoGame XNBs into an assembly as Embedded Resources
<Target Name="BeforeBuild" DependsOnTargets="BuildContent">
<ItemGroup>
<!-- Include just-built XNB files as embedded resources in output assembly -->
<EmbeddedResource Include="@(ExtraContent)">
<LogicalName>Apollo.Resources.Compiled.$([System.String]::new('%(RecursiveDir)').Replace('\', '.'))%(Filename)%(Extension)</LogicalName>
</EmbeddedResource>
<!-- Don't copy XNB files to output directory -->
<Content Remove="@(ExtraContent->'$(ParentOutputDir)\%(RecursiveDir)%(Filename)%(Extension)')" Condition="$(MonoGamePlatform) != 'Android'" />
<AndroidAsset Remove="@(ExtraContent->'$(ParentOutputDir)\%(RecursiveDir)%(Filename)%(Extension)')" Condition="$(MonoGamePlatform) == 'Android'" />
@tgjones
tgjones / HlslAntlrLexer.g4
Created May 25, 2015 10:17
ANTLR4 grammar for HLSL
lexer grammar HlslAntlrLexer;
@lexer::header {#pragma warning disable 3021}
AppendStructuredBuffer : 'AppendStructuredBuffer';
Bool : 'bool';
Bool1 : 'bool1';
Bool2 : 'bool2';
Bool3 : 'bool3';
Bool4 : 'bool4';
public class TorqGame : Tuki.Game
{
protected override void ConfigureGraphics(GraphicsDeviceManager graphics)
{
graphics.PreferredBackBufferWidth = 1920;
graphics.PreferredBackBufferHeight = 1200;
graphics.IsFullScreen = false;
}
protected override void LoadContent()
@tgjones
tgjones / Interop.cs
Created April 9, 2023 21:03
Marshalling Vector128<float> as return type in native interop call in .NET 7.0
using System.Runtime.InteropServices;
internal static partial class Interop
{
[LibraryImport("kernel32.dll")]
public static partial void GetSystemInfo(out SystemInfo Info);
[LibraryImport("kernel32.dll")]
public static partial IntPtr VirtualAllocEx(IntPtr hProcess, IntPtr lpAddress, IntPtr dwSize, AllocationType flAllocationType, MemoryProtection flProtect);