agate-svn-commit Mailing List for AgateLib (Page 25)
Status: Alpha
Brought to you by:
kanato
You can subscribe to this list here.
| 2009 |
Jan
|
Feb
|
Mar
|
Apr
(86) |
May
(77) |
Jun
|
Jul
(1) |
Aug
(31) |
Sep
(12) |
Oct
(31) |
Nov
(53) |
Dec
(39) |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2010 |
Jan
(53) |
Feb
(14) |
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
(2) |
Sep
|
Oct
|
Nov
(7) |
Dec
(13) |
| 2011 |
Jan
(17) |
Feb
(5) |
Mar
(1) |
Apr
|
May
|
Jun
(1) |
Jul
|
Aug
|
Sep
|
Oct
(10) |
Nov
(21) |
Dec
|
| 2012 |
Jan
(6) |
Feb
(14) |
Mar
(5) |
Apr
(4) |
May
(1) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
| 2013 |
Jan
(1) |
Feb
(8) |
Mar
(1) |
Apr
|
May
|
Jun
|
Jul
|
Aug
(2) |
Sep
(1) |
Oct
(5) |
Nov
(9) |
Dec
(5) |
| 2014 |
Jan
(3) |
Feb
(2) |
Mar
(4) |
Apr
(3) |
May
|
Jun
(5) |
Jul
(33) |
Aug
(69) |
Sep
(35) |
Oct
(4) |
Nov
(1) |
Dec
|
|
From: <ac...@us...> - 2009-05-03 15:24:02
|
Revision: 937
http://agate.svn.sourceforge.net/agate/?rev=937&view=rev
Author: accagon
Date: 2009-05-03 15:23:56 +0000 (Sun, 03 May 2009)
Log Message:
-----------
* Particle.cs:
- Name change IsDead->IsALive
- Remove Condition, IsALive stores the same information
Modified Paths:
--------------
branches/particles/AgateLib/Particles/Particle.cs
Modified: branches/particles/AgateLib/Particles/Particle.cs
===================================================================
--- branches/particles/AgateLib/Particles/Particle.cs 2009-05-02 22:30:19 UTC (rev 936)
+++ branches/particles/AgateLib/Particles/Particle.cs 2009-05-03 15:23:56 UTC (rev 937)
@@ -29,8 +29,7 @@
public class Particle
{
private float mLife = 10f;
- private Condition mCondition = Condition.ALive;
- private bool mIsDead = false;
+ private bool mIsALive = false;
private Vector2 mAcceleration = Vector2.Empty;
private Vector2 mPosition = Vector2.Empty;
@@ -44,22 +43,14 @@
{
get { return mLife; }
set { mLife = value; }
- }
-
- /// <value>
- /// Gets the condition.
- /// </value>
- public Condition Condition
- {
- get { return mCondition; }
}
/// <value>
/// Is particle dead.
/// </value>
- public bool IsDead
+ public bool IsALive
{
- get { return mIsDead; }
+ get { return mIsALive; }
}
/// <value>
@@ -103,15 +94,14 @@
if(mLife <= 0)
{
- mIsDead = true;
- mCondition = Condition.Dead;
+ mIsALive = false;
}
// Euler method
// v = v + a * dt
// x = x + v * dt
// mVelocity = mVelocity + mAcceleration * time;
- // mPosition = mPosition + mVelocity * time;
+ // mPosition = mPosition + mVelocity * time;
// verlet integration
// xi+1 = xi + (xi - xi-1) + a * dt * dt
@@ -122,14 +112,4 @@
// mPosition = mPosition + (mPosition - mPosition - 1) * (time / time - 1) + mAcceleration * time * time;
}
}
-
- /// <summary>
- /// Condition of a particle.
- /// </summary>
- [Flags]
- public enum Condition
- {
- Dead = 0,
- ALive = 1
- }
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ka...@us...> - 2009-05-02 22:30:21
|
Revision: 936
http://agate.svn.sourceforge.net/agate/?rev=936&view=rev
Author: kanato
Date: 2009-05-02 22:30:19 +0000 (Sat, 02 May 2009)
Log Message:
-----------
Remove Test3D folder with extra assembly info file.
Removed Paths:
-------------
branches/agate3d-3.2/Tests/Display3D/Test3D/
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ka...@us...> - 2009-05-01 18:10:57
|
Revision: 935
http://agate.svn.sourceforge.net/agate/?rev=935&view=rev
Author: kanato
Date: 2009-05-01 18:10:56 +0000 (Fri, 01 May 2009)
Log Message:
-----------
Trial with user primitives -- doesn't work.
Modified Paths:
--------------
branches/agate3d-3.2/Drivers/AgateMDX/MDX1_IndexBuffer.cs
branches/agate3d-3.2/Drivers/AgateMDX/MDX1_VertexBuffer.cs
Modified: branches/agate3d-3.2/Drivers/AgateMDX/MDX1_IndexBuffer.cs
===================================================================
--- branches/agate3d-3.2/Drivers/AgateMDX/MDX1_IndexBuffer.cs 2009-05-01 13:56:34 UTC (rev 934)
+++ branches/agate3d-3.2/Drivers/AgateMDX/MDX1_IndexBuffer.cs 2009-05-01 18:10:56 UTC (rev 935)
@@ -14,6 +14,7 @@
IndexBufferType mType;
int mCount;
Direct3D.IndexBuffer mBuffer;
+ object data;
public MDX1_IndexBuffer(MDX1_Display disp, IndexBufferType type, int count)
{
@@ -28,6 +29,10 @@
{
get { return mBuffer; }
}
+ public object Data
+ {
+ get { return data; }
+ }
private void CreateIndexBuffer()
{
@@ -57,11 +62,13 @@
public override void WriteIndices(int[] indices)
{
mBuffer.SetData(indices, 0, Microsoft.DirectX.Direct3D.LockFlags.Discard);
+ data = indices;
}
public override void WriteIndices(short[] indices)
{
mBuffer.SetData(indices, 0, Microsoft.DirectX.Direct3D.LockFlags.Discard);
+ data = indices;
}
}
}
Modified: branches/agate3d-3.2/Drivers/AgateMDX/MDX1_VertexBuffer.cs
===================================================================
--- branches/agate3d-3.2/Drivers/AgateMDX/MDX1_VertexBuffer.cs 2009-05-01 13:56:34 UTC (rev 934)
+++ branches/agate3d-3.2/Drivers/AgateMDX/MDX1_VertexBuffer.cs 2009-05-01 18:10:56 UTC (rev 935)
@@ -17,6 +17,7 @@
Direct3D.VertexDeclaration mDeclaration;
Direct3D.VertexFormats mFormats;
int mCount;
+ object data;
public MDX1_VertexBuffer(MDX1_Display display, VertexLayout layout, int vertexCount)
{
@@ -178,7 +179,6 @@
mDisplay.D3D_Device.Device.VertexDeclaration = mDeclaration;
mDisplay.D3D_Device.Device.DrawPrimitives(primType, start, primitiveCount);
}
-
public override void DrawIndexed(IndexBuffer _indexbuffer, int start, int count)
{
int primitiveCount = count;
@@ -194,7 +194,11 @@
mDisplay.D3D_Device.Device.SetStreamSource(0, mBuffer, 0);
mDisplay.D3D_Device.VertexFormat = mFormats;
mDisplay.D3D_Device.Device.VertexDeclaration = mDeclaration;
- mDisplay.D3D_Device.Device.DrawIndexedPrimitives(primType, 0, 0, count, start, primitiveCount);
+ //mDisplay.D3D_Device.Device.DrawIndexedPrimitives(primType, 0, 0, count, start, primitiveCount);
+ mDisplay.D3D_Device.Device.DrawIndexedUserPrimitives(primType, 0,
+ count, primitiveCount,
+ indexbuffer.Data, indexbuffer.IndexType == IndexBufferType.Int16,
+ data);
}
@@ -221,6 +225,7 @@
public override void Write<T>(T[] vertices)
{
mBuffer.SetData(vertices, 0, Microsoft.DirectX.Direct3D.LockFlags.Discard);
+ data = vertices;
}
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ac...@us...> - 2009-05-01 14:02:32
|
Revision: 933
http://agate.svn.sourceforge.net/agate/?rev=933&view=rev
Author: accagon
Date: 2009-05-01 13:49:05 +0000 (Fri, 01 May 2009)
Log Message:
-----------
* ParticleEmitter.cs: Check if a particle manipulator subscribed to UpdateParticles delegate
* Particle.cs: Remove Condition.Empty
* Emitters/PixelEmitter.cs: Add position parameter Apply emitter position to emitted particle
Modified Paths:
--------------
branches/particles/AgateLib/Particles/Emitters/PixelEmitter.cs
branches/particles/AgateLib/Particles/Particle.cs
branches/particles/AgateLib/Particles/ParticleEmitter.cs
Modified: branches/particles/AgateLib/Particles/Emitters/PixelEmitter.cs
===================================================================
--- branches/particles/AgateLib/Particles/Emitters/PixelEmitter.cs 2009-05-01 12:27:42 UTC (rev 932)
+++ branches/particles/AgateLib/Particles/Emitters/PixelEmitter.cs 2009-05-01 13:49:05 UTC (rev 933)
@@ -46,9 +46,11 @@
/// Constructs a pixel particle emitter.
/// </summary>
/// <param name="color">Emit color.</param>
- public PixelEmitter(Color color)
+ /// <param name="position"></param>
+ public PixelEmitter(Vector2 position, Color color)
{
- mEmitColor = color;
+ Position = position;
+ mEmitColor = color;
}
/// <summary>
@@ -63,6 +65,7 @@
{
drawSurf.Color = ptl.Color;
drawSurf.Draw(ptl.Position.X, ptl.Position.Y);
+ Console.WriteLine("Drawing at position: " + ptl.Position.X + " " + ptl.Position.Y + " color: " + ptl.Color);
}
}
}
@@ -84,7 +87,10 @@
while(time >= frequenzy)
{
// TODO: recyle dead particles
- Particles.Add(new PixelParticle(EmitColor));
+ PixelParticle pp = new PixelParticle(EmitColor);
+ pp.Position = Position;
+ Particles.Add(pp);
+
time -= frequenzy;
}
Modified: branches/particles/AgateLib/Particles/Particle.cs
===================================================================
--- branches/particles/AgateLib/Particles/Particle.cs 2009-05-01 12:27:42 UTC (rev 932)
+++ branches/particles/AgateLib/Particles/Particle.cs 2009-05-01 13:49:05 UTC (rev 933)
@@ -29,7 +29,7 @@
public class Particle
{
private float mLife = 10f;
- private Condition mCondition = Condition.Empty;
+ private Condition mCondition = Condition.ALive;
private bool mIsDead = false;
private Vector2 mAcceleration = Vector2.Empty;
@@ -129,8 +129,7 @@
[Flags]
public enum Condition
{
- Empty = 0,
- Dead = 1,
- ALive = 2
+ Dead = 0,
+ ALive = 1
}
}
Modified: branches/particles/AgateLib/Particles/ParticleEmitter.cs
===================================================================
--- branches/particles/AgateLib/Particles/ParticleEmitter.cs 2009-05-01 12:27:42 UTC (rev 932)
+++ branches/particles/AgateLib/Particles/ParticleEmitter.cs 2009-05-01 13:49:05 UTC (rev 933)
@@ -80,7 +80,9 @@
/// </param>
public override void Update (float time_ms)
{
- UpdateParticles(mParticles, time_ms);
+ if(UpdateParticles != null)
+ UpdateParticles(mParticles, time_ms);
+
base.Update (time_ms);
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ac...@us...> - 2009-05-01 14:02:32
|
Revision: 934
http://agate.svn.sourceforge.net/agate/?rev=934&view=rev
Author: accagon
Date: 2009-05-01 13:56:34 +0000 (Fri, 01 May 2009)
Log Message:
-----------
Remove console debug message
Modified Paths:
--------------
branches/particles/AgateLib/Particles/Emitters/PixelEmitter.cs
Modified: branches/particles/AgateLib/Particles/Emitters/PixelEmitter.cs
===================================================================
--- branches/particles/AgateLib/Particles/Emitters/PixelEmitter.cs 2009-05-01 13:49:05 UTC (rev 933)
+++ branches/particles/AgateLib/Particles/Emitters/PixelEmitter.cs 2009-05-01 13:56:34 UTC (rev 934)
@@ -30,7 +30,7 @@
{
private Color mEmitColor = Color.White;
- private Surface drawSurf = new Surface(1, 1);
+ private Surface drawSurf = new Surface(2, 2);
private float time = 0f;
/// <value>
@@ -53,7 +53,7 @@
mEmitColor = color;
}
- /// <summary>
+ /// <summary>s
/// Overridden Draw method.
/// Draws each living particle.
/// </summary>
@@ -65,7 +65,6 @@
{
drawSurf.Color = ptl.Color;
drawSurf.Draw(ptl.Position.X, ptl.Position.Y);
- Console.WriteLine("Drawing at position: " + ptl.Position.X + " " + ptl.Position.Y + " color: " + ptl.Color);
}
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ac...@us...> - 2009-05-01 13:22:16
|
Revision: 932
http://agate.svn.sourceforge.net/agate/?rev=932&view=rev
Author: accagon
Date: 2009-05-01 12:27:42 +0000 (Fri, 01 May 2009)
Log Message:
-----------
Folder moving:
- Move all emitters to the Emitters folder.
- Move all manipulators to the Manipulators folder.
- Move all particles to the Particles folder.
- Base classes remain in the root Particles folder.
Emitters:
- Do emit one particle type only
- Remove obsolete SampleEmitter
- Add PixelEmitter class, emits pixel particles
Particles:
- Remove surfaces, draw code
Modified Paths:
--------------
branches/particles/AgateLib/Particles/Particle.cs
branches/particles/AgateLib/Particles/ParticleEmitter.cs
Added Paths:
-----------
branches/particles/AgateLib/Particles/Emitters/
branches/particles/AgateLib/Particles/Emitters/PixelEmitter.cs
branches/particles/AgateLib/Particles/Manipulators/
branches/particles/AgateLib/Particles/Manipulators/GravityManipulator.cs
branches/particles/AgateLib/Particles/Particles/
branches/particles/AgateLib/Particles/Particles/PixelParticle.cs
branches/particles/AgateLib/Particles/Particles/SurfaceParticle.cs
Removed Paths:
-------------
branches/particles/AgateLib/Particles/GravityManipulator.cs
branches/particles/AgateLib/Particles/PixelParticle.cs
branches/particles/AgateLib/Particles/SampleEmitter.cs
Added: branches/particles/AgateLib/Particles/Emitters/PixelEmitter.cs
===================================================================
--- branches/particles/AgateLib/Particles/Emitters/PixelEmitter.cs (rev 0)
+++ branches/particles/AgateLib/Particles/Emitters/PixelEmitter.cs 2009-05-01 12:27:42 UTC (rev 932)
@@ -0,0 +1,95 @@
+// The contents of this file are subject to the Mozilla Public License
+// Version 1.1 (the "License"); you may not use this file except in
+// compliance with the License. You may obtain a copy of the License at
+// http://www.mozilla.org/MPL/
+//
+// Software distributed under the License is distributed on an "AS IS"
+// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+// License for the specific language governing rights and limitations
+// under the License.
+//
+// The Original Code is AgateLib.Particles.
+//
+// The Initial Developer of the Original Code is Marcel Hauf
+// Portions created by Marcel Hauf are Copyright (C) 2009.
+// All Rights Reserved.
+//
+// Contributor(s): Marcel Hauf.
+//
+using System;
+
+using AgateLib.DisplayLib;
+using AgateLib.Geometry;
+
+namespace AgateLib.Particles
+{
+ /// <summary>
+ /// A pixel particle emitter.
+ /// </summary>
+ public class PixelEmitter : ParticleEmitter
+ {
+ private Color mEmitColor = Color.White;
+
+ private Surface drawSurf = new Surface(1, 1);
+ private float time = 0f;
+
+ /// <value>
+ /// Gets or sets the emit color.
+ /// </value>
+ public Color EmitColor
+ {
+ get { return mEmitColor; }
+ set { mEmitColor = value; }
+ }
+
+ /// <summary>
+ /// Constructs a pixel particle emitter.
+ /// </summary>
+ /// <param name="color">Emit color.</param>
+ public PixelEmitter(Color color)
+ {
+ mEmitColor = color;
+ }
+
+ /// <summary>
+ /// Overridden Draw method.
+ /// Draws each living particle.
+ /// </summary>
+ public override void Draw ()
+ {
+ foreach(PixelParticle ptl in Particles)
+ {
+ if(ptl.Condition == Condition.ALive)
+ {
+ drawSurf.Color = ptl.Color;
+ drawSurf.Draw(ptl.Position.X, ptl.Position.Y);
+ }
+ }
+ }
+
+ /// <summary>
+ /// Overridden Update mehtod.
+ /// Emits particles based on the frequenzy property.
+ /// Updates the emitter position.
+ /// Calls particle manipulators to manipulate particles.
+ /// </summary>
+ /// <param name="time_ms">
+ /// A <see cref="System.Single"/>
+ /// </param>
+ public override void Update (float time_ms)
+ {
+ time += time_ms;
+ float frequenzy = EmitFrequenzy*1000;
+
+ while(time >= frequenzy)
+ {
+ // TODO: recyle dead particles
+ Particles.Add(new PixelParticle(EmitColor));
+ time -= frequenzy;
+ }
+
+ // updates own position and calls manipulators
+ base.Update (time_ms);
+ }
+ }
+}
Deleted: branches/particles/AgateLib/Particles/GravityManipulator.cs
===================================================================
--- branches/particles/AgateLib/Particles/GravityManipulator.cs 2009-05-01 07:55:09 UTC (rev 931)
+++ branches/particles/AgateLib/Particles/GravityManipulator.cs 2009-05-01 12:27:42 UTC (rev 932)
@@ -1,77 +0,0 @@
-// The contents of this file are subject to the Mozilla Public License
-// Version 1.1 (the "License"); you may not use this file except in
-// compliance with the License. You may obtain a copy of the License at
-// http://www.mozilla.org/MPL/
-//
-// Software distributed under the License is distributed on an "AS IS"
-// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
-// License for the specific language governing rights and limitations
-// under the License.
-//
-// The Original Code is AgateLib.Particles.
-//
-// The Initial Developer of the Original Code is Marcel Hauf
-// Portions created by Marcel Hauf are Copyright (C) 2009.
-// All Rights Reserved.
-//
-// Contributor(s): Marcel Hauf.
-//
-using System;
-using System.Collections.Generic;
-
-using AgateLib.Geometry;
-
-namespace AgateLib.Particles
-{
- /// <summary>
- /// A gravity particle manipulator.
- /// </summary>
- public class GravityManipulator
- {
- private float mStrength = 1f;
- private Vector2 mPosition = Vector2.Empty;
-
- /// <value>
- /// Gets or sets the strength.
- /// </value>
- public float Strength
- {
- get { return mStrength; }
- set { mStrength = value; }
- }
-
- /// <value>
- /// Gets or sets the position.
- /// </value>
- public Vector2 Position
- {
- get { return mPosition; }
- set { mPosition = value; }
- }
-
- /// <summary>
- /// Constructs a gravitiy manipulator.
- /// </summary>
- /// <param name="position"></param>
- /// <param name="strength"></param>
- public GravityManipulator(Vector2 position, float strength)
- {
- mPosition = position;
- mStrength = strength;
- }
-
- /// <summary>
- /// Subscribe to a particle emitter.
- /// </summary>
- /// <param name="emitter"></param>
- public void SubscribeToEmitter(ParticleEmitter emitter)
- {
- emitter.UpdateParticles += Manipulate;
- }
-
- internal void Manipulate(List<Particle> particles, float time_ms)
- {
- // TODO: add missing calculation to gravity manipulator
- }
- }
-}
Copied: branches/particles/AgateLib/Particles/Manipulators/GravityManipulator.cs (from rev 931, branches/particles/AgateLib/Particles/GravityManipulator.cs)
===================================================================
--- branches/particles/AgateLib/Particles/Manipulators/GravityManipulator.cs (rev 0)
+++ branches/particles/AgateLib/Particles/Manipulators/GravityManipulator.cs 2009-05-01 12:27:42 UTC (rev 932)
@@ -0,0 +1,77 @@
+// The contents of this file are subject to the Mozilla Public License
+// Version 1.1 (the "License"); you may not use this file except in
+// compliance with the License. You may obtain a copy of the License at
+// http://www.mozilla.org/MPL/
+//
+// Software distributed under the License is distributed on an "AS IS"
+// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+// License for the specific language governing rights and limitations
+// under the License.
+//
+// The Original Code is AgateLib.Particles.
+//
+// The Initial Developer of the Original Code is Marcel Hauf
+// Portions created by Marcel Hauf are Copyright (C) 2009.
+// All Rights Reserved.
+//
+// Contributor(s): Marcel Hauf.
+//
+using System;
+using System.Collections.Generic;
+
+using AgateLib.Geometry;
+
+namespace AgateLib.Particles
+{
+ /// <summary>
+ /// A gravity particle manipulator.
+ /// </summary>
+ public class GravityManipulator
+ {
+ private float mStrength = 1f;
+ private Vector2 mPosition = Vector2.Empty;
+
+ /// <value>
+ /// Gets or sets the strength.
+ /// </value>
+ public float Strength
+ {
+ get { return mStrength; }
+ set { mStrength = value; }
+ }
+
+ /// <value>
+ /// Gets or sets the position.
+ /// </value>
+ public Vector2 Position
+ {
+ get { return mPosition; }
+ set { mPosition = value; }
+ }
+
+ /// <summary>
+ /// Constructs a gravitiy manipulator.
+ /// </summary>
+ /// <param name="position"></param>
+ /// <param name="strength"></param>
+ public GravityManipulator(Vector2 position, float strength)
+ {
+ mPosition = position;
+ mStrength = strength;
+ }
+
+ /// <summary>
+ /// Subscribe to a particle emitter.
+ /// </summary>
+ /// <param name="emitter"></param>
+ public void SubscribeToEmitter(ParticleEmitter emitter)
+ {
+ emitter.UpdateParticles += Manipulate;
+ }
+
+ internal void Manipulate(List<Particle> particles, float time_ms)
+ {
+ // TODO: add missing calculation to gravity manipulator
+ }
+ }
+}
Property changes on: branches/particles/AgateLib/Particles/Manipulators/GravityManipulator.cs
___________________________________________________________________
Added: svn:mergeinfo
+ /branches/agate-3d/AgateLib/Particles/GravityManipulator.cs:659
/branches/build/AgateLib/Particles/GravityManipulator.cs:447-517
/branches/font/AgateLib/Particles/GravityManipulator.cs:778-916
/branches/merge-tests/AgateLib/Particles/GravityManipulator.cs:806-810
/branches/registrar/AgateLib/Particles/GravityManipulator.cs:595-599
/branches/sprites/AgateLib/Particles/GravityManipulator.cs:463-513
Modified: branches/particles/AgateLib/Particles/Particle.cs
===================================================================
--- branches/particles/AgateLib/Particles/Particle.cs 2009-05-01 07:55:09 UTC (rev 931)
+++ branches/particles/AgateLib/Particles/Particle.cs 2009-05-01 12:27:42 UTC (rev 932)
@@ -32,8 +32,6 @@
private Condition mCondition = Condition.Empty;
private bool mIsDead = false;
- private ISurface mImage;
-
private Vector2 mAcceleration = Vector2.Empty;
private Vector2 mPosition = Vector2.Empty;
private Vector2 mVelocity = Vector2.Empty;
@@ -65,15 +63,6 @@
}
/// <value>
- /// Gets or sets the surface.
- /// </value>
- public ISurface Image
- {
- get { return mImage; }
- set { mImage = value; }
- }
-
- /// <value>
/// Gets or sets the acceleration.
/// </value>
public Vector2 Acceleration
@@ -98,14 +87,6 @@
{
get { return mVelocity; }
set { mVelocity = value; }
- }
-
- /// <summary>
- /// Draws the particle on screen.
- /// </summary>
- public virtual void Draw()
- {
- mImage.Draw(mPosition.X, mPosition.Y);
}
/// <summary>
Modified: branches/particles/AgateLib/Particles/ParticleEmitter.cs
===================================================================
--- branches/particles/AgateLib/Particles/ParticleEmitter.cs 2009-05-01 07:55:09 UTC (rev 931)
+++ branches/particles/AgateLib/Particles/ParticleEmitter.cs 2009-05-01 12:27:42 UTC (rev 932)
@@ -19,6 +19,7 @@
using System;
using System.Collections.Generic;
+using AgateLib.DisplayLib;
using AgateLib.Geometry;
namespace AgateLib.Particles
@@ -63,15 +64,11 @@
public UpdateParticles UpdateParticles;
/// <summary>
- /// Overridden draw method.
/// Draws each particle.
/// </summary>
- public override void Draw ()
+ public virtual void Draw ()
{
- mParticles.ForEach(delegate(Particle mParticle)
- {
- mParticle.Draw();
- });
+ // Draws particles
}
/// <summary>
Copied: branches/particles/AgateLib/Particles/Particles/PixelParticle.cs (from rev 931, branches/particles/AgateLib/Particles/PixelParticle.cs)
===================================================================
--- branches/particles/AgateLib/Particles/Particles/PixelParticle.cs (rev 0)
+++ branches/particles/AgateLib/Particles/Particles/PixelParticle.cs 2009-05-01 12:27:42 UTC (rev 932)
@@ -0,0 +1,53 @@
+// The contents of this file are subject to the Mozilla Public License
+// Version 1.1 (the "License"); you may not use this file except in
+// compliance with the License. You may obtain a copy of the License at
+// http://www.mozilla.org/MPL/
+//
+// Software distributed under the License is distributed on an "AS IS"
+// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+// License for the specific language governing rights and limitations
+// under the License.
+//
+// The Original Code is AgateLib.Particles.
+//
+// The Initial Developer of the Original Code is Marcel Hauf
+// Portions created by Marcel Hauf are Copyright (C) 2009.
+// All Rights Reserved.
+//
+// Contributor(s): Marcel Hauf.
+//
+using System;
+
+using AgateLib.DisplayLib;
+using AgateLib.Geometry;
+
+namespace AgateLib.Particles
+{
+ /// <summary>
+ /// A particle which draws one pixel.
+ /// </summary>
+ public class PixelParticle : Particle
+ {
+ private Color mColor = Color.White;
+
+ /// <value>
+ /// Gets or sets the color.
+ /// </value>
+ public Color Color
+ {
+ get { return mColor; }
+ set { mColor = value; }
+ }
+
+ /// <summary>
+ /// Constructs a PixelParticle.
+ /// </summary>
+ /// <param name="color">
+ /// The color of the particle.
+ /// </param>
+ public PixelParticle(Color color)
+ {
+ mColor = color;
+ }
+ }
+}
Property changes on: branches/particles/AgateLib/Particles/Particles/PixelParticle.cs
___________________________________________________________________
Added: svn:mergeinfo
+ /branches/agate-3d/AgateLib/Particles/PixelParticle.cs:659
/branches/build/AgateLib/Particles/PixelParticle.cs:447-517
/branches/font/AgateLib/Particles/PixelParticle.cs:778-916
/branches/merge-tests/AgateLib/Particles/PixelParticle.cs:806-810
/branches/registrar/AgateLib/Particles/PixelParticle.cs:595-599
/branches/sprites/AgateLib/Particles/PixelParticle.cs:463-513
Added: branches/particles/AgateLib/Particles/Particles/SurfaceParticle.cs
===================================================================
--- branches/particles/AgateLib/Particles/Particles/SurfaceParticle.cs (rev 0)
+++ branches/particles/AgateLib/Particles/Particles/SurfaceParticle.cs 2009-05-01 12:27:42 UTC (rev 932)
@@ -0,0 +1,16 @@
+
+using System;
+
+using AgateLib.DisplayLib;
+using AgateLib.Particles;
+
+namespace AgateLib.Particles
+{
+ public class SurfaceParticle : Particle
+ {
+ public SurfaceParticle(Surface image)
+ {
+
+ }
+ }
+}
Deleted: branches/particles/AgateLib/Particles/PixelParticle.cs
===================================================================
--- branches/particles/AgateLib/Particles/PixelParticle.cs 2009-05-01 07:55:09 UTC (rev 931)
+++ branches/particles/AgateLib/Particles/PixelParticle.cs 2009-05-01 12:27:42 UTC (rev 932)
@@ -1,57 +0,0 @@
-// The contents of this file are subject to the Mozilla Public License
-// Version 1.1 (the "License"); you may not use this file except in
-// compliance with the License. You may obtain a copy of the License at
-// http://www.mozilla.org/MPL/
-//
-// Software distributed under the License is distributed on an "AS IS"
-// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
-// License for the specific language governing rights and limitations
-// under the License.
-//
-// The Original Code is AgateLib.Particles.
-//
-// The Initial Developer of the Original Code is Marcel Hauf
-// Portions created by Marcel Hauf are Copyright (C) 2009.
-// All Rights Reserved.
-//
-// Contributor(s): Marcel Hauf.
-//
-using System;
-
-using AgateLib.DisplayLib;
-using AgateLib.Geometry;
-
-namespace AgateLib.Particles
-{
- /// <summary>
- /// A particle which draws one pixel.
- /// </summary>
- public class PixelParticle : Particle
- {
- internal PixelBuffer mPixelBuffer = new PixelBuffer(PixelFormat.Any, new Size(1,1));
-
- /// <value>
- /// Gets or sets the color.
- /// </value>
- public Color Color
- {
- get { return mPixelBuffer.GetPixel(0,0); }
- set {
- mPixelBuffer.SetPixel(0,0, value);
- base.Image = new Surface(mPixelBuffer);
- }
- }
-
- /// <summary>
- /// Constructs a PixelParticle.
- /// </summary>
- /// <param name="color">
- /// The color of the particle.
- /// </param>
- public PixelParticle(Color color)
- {
- mPixelBuffer.SetPixel(0,0, color);
- base.Image = new Surface(mPixelBuffer);
- }
- }
-}
Deleted: branches/particles/AgateLib/Particles/SampleEmitter.cs
===================================================================
--- branches/particles/AgateLib/Particles/SampleEmitter.cs 2009-05-01 07:55:09 UTC (rev 931)
+++ branches/particles/AgateLib/Particles/SampleEmitter.cs 2009-05-01 12:27:42 UTC (rev 932)
@@ -1,101 +0,0 @@
-
-using System;
-using System.Collections.Generic;
-
-using AgateLib.Geometry;
-
-namespace AgateLib.Particles
-{
- /// <summary>
- /// A particle emitter which emits copies of sample particles.
- /// </summary>
- public class SampleEmitter : ParticleEmitter
- {
- private int lastParticle = 0;
- private Random ran;
-
- private List<Particle> mSampleParticles;
-
- private EmitOrder mEmitOrder = EmitOrder.None;
-
- /// <value>
- /// Gets or sets the sample particles.
- /// </value>
- public List<Particle> SampleParticles
- {
- get { return mSampleParticles; }
- set { mSampleParticles = value; }
- }
-
- /// <value>
- /// Gets or sets the emit order.
- /// </value>
- public EmitOrder EmitOrder
- {
- get { return mEmitOrder; }
- set { mEmitOrder = value; }
- }
-
- /// <summary>
- /// Constructs a SampleEmitter with a sequenz emitting order
- /// and a default frequenzy.
- /// </summary>
- /// <param name="position"></param>
- public SampleEmitter(Vector2 position)
- {
- mSampleParticles = new List<Particle>();
- mEmitOrder = EmitOrder.Sequenz;
- base.Position = position;
- ran = new Random();
- }
-
- /// <summary>
- /// Overridden Update method.
- /// Emits new sample particle copies.
- /// Updates and manipulates each particle.
- /// </summary>
- /// <param name="time_ms">Passed time in milliseconds since last update.</param>
- public override void Update (float time_ms)
- {
- if(mSampleParticles.Count == 0)
- {
- base.Update(time_ms);
- return;
- }
-
- // TODO: add emit frequenzy
- switch(mEmitOrder)
- {
- case EmitOrder.None:
- break;
-
- case EmitOrder.Sequenz:
- base.Particles.Add(mSampleParticles[lastParticle]);
- if(lastParticle == mSampleParticles.Count - 1)
- {
- lastParticle = 0;
- }
- else
- {
- lastParticle++;
- }
- break;
-
- case EmitOrder.Random:
- base.Particles.Add(mSampleParticles[ran.Next(0, mSampleParticles.Count-1)]);
- break;
- }
- base.Update (time_ms);
- }
- }
-
- /// <summary>
- /// Emit order.
- /// </summary>
- public enum EmitOrder
- {
- None,
- Sequenz,
- Random
- }
-}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ka...@us...> - 2009-05-01 07:55:12
|
Revision: 931
http://agate.svn.sourceforge.net/agate/?rev=931&view=rev
Author: kanato
Date: 2009-05-01 07:55:09 +0000 (Fri, 01 May 2009)
Log Message:
-----------
Update vertex buffer so local state info is updated correctly.
Modified Paths:
--------------
branches/agate3d-3.2/Drivers/AgateMDX/MDX1_Display.cs
branches/agate3d-3.2/Drivers/AgateMDX/MDX1_IndexBuffer.cs
branches/agate3d-3.2/Drivers/AgateMDX/MDX1_VertexBuffer.cs
branches/agate3d-3.2/Tests/Display3D/Matrices.cs
Modified: branches/agate3d-3.2/Drivers/AgateMDX/MDX1_Display.cs
===================================================================
--- branches/agate3d-3.2/Drivers/AgateMDX/MDX1_Display.cs 2009-05-01 07:34:20 UTC (rev 930)
+++ branches/agate3d-3.2/Drivers/AgateMDX/MDX1_Display.cs 2009-05-01 07:55:09 UTC (rev 931)
@@ -120,7 +120,10 @@
mDevice = new D3DDevice(device);
-
+
+ mDevice.Device.RenderState.StencilEnable = false;
+ mDevice.Device.RenderState.ZBufferEnable = false;
+
// create primitive objects
mLine = new Direct3D.Line(device);
@@ -324,9 +327,6 @@
mDevice.Device.Viewport = view;
mCurrentClipRect = newClipRect;
- mDevice.Device.RenderState.StencilEnable = false;
- mDevice.Device.RenderState.ZBufferEnable = false;
-
SetOrthoProjection(newClipRect);
}
public override void PushClipRect(Rectangle newClipRect)
Modified: branches/agate3d-3.2/Drivers/AgateMDX/MDX1_IndexBuffer.cs
===================================================================
--- branches/agate3d-3.2/Drivers/AgateMDX/MDX1_IndexBuffer.cs 2009-05-01 07:34:20 UTC (rev 930)
+++ branches/agate3d-3.2/Drivers/AgateMDX/MDX1_IndexBuffer.cs 2009-05-01 07:55:09 UTC (rev 931)
@@ -24,6 +24,11 @@
CreateIndexBuffer();
}
+ public Direct3D.IndexBuffer DeviceIndexBuffer
+ {
+ get { return mBuffer; }
+ }
+
private void CreateIndexBuffer()
{
int indexSize = 2;
Modified: branches/agate3d-3.2/Drivers/AgateMDX/MDX1_VertexBuffer.cs
===================================================================
--- branches/agate3d-3.2/Drivers/AgateMDX/MDX1_VertexBuffer.cs 2009-05-01 07:34:20 UTC (rev 930)
+++ branches/agate3d-3.2/Drivers/AgateMDX/MDX1_VertexBuffer.cs 2009-05-01 07:55:09 UTC (rev 931)
@@ -173,14 +173,16 @@
SetTextures();
+
mDisplay.D3D_Device.Device.SetStreamSource(0, mBuffer, 0);
mDisplay.D3D_Device.Device.VertexDeclaration = mDeclaration;
mDisplay.D3D_Device.Device.DrawPrimitives(primType, start, primitiveCount);
}
- public override void DrawIndexed(IndexBuffer indexbuffer, int start, int count)
+ public override void DrawIndexed(IndexBuffer _indexbuffer, int start, int count)
{
int primitiveCount = count;
+ MDX1_IndexBuffer indexbuffer = _indexbuffer.Impl as MDX1_IndexBuffer;
// after calling GetPrimitiveType, count is the number of primitives
// instead of the number of vertices.
@@ -188,9 +190,12 @@
SetTextures();
+ mDisplay.D3D_Device.Device.Indices = indexbuffer.DeviceIndexBuffer;
mDisplay.D3D_Device.Device.SetStreamSource(0, mBuffer, 0);
+ mDisplay.D3D_Device.VertexFormat = mFormats;
mDisplay.D3D_Device.Device.VertexDeclaration = mDeclaration;
- mDisplay.D3D_Device.Device.DrawIndexedPrimitives(primType, start, 0, count, 0, primitiveCount);
+ mDisplay.D3D_Device.Device.DrawIndexedPrimitives(primType, 0, 0, count, start, primitiveCount);
+
}
private void SetTextures()
Modified: branches/agate3d-3.2/Tests/Display3D/Matrices.cs
===================================================================
--- branches/agate3d-3.2/Tests/Display3D/Matrices.cs 2009-05-01 07:34:20 UTC (rev 930)
+++ branches/agate3d-3.2/Tests/Display3D/Matrices.cs 2009-05-01 07:55:09 UTC (rev 931)
@@ -153,13 +153,10 @@
}
Display.DrawRect(new Rectangle(0, 0, 8, 8), Color.Black);
-
b.DrawIndexed(indices);
Display.EndFrame();
Core.KeepAlive();
-
-
}
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ka...@us...> - 2009-05-01 07:34:25
|
Revision: 930
http://agate.svn.sourceforge.net/agate/?rev=930&view=rev
Author: kanato
Date: 2009-05-01 07:34:20 +0000 (Fri, 01 May 2009)
Log Message:
-----------
Update AgateMDX with vertex/index buffer support. Not working right yet.
Modified Paths:
--------------
branches/agate3d-3.2/AgateLib/DisplayLib/IndexBuffer.cs
branches/agate3d-3.2/Drivers/AgateMDX/D3DDevice.cs
branches/agate3d-3.2/Drivers/AgateMDX/MDX1_Display.cs
branches/agate3d-3.2/Drivers/AgateMDX/MDX1_Surface.cs
branches/agate3d-3.2/Drivers/AgateMDX/MDX1_VertexBuffer.cs
branches/agate3d-3.2/Drivers/AgateOTK/GL_IndexBuffer.cs
branches/agate3d-3.2/Tests/Display3D/Matrices.cs
Added Paths:
-----------
branches/agate3d-3.2/Drivers/AgateMDX/MDX1_IndexBuffer.cs
Modified: branches/agate3d-3.2/AgateLib/DisplayLib/IndexBuffer.cs
===================================================================
--- branches/agate3d-3.2/AgateLib/DisplayLib/IndexBuffer.cs 2009-05-01 02:16:20 UTC (rev 929)
+++ branches/agate3d-3.2/AgateLib/DisplayLib/IndexBuffer.cs 2009-05-01 07:34:20 UTC (rev 930)
@@ -17,13 +17,63 @@
public void WriteIndices(short[] indices)
{
+ if (impl.IndexType == IndexBufferType.Int32)
+ {
+ WriteIndices(ConvertToInt32(indices));
+ return;
+ }
+
impl.WriteIndices(indices);
}
public void WriteIndices(int[] indices)
{
+ if (impl.IndexType == IndexBufferType.Int16)
+ {
+ WriteIndices(ConvertToInt16(indices));
+ return;
+ }
+
impl.WriteIndices(indices);
}
+ private short[] ConvertToInt16(int[] indices)
+ {
+ short[] retval = new short[indices.Length];
+
+ int i = 0;
+
+ try
+ {
+ checked
+ {
+ for (i = 0; i < retval.Length; i++)
+ {
+ retval[i] = (short)indices[i];
+ }
+ }
+ }
+ catch (OverflowException ex)
+ {
+ throw new AgateLib.AgateException(ex, string.Format(
+ "A 16 bit index buffer cannot contain values greater than {0}, " +
+ "but there is a value of {1} at index {2}.",
+ short.MaxValue, indices[i], i));
+ }
+
+ return retval;
+ }
+ private int[] ConvertToInt32(short[] indices)
+ {
+ int[] retval = new int[indices.Length];
+
+ for (int i = 0; i < retval.Length; i++)
+ {
+ retval[i] = (short)indices[i];
+ }
+
+ return retval;
+ }
+
public int Count
{
get { return impl.Count; }
Modified: branches/agate3d-3.2/Drivers/AgateMDX/D3DDevice.cs
===================================================================
--- branches/agate3d-3.2/Drivers/AgateMDX/D3DDevice.cs 2009-05-01 02:16:20 UTC (rev 929)
+++ branches/agate3d-3.2/Drivers/AgateMDX/D3DDevice.cs 2009-05-01 07:34:20 UTC (rev 930)
@@ -32,7 +32,7 @@
public class D3DDevice : IDisposable
{
private Device mDevice;
- private Texture mLastTexture;
+ private Texture[] mLastTexture = new Texture[8];
private MDX1_IRenderTarget mRenderTarget;
private DrawBuffer mDrawBuffer;
@@ -46,6 +46,7 @@
private int mMaxLightsUsed = 0;
+
//VertexBuffer mSurfaceVB;
//const int NumVertices = 1000;
//int mSurfaceVBPointer = 0;
@@ -256,13 +257,16 @@
public void SetDeviceStateTexture(Texture texture)
{
-
- if (texture == mLastTexture)
+ SetDeviceStateTexture(texture, 0);
+ }
+ public void SetDeviceStateTexture(Texture texture, int index)
+ {
+ if (texture == mLastTexture[index])
return;
- mDevice.SetTexture(0, texture);
+ mDevice.SetTexture(index, texture);
- mLastTexture = texture;
+ mLastTexture[index] = texture;
if (texture != null)
{
@@ -349,7 +353,7 @@
mDevice.RenderState.AmbientMaterialSource = ColorSource.Color1;
mDevice.RenderState.AmbientColor = lights.Ambient.ToArgb();
-
+
//Material mat = new Material();
//mat.Diffuse = System.Drawing.Color.White;
Modified: branches/agate3d-3.2/Drivers/AgateMDX/MDX1_Display.cs
===================================================================
--- branches/agate3d-3.2/Drivers/AgateMDX/MDX1_Display.cs 2009-05-01 02:16:20 UTC (rev 929)
+++ branches/agate3d-3.2/Drivers/AgateMDX/MDX1_Display.cs 2009-05-01 07:34:20 UTC (rev 930)
@@ -53,6 +53,10 @@
private bool mVSync = true;
+ private bool mHasDepth , mHasStencil;
+ private float mDepthClear = 0;
+ private int mStencilClear = 0;
+
#endregion
#region --- Creation / Destruction ---
@@ -96,20 +100,55 @@
if (caps.DeviceCaps.SupportsPureDevice)
flags |= Direct3D.CreateFlags.PureDevice;
- Device device = new Device
- (0, dtype, window.RenderTarget.TopLevelControl.Handle,
- flags, present);
+ Device device = new Device(0, dtype,
+ window.RenderTarget.TopLevelControl.Handle,
+ flags, present);
+ try
+ {
+ DepthFormat f = (DepthFormat)device.DepthStencilSurface.Description.Format;
+ SetHaveDepthStencil(f);
+ }
+ catch
+ {
+ mHasDepth = false;
+ mHasStencil = false;
+ }
+
device.DeviceLost += new EventHandler(mDevice_DeviceLost);
device.DeviceReset += new EventHandler(mDevice_DeviceReset);
mDevice = new D3DDevice(device);
+
// create primitive objects
mLine = new Direct3D.Line(device);
- //CreateSurfaceVB();
+ }
+ private void SetHaveDepthStencil(DepthFormat depthFormat)
+ {
+ switch (depthFormat)
+ {
+ case DepthFormat.D24X4S4:
+ case DepthFormat.D24S8:
+ case DepthFormat.D15S1:
+ mHasStencil = true;
+ mHasDepth = true;
+ break;
+
+ case DepthFormat.D24X8:
+ case DepthFormat.D32:
+ case DepthFormat.D16:
+ mHasStencil = false;
+ mHasDepth = true;
+ break;
+
+ default:
+ mHasDepth = false;
+ mHasStencil = false;
+ break;
+ }
}
public override void Dispose()
@@ -195,15 +234,6 @@
#region --- Creation of objects ---
- //public override DisplayWindowImpl CreateDisplayWindow(string title, int clientWidth, int clientHeight,
- // string iconFile, bool startFullScreen, bool allowResize)
- //{
- // return new MDX1_DisplayWindow(title, clientWidth, clientHeight, iconFile, startFullScreen, allowResize);
- //}
- //public override DisplayWindowImpl CreateDisplayWindow(System.Windows.Forms.Control renderTarget)
- //{
- // return new MDX1_DisplayWindow(renderTarget);
- //}
public override DisplayWindowImpl CreateDisplayWindow(CreateWindowParams windowParams)
{
return new MDX1_DisplayWindow(windowParams);
@@ -252,12 +282,10 @@
while (mClipRects.Count > 0)
PopClipRect();
-
mRenderTarget.EndRender();
}
-
#endregion
#region --- Clip Rect stuff ---
@@ -295,6 +323,9 @@
mDevice.Device.Viewport = view;
mCurrentClipRect = newClipRect;
+
+ mDevice.Device.RenderState.StencilEnable = false;
+ mDevice.Device.RenderState.ZBufferEnable = false;
SetOrthoProjection(newClipRect);
}
@@ -307,9 +338,7 @@
{
if (mClipRects.Count == 0)
{
-#if DEBUG
throw new Exception("You have popped the cliprect too many times.");
-#endif
}
else
{
@@ -323,11 +352,23 @@
#endregion
#region --- Methods for drawing to the back buffer ---
+ ClearFlags ClearFlags
+ {
+ get
+ {
+ ClearFlags retval = ClearFlags.Target;
+
+ if (mHasDepth) retval |= ClearFlags.ZBuffer;
+ if (mHasStencil) retval |= ClearFlags.Stencil;
+
+ return retval;
+ }
+ }
public override void Clear(Color color)
{
mDevice.DrawBuffer.Flush();
- mDevice.Clear(ClearFlags.Target, color.ToArgb(), 1.0f, 0);
+ mDevice.Clear(ClearFlags, color.ToArgb(), mDepthClear, mStencilClear);
}
public override void Clear(Color color, Rectangle rect)
{
@@ -336,7 +377,7 @@
System.Drawing.Rectangle[] rects = new System.Drawing.Rectangle[1];
rects[0] = Interop.Convert(rect);
- mDevice.Clear(ClearFlags.Target, color.ToArgb(), 1.0f, 0, rects);
+ mDevice.Clear(ClearFlags, color.ToArgb(), mDepthClear, mStencilClear, rects);
}
@@ -504,22 +545,12 @@
private PresentParameters CreateFullScreenPresentParameters(MDX1_DisplayWindow displayWindow,
int width, int height, int bpp)
{
- PresentParameters present = new PresentParameters();
+ PresentParameters present = CreateBasePresentParams(displayWindow);
- present.AutoDepthStencilFormat = DepthFormat.Unknown;
- present.EnableAutoDepthStencil = false;
- present.DeviceWindowHandle = displayWindow.RenderTarget.Handle;
- present.BackBufferWidth = width;
- present.BackBufferHeight = height;
present.SwapEffect = SwapEffect.Flip;
present.Windowed = false;
present.PresentFlag = PresentFlag.None;
- if (VSync)
- present.PresentationInterval = PresentInterval.Default;
- else
- present.PresentationInterval = PresentInterval.Immediate;
-
SelectBestDisplayMode(present, bpp);
return present;
@@ -528,16 +559,23 @@
private PresentParameters CreateWindowedPresentParameters(MDX1_DisplayWindow displayWindow,
int width, int height)
{
+ PresentParameters present = CreateBasePresentParams(displayWindow);
+
+ return present;
+ }
+
+ private PresentParameters CreateBasePresentParams(MDX1_DisplayWindow displayWindow)
+ {
PresentParameters present = new PresentParameters();
present.BackBufferCount = 1;
- present.AutoDepthStencilFormat = DepthFormat.Unknown;
- present.EnableAutoDepthStencil = false;
+ present.AutoDepthStencilFormat = GetDepthFormat(Format.A8R8G8B8);
+ present.EnableAutoDepthStencil = true;
present.DeviceWindowHandle = displayWindow.RenderTarget.Handle;
- present.BackBufferWidth = width;
- present.BackBufferHeight = height;
+ present.BackBufferWidth = displayWindow.Width;
+ present.BackBufferHeight = displayWindow.Height;
present.BackBufferFormat = Format.Unknown;
- present.SwapEffect = SwapEffect.Copy;
+ present.SwapEffect = SwapEffect.Discard;
present.Windowed = true;
present.PresentFlag = PresentFlag.LockableBackBuffer;
@@ -548,6 +586,52 @@
return present;
}
+ private DepthFormat GetDepthFormat(Format backbufferFormat)
+ {
+ DepthFormat[] formats = new DepthFormat[]
+ {
+ DepthFormat.D24S8,
+ DepthFormat.D24X4S4,
+ DepthFormat.D24X8,
+ DepthFormat.D15S1,
+ DepthFormat.D32,
+ DepthFormat.D16,
+ };
+
+ var adapter = Manager.Adapters.Default.Adapter;
+ Format deviceFormat = GetDeviceFormat(backbufferFormat);
+
+ foreach (var f in formats)
+ {
+ if (Manager.CheckDeviceFormat(adapter, DeviceType.Hardware, deviceFormat,
+ Usage.DepthStencil, ResourceType.Surface, f) == false)
+ {
+ continue;
+ }
+ if (Manager.CheckDepthStencilMatch(adapter, DeviceType.Hardware,
+ deviceFormat, backbufferFormat, f) == false)
+ {
+ continue;
+ }
+
+ return f;
+ }
+
+ return DepthFormat.Unknown;
+ }
+ private Format GetDeviceFormat(Format backbufferFormat)
+ {
+ switch (backbufferFormat)
+ {
+ case Format.A8R8G8B8: return Format.X8R8G8B8;
+ case Format.A8B8G8R8: return Format.X8B8G8R8;
+ case Format.A1R5G5B5: return Format.X1R5G5B5;
+
+ default:
+ return backbufferFormat;
+ }
+ }
+
public override ScreenMode[] EnumScreenModes()
{
List<ScreenMode> modes = new List<ScreenMode>();
@@ -839,11 +923,15 @@
Matrix4 world = Matrix4.Identity;
Matrix4 view = Matrix4.Identity;
- // TODO: Fix this
- protected override VertexBufferImpl CreateVertexBuffer(VertexLayout layout, int vertexCount)
+ protected override VertexBufferImpl CreateVertexBuffer(
+ AgateLib.Geometry.VertexTypes.VertexLayout layout, int vertexCount)
{
- return new MDX1_VertexBuffer(this);
+ return new MDX1_VertexBuffer(this, layout, vertexCount);
}
+ protected override IndexBufferImpl CreateIndexBuffer(IndexBufferType type, int size)
+ {
+ return new MDX1_IndexBuffer(this, type, size);
+ }
private Matrix TransformAgateMatrix(Matrix4 value)
{
Added: branches/agate3d-3.2/Drivers/AgateMDX/MDX1_IndexBuffer.cs
===================================================================
--- branches/agate3d-3.2/Drivers/AgateMDX/MDX1_IndexBuffer.cs (rev 0)
+++ branches/agate3d-3.2/Drivers/AgateMDX/MDX1_IndexBuffer.cs 2009-05-01 07:34:20 UTC (rev 930)
@@ -0,0 +1,62 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using AgateLib.DisplayLib;
+using AgateLib.ImplementationBase;
+using Direct3D = Microsoft.DirectX.Direct3D;
+
+namespace AgateMDX
+{
+ class MDX1_IndexBuffer : IndexBufferImpl
+ {
+ MDX1_Display mDisplay;
+ IndexBufferType mType;
+ int mCount;
+ Direct3D.IndexBuffer mBuffer;
+
+ public MDX1_IndexBuffer(MDX1_Display disp, IndexBufferType type, int count)
+ {
+ mDisplay = disp;
+ mType = type;
+ mCount = count;
+
+ CreateIndexBuffer();
+ }
+
+ private void CreateIndexBuffer()
+ {
+ int indexSize = 2;
+
+ if (IndexType == IndexBufferType.Int32)
+ indexSize = 4;
+
+ mBuffer = new Microsoft.DirectX.Direct3D.IndexBuffer(
+ mDisplay.D3D_Device.Device,
+ mCount * indexSize,
+ Microsoft.DirectX.Direct3D.Usage.WriteOnly,
+ Microsoft.DirectX.Direct3D.Pool.Managed,
+ IndexType == IndexBufferType.Int16);
+ }
+
+ public override int Count
+ {
+ get { return mCount; }
+ }
+
+ public override AgateLib.DisplayLib.IndexBufferType IndexType
+ {
+ get { return mType; }
+ }
+
+ public override void WriteIndices(int[] indices)
+ {
+ mBuffer.SetData(indices, 0, Microsoft.DirectX.Direct3D.LockFlags.Discard);
+ }
+
+ public override void WriteIndices(short[] indices)
+ {
+ mBuffer.SetData(indices, 0, Microsoft.DirectX.Direct3D.LockFlags.Discard);
+ }
+ }
+}
Modified: branches/agate3d-3.2/Drivers/AgateMDX/MDX1_Surface.cs
===================================================================
--- branches/agate3d-3.2/Drivers/AgateMDX/MDX1_Surface.cs 2009-05-01 02:16:20 UTC (rev 929)
+++ branches/agate3d-3.2/Drivers/AgateMDX/MDX1_Surface.cs 2009-05-01 07:34:20 UTC (rev 930)
@@ -65,6 +65,11 @@
#endregion
+ public Texture D3dTexture
+ {
+ get { return mTexture.Value; }
+ }
+
#region --- TextureCoordinates structure ---
struct TextureCoordinates
Modified: branches/agate3d-3.2/Drivers/AgateMDX/MDX1_VertexBuffer.cs
===================================================================
--- branches/agate3d-3.2/Drivers/AgateMDX/MDX1_VertexBuffer.cs 2009-05-01 02:16:20 UTC (rev 929)
+++ branches/agate3d-3.2/Drivers/AgateMDX/MDX1_VertexBuffer.cs 2009-05-01 07:34:20 UTC (rev 930)
@@ -2,7 +2,9 @@
using System.Collections.Generic;
using System.Text;
using AgateLib;
+using AgateLib.DisplayLib;
using AgateLib.Geometry;
+using AgateLib.Geometry.VertexTypes;
using AgateLib.ImplementationBase;
using Direct3D = Microsoft.DirectX.Direct3D;
@@ -11,50 +13,209 @@
class MDX1_VertexBuffer : VertexBufferImpl
{
MDX1_Display mDisplay;
+ Direct3D.VertexBuffer mBuffer;
+ Direct3D.VertexDeclaration mDeclaration;
+ Direct3D.VertexFormats mFormats;
+ int mCount;
- public MDX1_VertexBuffer(MDX1_Display display)
+ public MDX1_VertexBuffer(MDX1_Display display, VertexLayout layout, int vertexCount)
{
mDisplay = display;
+ mCount = vertexCount;
+
+ mDeclaration = CreateVertexDeclaration(layout);
+ mFormats = CreateVertexFormats(layout);
+
+ mBuffer = new Microsoft.DirectX.Direct3D.VertexBuffer(
+ mDisplay.D3D_Device.Device,
+ vertexCount * layout.VertexSize,
+ Microsoft.DirectX.Direct3D.Usage.WriteOnly,
+ mFormats,
+ Direct3D.Pool.Managed);
}
+ private Direct3D.VertexFormats CreateVertexFormats(VertexLayout layout)
+ {
+ Direct3D.VertexFormats retval = Microsoft.DirectX.Direct3D.VertexFormats.None;
- public override void WriteNormalData(Vector3[] data)
- {
- throw new NotImplementedException();
+ foreach (var element in layout)
+ {
+ switch (element.ElementType)
+ {
+ case VertexElement.Position:
+ retval |= Microsoft.DirectX.Direct3D.VertexFormats.Position;
+ break;
+
+ case VertexElement.Texture:
+ retval |= Microsoft.DirectX.Direct3D.VertexFormats.Texture0;
+ break;
+
+ case VertexElement.Texture1:
+ retval |= Microsoft.DirectX.Direct3D.VertexFormats.Texture1;
+ break;
+
+ case VertexElement.Texture2:
+ retval |= Microsoft.DirectX.Direct3D.VertexFormats.Texture2;
+ break;
+
+ case VertexElement.Texture3:
+ retval |= Microsoft.DirectX.Direct3D.VertexFormats.Texture3;
+ break;
+
+ case VertexElement.Color:
+ retval |= Microsoft.DirectX.Direct3D.VertexFormats.Diffuse;
+ break;
+ }
+ }
+
+ return retval;
}
- public override void WriteTextureCoords(Vector2[] texCoords)
+ private Direct3D.VertexDeclaration CreateVertexDeclaration(VertexLayout layout)
{
- throw new NotImplementedException();
+ List<Direct3D.VertexElement> formats = new List<Microsoft.DirectX.Direct3D.VertexElement>();
+
+ for (int i = 0; i < layout.Count; i++)
+ {
+ var element = layout[i];
+ short loc = 0;
+ int size;
+
+ Direct3D.VertexElement d3d_element = ConvertElement(element, out size);
+ d3d_element.Offset = loc;
+ loc += (short)size;
+ }
+
+ formats.Add(Direct3D.VertexElement.VertexDeclarationEnd);
+
+ return new Direct3D.VertexDeclaration(
+ mDisplay.D3D_Device.Device, formats.ToArray());
}
- public override void WriteVertexData(Vector3[] data)
+ private Direct3D.VertexElement ConvertElement(VertexElementDesc element, out int size)
{
- throw new NotImplementedException();
+ Direct3D.DeclarationType declType;
+ Direct3D.DeclarationMethod declMethod = Microsoft.DirectX.Direct3D.DeclarationMethod.Default;
+ Direct3D.DeclarationUsage declUsage;
+
+ switch(element.DataType)
+ {
+ case VertexElementDataType.Float1:
+ declType = Microsoft.DirectX.Direct3D.DeclarationType.Float1;
+ break;
+ case VertexElementDataType.Float2:
+ declType = Microsoft.DirectX.Direct3D.DeclarationType.Float2;
+ break;
+ case VertexElementDataType.Float3:
+ declType = Microsoft.DirectX.Direct3D.DeclarationType.Float3;
+ break;
+ case VertexElementDataType.Float4:
+ declType = Microsoft.DirectX.Direct3D.DeclarationType.Float4;
+ break;
+ default:
+ throw new NotImplementedException(
+ element.DataType.ToString() + " not implemented.");
+ }
+
+ size = VertexLayout.SizeOf(element.DataType);
+
+ switch(element.ElementType)
+ {
+ case VertexElement.Position:
+ declUsage = Microsoft.DirectX.Direct3D.DeclarationUsage.Position;
+ break;
+ case VertexElement.Texture:
+ declUsage = Microsoft.DirectX.Direct3D.DeclarationUsage.TextureCoordinate;
+ break;
+ case VertexElement.Normal:
+ declUsage = Microsoft.DirectX.Direct3D.DeclarationUsage.Normal;
+ break;
+ case VertexElement.Tangent:
+ declUsage = Microsoft.DirectX.Direct3D.DeclarationUsage.Tangent;
+ break;
+ case VertexElement.Color:
+ declUsage = Microsoft.DirectX.Direct3D.DeclarationUsage.Color;
+ break;
+ case VertexElement.Bitangent:
+ declUsage = Microsoft.DirectX.Direct3D.DeclarationUsage.BiNormal;
+ break;
+ default:
+ throw new NotImplementedException(
+ element.ElementType.ToString() + " not implemented.");
+ }
+
+ return new Direct3D.VertexElement(0, 0, declType, declMethod, declUsage, 0);
}
- public override void WriteIndices(short[] indices)
+
+ private Direct3D.PrimitiveType GetPrimitiveType(ref int vertexCount)
{
- throw new NotImplementedException();
+ switch (this.PrimitiveType)
+ {
+ case PrimitiveType.TriangleFan:
+ vertexCount = vertexCount - 2;
+ return Microsoft.DirectX.Direct3D.PrimitiveType.TriangleFan;
+ case PrimitiveType.TriangleList:
+ vertexCount /= 3;
+ return Microsoft.DirectX.Direct3D.PrimitiveType.TriangleList;
+ case PrimitiveType.TriangleStrip:
+ vertexCount = vertexCount - 2;
+ return Microsoft.DirectX.Direct3D.PrimitiveType.TriangleStrip;
+ default:
+ throw new NotImplementedException(this.PrimitiveType.ToString() + " not implemented.");
+ }
}
- public override void Draw(int vertexStart, int vertexCount)
+ public override void Draw(int start, int count)
{
- throw new NotImplementedException();
+ int primitiveCount = count;
+
+ // after calling GetPrimitiveType, primitiveCount is the number of primitives
+ // instead of the number of vertices.
+ Direct3D.PrimitiveType primType = GetPrimitiveType(ref primitiveCount);
+
+ SetTextures();
+
+ mDisplay.D3D_Device.Device.SetStreamSource(0, mBuffer, 0);
+ mDisplay.D3D_Device.Device.VertexDeclaration = mDeclaration;
+ mDisplay.D3D_Device.Device.DrawPrimitives(primType, start, primitiveCount);
}
+ public override void DrawIndexed(IndexBuffer indexbuffer, int start, int count)
+ {
+ int primitiveCount = count;
- public override int IndexCount
+ // after calling GetPrimitiveType, count is the number of primitives
+ // instead of the number of vertices.
+ Direct3D.PrimitiveType primType = GetPrimitiveType(ref primitiveCount);
+
+ SetTextures();
+
+ mDisplay.D3D_Device.Device.SetStreamSource(0, mBuffer, 0);
+ mDisplay.D3D_Device.Device.VertexDeclaration = mDeclaration;
+ mDisplay.D3D_Device.Device.DrawIndexedPrimitives(primType, start, 0, count, 0, primitiveCount);
+ }
+
+ private void SetTextures()
{
- get { return 0; }
+ for (int i = 0; i < Textures.Count; i++)
+ {
+ if (Textures[i] == null)
+ mDisplay.D3D_Device.SetDeviceStateTexture(null, i);
+ else
+ {
+ MDX1_Surface surf = (MDX1_Surface)Textures[i].Impl;
+
+ mDisplay.D3D_Device.SetDeviceStateTexture(surf.D3dTexture, i);
+ }
+ }
}
public override int VertexCount
{
- get { return 0; }
+ get { return mCount; }
}
-
- public override void WriteAttributeData(string attributeName, Vector3[] data)
+ public override void Write<T>(T[] vertices)
{
- throw new NotImplementedException();
+ mBuffer.SetData(vertices, 0, Microsoft.DirectX.Direct3D.LockFlags.Discard);
}
}
}
Modified: branches/agate3d-3.2/Drivers/AgateOTK/GL_IndexBuffer.cs
===================================================================
--- branches/agate3d-3.2/Drivers/AgateOTK/GL_IndexBuffer.cs 2009-05-01 02:16:20 UTC (rev 929)
+++ branches/agate3d-3.2/Drivers/AgateOTK/GL_IndexBuffer.cs 2009-05-01 07:34:20 UTC (rev 930)
@@ -46,33 +46,6 @@
GL.BindBuffer(BufferTarget.ElementArrayBuffer, mBufferID);
}
- private short[] ConvertToInt16(int[] indices)
- {
- short[] retval = new short[indices.Length];
-
- int i = 0;
-
- try
- {
- checked
- {
- for (i = 0; i < retval.Length; i++)
- {
- retval[i] = (short)indices[i];
- }
- }
- }
- catch (OverflowException ex)
- {
- throw new AgateLib.AgateException(ex, string.Format(
- "A 16 bit index buffer cannot contain values greater than {0}, " +
- "but there is a value of {1} at index {2}.",
- short.MaxValue, indices[i], i));
- }
-
- return retval;
- }
-
unsafe public override void WriteIndices(int[] indices)
{
if (indices.Length != Count)
@@ -80,10 +53,8 @@
"The size of the passed array must match the size of the index buffer.");
if (mType == IndexBufferType.Int16)
- {
- WriteIndices(ConvertToInt16(indices));
- return;
- }
+ throw new ArgumentException(
+ "Cannot write 32-bit data to a 16-bit buffer.");
Bind();
Modified: branches/agate3d-3.2/Tests/Display3D/Matrices.cs
===================================================================
--- branches/agate3d-3.2/Tests/Display3D/Matrices.cs 2009-05-01 02:16:20 UTC (rev 929)
+++ branches/agate3d-3.2/Tests/Display3D/Matrices.cs 2009-05-01 07:34:20 UTC (rev 930)
@@ -30,6 +30,7 @@
}
#endregion
+
static int matrixIndex = 1;
static int move, turn;
@@ -58,6 +59,7 @@
cube.Location = new Vector3(cube.Length / 2, cube.Length / 2, 0);
cube.CreateVertexBuffer();
+ IndexBuffer indices = cube.IndexBuffer;
VertexBuffer b = cube.VertexBuffer;
b.Textures[0] = surf;
@@ -111,7 +113,7 @@
break;
case 1:
- myproj = Matrix4.Projection(45, wind.Width / (float)wind.Height, 1f, 1000);
+ myproj = Matrix4.Projection(45, wind.Width / (float)wind.Height, 1f, 1000f);
myview = Matrix4.LookAt(position, lookTarget,
new Vector3(0, 0, 1));
@@ -136,7 +138,7 @@
Display.MatrixWorld = Matrix4.Translation(0, 0, 0);
m[0].Position = position;
- m.DoLighting();
+ //m.DoLighting();
// draw a weird checkerboard
for (int x = 0; x < 8; x += 2)
@@ -152,7 +154,7 @@
Display.DrawRect(new Rectangle(0, 0, 8, 8), Color.Black);
- b.Draw();
+ b.DrawIndexed(indices);
Display.EndFrame();
Core.KeepAlive();
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ka...@us...> - 2009-05-01 02:16:30
|
Revision: 929
http://agate.svn.sourceforge.net/agate/?rev=929&view=rev
Author: kanato
Date: 2009-05-01 02:16:20 +0000 (Fri, 01 May 2009)
Log Message:
-----------
Make CubeBuilder write tangent and bitangent vectors.
Modified Paths:
--------------
branches/agate3d-3.2/AgateLib/Geometry/Builders/Cube.cs
Modified: branches/agate3d-3.2/AgateLib/Geometry/Builders/Cube.cs
===================================================================
--- branches/agate3d-3.2/AgateLib/Geometry/Builders/Cube.cs 2009-04-29 18:28:26 UTC (rev 928)
+++ branches/agate3d-3.2/AgateLib/Geometry/Builders/Cube.cs 2009-05-01 02:16:20 UTC (rev 929)
@@ -60,6 +60,8 @@
GenerateVertexData(vertices);
GenerateNormalData(vertices);
GenerateTexCoordData(vertices);
+ GenerateTangentData(vertices);
+ GenerateBitangentData(vertices);
mVertices.WriteVertexData(vertices);
mIndices.WriteIndices(GetIndexData());
@@ -88,7 +90,7 @@
return retval;
}
- private Vector3[] GetBitangent()
+ private void GenerateBitangentData(PositionTextureNTB[] vertices)
{
Vector3[] retval = new Vector3[24];
@@ -96,50 +98,44 @@
for (int sign = -1; sign >= 1; sign += 2)
{
- retval[i++] = new Vector3(0, sign, 0);
- retval[i++] = new Vector3(0, sign, 0);
- retval[i++] = new Vector3(0, sign, 0);
- retval[i++] = new Vector3(0, sign, 0);
+ vertices[i++].Bitangent = new Vector3(0, sign, 0);
+ vertices[i++].Bitangent = new Vector3(0, sign, 0);
+ vertices[i++].Bitangent = new Vector3(0, sign, 0);
+ vertices[i++].Bitangent = new Vector3(0, sign, 0);
- retval[i++] = new Vector3(sign, 0, 0);
- retval[i++] = new Vector3(sign, 0, 0);
- retval[i++] = new Vector3(sign, 0, 0);
- retval[i++] = new Vector3(sign, 0, 0);
+ vertices[i++].Bitangent = new Vector3(sign, 0, 0);
+ vertices[i++].Bitangent = new Vector3(sign, 0, 0);
+ vertices[i++].Bitangent = new Vector3(sign, 0, 0);
+ vertices[i++].Bitangent = new Vector3(sign, 0, 0);
- retval[i++] = new Vector3(0, 0, sign);
- retval[i++] = new Vector3(0, 0, sign);
- retval[i++] = new Vector3(0, 0, sign);
- retval[i++] = new Vector3(0, 0, sign);
+ vertices[i++].Bitangent = new Vector3(0, 0, sign);
+ vertices[i++].Bitangent = new Vector3(0, 0, sign);
+ vertices[i++].Bitangent = new Vector3(0, 0, sign);
+ vertices[i++].Bitangent = new Vector3(0, 0, sign);
}
-
- return retval;
}
- private Vector3[] GetTangent()
+ private void GenerateTangentData(PositionTextureNTB[] vertices)
{
- Vector3[] retval = new Vector3[24];
-
int i = 0;
for (int sign = -1; sign <= 1; sign += 2)
{
- retval[i++] = new Vector3(sign, 0, 0);
- retval[i++] = new Vector3(sign, 0, 0);
- retval[i++] = new Vector3(sign, 0, 0);
- retval[i++] = new Vector3(sign, 0, 0);
+ vertices[i++].Tangent = new Vector3(sign, 0, 0);
+ vertices[i++].Tangent = new Vector3(sign, 0, 0);
+ vertices[i++].Tangent = new Vector3(sign, 0, 0);
+ vertices[i++].Tangent = new Vector3(sign, 0, 0);
- retval[i++] = new Vector3(0, 0, sign);
- retval[i++] = new Vector3(0, 0, sign);
- retval[i++] = new Vector3(0, 0, sign);
- retval[i++] = new Vector3(0, 0, sign);
+ vertices[i++].Tangent = new Vector3(0, 0, sign);
+ vertices[i++].Tangent = new Vector3(0, 0, sign);
+ vertices[i++].Tangent = new Vector3(0, 0, sign);
+ vertices[i++].Tangent = new Vector3(0, 0, sign);
- retval[i++] = new Vector3(0, sign, 0);
- retval[i++] = new Vector3(0, sign, 0);
- retval[i++] = new Vector3(0, sign, 0);
- retval[i++] = new Vector3(0, sign, 0);
+ vertices[i++].Tangent = new Vector3(0, sign, 0);
+ vertices[i++].Tangent = new Vector3(0, sign, 0);
+ vertices[i++].Tangent = new Vector3(0, sign, 0);
+ vertices[i++].Tangent = new Vector3(0, sign, 0);
}
-
- return retval;
}
private void GenerateNormalData(PositionTextureNTB[] vertices)
{
@@ -164,8 +160,6 @@
vertices[i++].Normal = new Vector3(sign, 0, 0);
}
}
-
-
private void GenerateVertexData(PositionTextureNTB[] vertices)
{
int i = 0;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ac...@us...> - 2009-04-29 18:28:32
|
Revision: 928
http://agate.svn.sourceforge.net/agate/?rev=928&view=rev
Author: accagon
Date: 2009-04-29 18:28:26 +0000 (Wed, 29 Apr 2009)
Log Message:
-----------
* SampleEmitter.cs: Add missing name changes, fix for wrong function name
Modified Paths:
--------------
branches/particles/AgateLib/Particles/SampleEmitter.cs
Modified: branches/particles/AgateLib/Particles/SampleEmitter.cs
===================================================================
--- branches/particles/AgateLib/Particles/SampleEmitter.cs 2009-04-28 16:53:20 UTC (rev 927)
+++ branches/particles/AgateLib/Particles/SampleEmitter.cs 2009-04-29 18:28:26 UTC (rev 928)
@@ -64,14 +64,14 @@
}
// TODO: add emit frequenzy
- switch(mEmitType)
+ switch(mEmitOrder)
{
- case EmitType.None:
+ case EmitOrder.None:
break;
- case EmitType.Order:
+ case EmitOrder.Sequenz:
base.Particles.Add(mSampleParticles[lastParticle]);
- if(lastParticle == mSampleParticles.Contains - 1)
+ if(lastParticle == mSampleParticles.Count - 1)
{
lastParticle = 0;
}
@@ -81,7 +81,7 @@
}
break;
- case EmitType.Random:
+ case EmitOrder.Random:
base.Particles.Add(mSampleParticles[ran.Next(0, mSampleParticles.Count-1)]);
break;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ac...@us...> - 2009-04-28 16:53:29
|
Revision: 927
http://agate.svn.sourceforge.net/agate/?rev=927&view=rev
Author: accagon
Date: 2009-04-28 16:53:20 +0000 (Tue, 28 Apr 2009)
Log Message:
-----------
Add SampleEmitter, emits copies of sample particles.
Added Paths:
-----------
branches/particles/AgateLib/Particles/SampleEmitter.cs
Added: branches/particles/AgateLib/Particles/SampleEmitter.cs
===================================================================
--- branches/particles/AgateLib/Particles/SampleEmitter.cs (rev 0)
+++ branches/particles/AgateLib/Particles/SampleEmitter.cs 2009-04-28 16:53:20 UTC (rev 927)
@@ -0,0 +1,101 @@
+
+using System;
+using System.Collections.Generic;
+
+using AgateLib.Geometry;
+
+namespace AgateLib.Particles
+{
+ /// <summary>
+ /// A particle emitter which emits copies of sample particles.
+ /// </summary>
+ public class SampleEmitter : ParticleEmitter
+ {
+ private int lastParticle = 0;
+ private Random ran;
+
+ private List<Particle> mSampleParticles;
+
+ private EmitOrder mEmitOrder = EmitOrder.None;
+
+ /// <value>
+ /// Gets or sets the sample particles.
+ /// </value>
+ public List<Particle> SampleParticles
+ {
+ get { return mSampleParticles; }
+ set { mSampleParticles = value; }
+ }
+
+ /// <value>
+ /// Gets or sets the emit order.
+ /// </value>
+ public EmitOrder EmitOrder
+ {
+ get { return mEmitOrder; }
+ set { mEmitOrder = value; }
+ }
+
+ /// <summary>
+ /// Constructs a SampleEmitter with a sequenz emitting order
+ /// and a default frequenzy.
+ /// </summary>
+ /// <param name="position"></param>
+ public SampleEmitter(Vector2 position)
+ {
+ mSampleParticles = new List<Particle>();
+ mEmitOrder = EmitOrder.Sequenz;
+ base.Position = position;
+ ran = new Random();
+ }
+
+ /// <summary>
+ /// Overridden Update method.
+ /// Emits new sample particle copies.
+ /// Updates and manipulates each particle.
+ /// </summary>
+ /// <param name="time_ms">Passed time in milliseconds since last update.</param>
+ public override void Update (float time_ms)
+ {
+ if(mSampleParticles.Count == 0)
+ {
+ base.Update(time_ms);
+ return;
+ }
+
+ // TODO: add emit frequenzy
+ switch(mEmitType)
+ {
+ case EmitType.None:
+ break;
+
+ case EmitType.Order:
+ base.Particles.Add(mSampleParticles[lastParticle]);
+ if(lastParticle == mSampleParticles.Contains - 1)
+ {
+ lastParticle = 0;
+ }
+ else
+ {
+ lastParticle++;
+ }
+ break;
+
+ case EmitType.Random:
+ base.Particles.Add(mSampleParticles[ran.Next(0, mSampleParticles.Count-1)]);
+ break;
+ }
+ base.Update (time_ms);
+ }
+ }
+
+ /// <summary>
+ /// Emit order.
+ /// </summary>
+ public enum EmitOrder
+ {
+ None,
+ Sequenz,
+ Random
+ }
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ac...@us...> - 2009-04-28 16:44:50
|
Revision: 926
http://agate.svn.sourceforge.net/agate/?rev=926&view=rev
Author: accagon
Date: 2009-04-28 16:44:34 +0000 (Tue, 28 Apr 2009)
Log Message:
-----------
* ParticleEmitter.cs: Add public property EmitFrequenzy and Particles
* Particle.cs and PixelParticle.cs: Rename mSurface, Surface to mImage, Image
Modified Paths:
--------------
branches/particles/AgateLib/Particles/Particle.cs
branches/particles/AgateLib/Particles/ParticleEmitter.cs
branches/particles/AgateLib/Particles/PixelParticle.cs
Modified: branches/particles/AgateLib/Particles/Particle.cs
===================================================================
--- branches/particles/AgateLib/Particles/Particle.cs 2009-04-28 08:25:11 UTC (rev 925)
+++ branches/particles/AgateLib/Particles/Particle.cs 2009-04-28 16:44:34 UTC (rev 926)
@@ -32,7 +32,7 @@
private Condition mCondition = Condition.Empty;
private bool mIsDead = false;
- private ISurface mSurface;
+ private ISurface mImage;
private Vector2 mAcceleration = Vector2.Empty;
private Vector2 mPosition = Vector2.Empty;
@@ -67,10 +67,10 @@
/// <value>
/// Gets or sets the surface.
/// </value>
- public ISurface Surface
+ public ISurface Image
{
- get { return mSurface; }
- set { mSurface = value; }
+ get { return mImage; }
+ set { mImage = value; }
}
/// <value>
@@ -105,7 +105,7 @@
/// </summary>
public virtual void Draw()
{
- mSurface.Draw(mPosition.X, mPosition.Y);
+ mImage.Draw(mPosition.X, mPosition.Y);
}
/// <summary>
Modified: branches/particles/AgateLib/Particles/ParticleEmitter.cs
===================================================================
--- branches/particles/AgateLib/Particles/ParticleEmitter.cs 2009-04-28 08:25:11 UTC (rev 925)
+++ branches/particles/AgateLib/Particles/ParticleEmitter.cs 2009-04-28 16:44:34 UTC (rev 926)
@@ -36,6 +36,26 @@
{
private List<Particle> mParticles = new List<Particle>();
+ private float mEmitFrequenzy = 1f;
+
+ /// <value>
+ /// Gets or sets the particles.
+ /// </value>
+ public List<Particle> Particles
+ {
+ get { return mParticles; }
+ set { mParticles = value; }
+ }
+
+ /// <value>
+ /// Gets or sets the emit frequenzy in seconds.
+ /// </value>
+ public float EmitFrequenzy
+ {
+ get { return mEmitFrequenzy; }
+ set { mEmitFrequenzy = value; }
+ }
+
/// <summary>
/// Delegate to update particles.
/// Particle manipulators should subscribe here.
Modified: branches/particles/AgateLib/Particles/PixelParticle.cs
===================================================================
--- branches/particles/AgateLib/Particles/PixelParticle.cs 2009-04-28 08:25:11 UTC (rev 925)
+++ branches/particles/AgateLib/Particles/PixelParticle.cs 2009-04-28 16:44:34 UTC (rev 926)
@@ -38,7 +38,7 @@
get { return mPixelBuffer.GetPixel(0,0); }
set {
mPixelBuffer.SetPixel(0,0, value);
- base.Surface = new Surface(mPixelBuffer);
+ base.Image = new Surface(mPixelBuffer);
}
}
@@ -51,7 +51,7 @@
public PixelParticle(Color color)
{
mPixelBuffer.SetPixel(0,0, color);
- base.Surface = new Surface(mPixelBuffer);
+ base.Image = new Surface(mPixelBuffer);
}
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ka...@us...> - 2009-04-28 08:25:22
|
Revision: 925
http://agate.svn.sourceforge.net/agate/?rev=925&view=rev
Author: kanato
Date: 2009-04-28 08:25:11 +0000 (Tue, 28 Apr 2009)
Log Message:
-----------
Switch to using vertex structures with VertexLayout information.
Modified Paths:
--------------
branches/agate3d-3.2/AgateLib/DisplayLib/Shaders/ShaderProgram.cs
branches/agate3d-3.2/AgateLib/DisplayLib/VertexBuffer.cs
branches/agate3d-3.2/AgateLib/Geometry/Builders/Cube.cs
branches/agate3d-3.2/AgateLib/Geometry/Builders/Terrain.cs
branches/agate3d-3.2/AgateLib/ImplementationBase/DisplayImpl.cs
branches/agate3d-3.2/AgateLib/ImplementationBase/VertexBufferImpl.cs
branches/agate3d-3.2/Drivers/AgateOTK/GL_Display.cs
branches/agate3d-3.2/Drivers/AgateOTK/GL_VertexBuffer.cs
branches/agate3d-3.2/Tests/Display3D/Glsl.cs
branches/agate3d-3.2/Tests/Display3D/Matrices.cs
branches/agate3d-3.2/Tests/Display3D/Test3d.cs
Added Paths:
-----------
branches/agate3d-3.2/AgateLib/DisplayLib/IndexBuffer.cs
branches/agate3d-3.2/AgateLib/Geometry/VertexTypes/
branches/agate3d-3.2/AgateLib/Geometry/VertexTypes/PositionTextureNTB.cs
branches/agate3d-3.2/AgateLib/Geometry/VertexTypes/PositionTextureNormal.cs
branches/agate3d-3.2/AgateLib/Geometry/VertexTypes/VertexLayout.cs
branches/agate3d-3.2/AgateLib/ImplementationBase/IndexBufferImpl.cs
branches/agate3d-3.2/Drivers/AgateOTK/GL_IndexBuffer.cs
Added: branches/agate3d-3.2/AgateLib/DisplayLib/IndexBuffer.cs
===================================================================
--- branches/agate3d-3.2/AgateLib/DisplayLib/IndexBuffer.cs (rev 0)
+++ branches/agate3d-3.2/AgateLib/DisplayLib/IndexBuffer.cs 2009-04-28 08:25:11 UTC (rev 925)
@@ -0,0 +1,43 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using AgateLib.ImplementationBase;
+
+namespace AgateLib.DisplayLib
+{
+ public class IndexBuffer
+ {
+ IndexBufferImpl impl;
+
+ public IndexBuffer(IndexBufferType type, int size)
+ {
+ impl = Display.Impl.CreateIndexBuffer(type, size);
+ }
+
+ public void WriteIndices(short[] indices)
+ {
+ impl.WriteIndices(indices);
+ }
+ public void WriteIndices(int[] indices)
+ {
+ impl.WriteIndices(indices);
+ }
+
+ public int Count
+ {
+ get { return impl.Count; }
+ }
+
+ public IndexBufferImpl Impl
+ {
+ get { return impl; }
+ }
+ }
+
+ public enum IndexBufferType
+ {
+ Int16,
+ Int32,
+ }
+}
Modified: branches/agate3d-3.2/AgateLib/DisplayLib/Shaders/ShaderProgram.cs
===================================================================
--- branches/agate3d-3.2/AgateLib/DisplayLib/Shaders/ShaderProgram.cs 2009-04-28 01:26:55 UTC (rev 924)
+++ branches/agate3d-3.2/AgateLib/DisplayLib/Shaders/ShaderProgram.cs 2009-04-28 08:25:11 UTC (rev 925)
@@ -3,6 +3,7 @@
using System.Linq;
using System.Text;
using AgateLib.Geometry;
+using AgateLib.Geometry.VertexTypes;
namespace AgateLib.DisplayLib.Shaders
{
Modified: branches/agate3d-3.2/AgateLib/DisplayLib/VertexBuffer.cs
===================================================================
--- branches/agate3d-3.2/AgateLib/DisplayLib/VertexBuffer.cs 2009-04-28 01:26:55 UTC (rev 924)
+++ branches/agate3d-3.2/AgateLib/DisplayLib/VertexBuffer.cs 2009-04-28 08:25:11 UTC (rev 925)
@@ -4,6 +4,7 @@
using System.Text;
using AgateLib.ImplementationBase;
using AgateLib.Geometry;
+using AgateLib.Geometry.VertexTypes;
namespace AgateLib.DisplayLib
{
@@ -17,6 +18,7 @@
throw new ArgumentNullException(
"The supplied VertexLayout must not be null. " +
"You may wish to use one of the static members of VertexLayout.");
+
if (layout.Count == 0)
throw new ArgumentException(
"The supplied VertexLayout has no items in it. You must supply a valid layout.");
@@ -24,50 +26,41 @@
impl = Display.Impl.CreateVertexBuffer(layout, vertexCount);
}
- public void WriteVertexData(Vector3[] data)
+ public void WriteVertexData<T>(T[] data)
{
- impl.WriteVertexData(data);
+ impl.Write(data);
}
- public void WriteTextureCoords(Vector2[] texCoords)
+ public void Draw()
{
- impl.WriteTextureCoords(texCoords);
+ impl.Draw(0, VertexCount);
}
- public void WriteNormalData(Vector3[] data)
+ public void Draw(int start, int count)
{
- impl.WriteNormalData(data);
+ impl.Draw(start, count);
}
- public void WriteIndices(short[] indices)
+ /// <summary>
+ /// Draws the vertices using the indexes in the index buffer.
+ /// </summary>
+ /// <param name="indexbuffer"></param>
+ public void DrawIndexed(IndexBuffer indexbuffer)
{
- impl.WriteIndices(indices);
- impl.Indexed = true;
+ impl.DrawIndexed(indexbuffer, 0, indexbuffer.Count);
}
- public void WriteAttributeData(string attributeName, Vector3[] data)
+ /// <summary>
+ /// Draws the vertices using the specified set of indexes in the index buffer.
+ /// </summary>
+ /// <param name="indexbuffer"></param>
+ /// <param name="start"></param>
+ /// <param name="count"></param>
+ public void DrawIndexed(IndexBuffer indexbuffer, int start, int count)
{
- impl.WriteAttributeData(attributeName, data);
+ impl.DrawIndexed(indexbuffer, start, count);
}
- public bool Indexed
- {
- get { return impl.Indexed; }
- set { impl.Indexed = value; }
- }
- public void Draw()
- {
- impl.Draw();
- }
- public void Draw(int start, int count)
- {
- impl.Draw(start, count);
- }
-
public int VertexCount
{
get { return impl.VertexCount; }
}
- public int IndexCount
- {
- get { return impl.IndexCount; }
- }
public PrimitiveType PrimitiveType
{
get { return impl.PrimitiveType; }
@@ -77,7 +70,6 @@
{
get { return impl.Textures; }
}
-
}
public class TextureList
@@ -111,221 +103,4 @@
}
}
- public class VertexLayout : IList<VertexMember>
- {
- List<VertexMember> items = new List<VertexMember>();
-
- int VertexSize
- {
- get
- {
- return this.Sum(x => x.ItemSize);
- }
- }
-
- public static VertexLayout PositionNormalTexture
- {
- get
- {
- return new VertexLayout
- {
- new VertexMember(VertexMemberType.Float3, VertexMemberUsage.Position),
- new VertexMember(VertexMemberType.Float3, VertexMemberUsage.Normal),
- new VertexMember(VertexMemberType.Float2, VertexMemberUsage.Texture),
- };
- }
- }
- public static VertexLayout PositionNormalTangentBitangentTexture
- {
- get
- {
- return new VertexLayout
- {
- new VertexMember(VertexMemberType.Float3, VertexMemberUsage.Position),
- new VertexMember(VertexMemberType.Float3, VertexMemberUsage.Normal),
- new VertexMember(VertexMemberType.Float3, VertexMemberUsage.Tangent),
- new VertexMember(VertexMemberType.Float3, VertexMemberUsage.Bitangent),
- new VertexMember(VertexMemberType.Float2, VertexMemberUsage.Texture),
- };
- }
- }
- public VertexLayout PositionNormal
- {
- get
- {
- return new VertexLayout
- {
- new VertexMember(VertexMemberType.Float3, VertexMemberUsage.Position),
- new VertexMember(VertexMemberType.Float3, VertexMemberUsage.Normal),
- };
- }
- }
- public VertexLayout PositionTexture
- {
- get
- {
- return new VertexLayout
- {
- new VertexMember(VertexMemberType.Float3, VertexMemberUsage.Position),
- new VertexMember(VertexMemberType.Float2, VertexMemberUsage.Texture),
- };
- }
- }
-
- #region --- IList<VertexMember> Members ---
-
- int IList<VertexMember>.IndexOf(VertexMember item)
- {
- return items.IndexOf(item);
- }
- void IList<VertexMember>.Insert(int index, VertexMember item)
- {
- items.Insert(index, item);
- }
- public void RemoveAt(int index)
- {
- items.RemoveAt(index);
- }
- public VertexMember this[int index]
- {
- get { return items[index]; }
- set { items[index] = value; }
- }
-
- #endregion
- #region --- ICollection<VertexMember> Members ---
-
- public void Add(VertexMember item)
- {
- items.Add(item);
- }
- public void Clear()
- {
- items.Clear();
- }
- bool ICollection<VertexMember>.Contains(VertexMember item)
- {
- return items.Contains(item);
- }
- public void CopyTo(VertexMember[] array, int arrayIndex)
- {
- items.CopyTo(array, arrayIndex);
- }
-
- public int Count
- {
- get { return items.Count; }
- }
-
- bool ICollection<VertexMember>.IsReadOnly
- {
- get { return false; }
- }
-
- bool ICollection<VertexMember>.Remove(VertexMember item)
- {
- return items.Remove(item);
- }
-
- #endregion
- #region --- IEnumerable<VertexMember> Members ---
-
- IEnumerator<VertexMember> IEnumerable<VertexMember>.GetEnumerator()
- {
- return items.GetEnumerator();
- }
-
- #endregion
- #region --- IEnumerable Members ---
-
- System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
- {
- return items.GetEnumerator();
- }
-
- #endregion
-
- public bool Contains(VertexMemberUsage vertexMemberUsage)
- {
- return items.Any(x => x.Usage == vertexMemberUsage);
- }
- public bool Contains(string attributeName)
- {
- return items.Any(x => x.Usage == VertexMemberUsage.Attribute && x.AttributeString == attributeName);
- }
- }
-
- public class VertexMember
- {
- VertexMemberUsage mDef;
- string mAttributeString;
-
- public VertexMember(VertexMemberType type, VertexMemberUsage def)
- {
- if (def == VertexMemberUsage.Attribute)
- throw new AgateException("Use the (VertexMemberType, string) overload instead.");
-
- MemberType = type;
- Usage = def;
- }
-
- public VertexMember(VertexMemberType type, string attributeName)
- {
- MemberType = type;
- Usage = VertexMemberUsage.Attribute;
- AttributeString = attributeName;
- }
-
- public VertexMemberType MemberType { get; private set; }
- public VertexMemberUsage Usage
- {
- get { return mDef; }
- private set
- {
- mDef = value;
-
- if (mDef != VertexMemberUsage.Attribute)
- mAttributeString = null;
- }
- }
- public string AttributeString
- {
- get { return mAttributeString; }
- private set
- {
- mAttributeString = value;
- mDef = VertexMemberUsage.Attribute;
- }
- }
-
- public int ItemSize
- {
- get
- {
- return 1;
- }
- }
- }
-
- public enum VertexMemberType
- {
- Float1,
- Float2,
- Float3,
- Float4,
- }
-
- public enum VertexMemberUsage
- {
- Position,
- Normal,
- Tangent,
- Bitangent,
- Color,
- Texture,
- Texture1,
- Texture2,
- Texture3,
- Attribute,
- }
}
Modified: branches/agate3d-3.2/AgateLib/Geometry/Builders/Cube.cs
===================================================================
--- branches/agate3d-3.2/AgateLib/Geometry/Builders/Cube.cs 2009-04-28 01:26:55 UTC (rev 924)
+++ branches/agate3d-3.2/AgateLib/Geometry/Builders/Cube.cs 2009-04-28 08:25:11 UTC (rev 925)
@@ -2,57 +2,68 @@
using System.Collections.Generic;
using System.Text;
using AgateLib.DisplayLib;
+using AgateLib.Geometry.VertexTypes;
namespace AgateLib.Geometry.Builders
{
public class CubeBuilder
{
+ VertexBuffer mVertices = null;
+ IndexBuffer mIndices = null;
+
public CubeBuilder()
{
Length = 1;
- VertexType = VertexLayout.PositionNormalTexture;
+ VertexType = VertexTypes.PositionTextureNTB.VertexLayout;
}
+ public VertexBuffer VertexBuffer
+ {
+ get { return mVertices; }
+ }
+ public IndexBuffer IndexBuffer
+ {
+ get { return mIndices; }
+ }
+
public float Length { get; set; }
public Vector3 Location { get; set; }
+
bool GenerateTextureCoords
{
- get { return VertexType.Contains(VertexMemberUsage.Texture); }
+ get { return VertexType.ContainsElement(VertexElement.Texture); }
}
bool GenerateNormals
{
- get { return VertexType.Contains(VertexMemberUsage.Normal); }
+ get { return VertexType.ContainsElement(VertexElement.Normal); }
}
bool GenerateTangent
{
- get { return VertexType.Contains(VertexMemberUsage.Tangent); }
+ get { return VertexType.ContainsElement(VertexElement.Tangent); }
}
bool GenerateBitangent
{
- get { return VertexType.Contains(VertexMemberUsage.Bitangent); }
+ get { return VertexType.ContainsElement(VertexElement.Bitangent); }
}
-
public VertexLayout VertexType { get; set; }
- public VertexBuffer CreateVertexBuffer()
+ public void CreateVertexBuffer()
{
- VertexBuffer retval = new VertexBuffer(VertexType, 24);
+ PositionTextureNTB[] vertices = new PositionTextureNTB[24];
- retval.PrimitiveType = PrimitiveType.TriangleList;
- retval.WriteVertexData(GetVertexData());
- retval.WriteIndices(GetIndexData());
+ mVertices = new VertexBuffer(VertexType, 24);
+ mIndices = new IndexBuffer(IndexBufferType.Int16, 36);
- if (GenerateTextureCoords)
- retval.WriteTextureCoords(GetTextureCoords());
- if (GenerateNormals)
- retval.WriteNormalData(GetNormals());
- if (GenerateTangent)
- retval.WriteAttributeData("tangent", GetTangent());
- if (GenerateBitangent)
- retval.WriteAttributeData("bitangent", GetBitangent());
+ mVertices.PrimitiveType = PrimitiveType.TriangleList;
- return retval;
+ GenerateVertexData(vertices);
+ GenerateNormalData(vertices);
+ GenerateTexCoordData(vertices);
+
+ mVertices.WriteVertexData(vertices);
+ mIndices.WriteIndices(GetIndexData());
+
}
@@ -130,77 +141,67 @@
return retval;
}
- private Vector3[] GetNormals()
+ private void GenerateNormalData(PositionTextureNTB[] vertices)
{
- Vector3[] retval = new Vector3[24];
-
int i = 0;
float length = Length / 2.0f;
for (int sign = -1; sign <= 1; sign += 2)
{
- retval[i++] = new Vector3(0, 0, sign);
- retval[i++] = new Vector3(0, 0, sign);
- retval[i++] = new Vector3(0, 0, sign);
- retval[i++] = new Vector3(0, 0, sign);
+ vertices[i++].Normal = new Vector3(0, 0, sign);
+ vertices[i++].Normal = new Vector3(0, 0, sign);
+ vertices[i++].Normal = new Vector3(0, 0, sign);
+ vertices[i++].Normal = new Vector3(0, 0, sign);
- retval[i++] = new Vector3(0, sign, 0);
- retval[i++] = new Vector3(0, sign, 0);
- retval[i++] = new Vector3(0, sign, 0);
- retval[i++] = new Vector3(0, sign, 0);
+ vertices[i++].Normal = new Vector3(0, sign, 0);
+ vertices[i++].Normal = new Vector3(0, sign, 0);
+ vertices[i++].Normal = new Vector3(0, sign, 0);
+ vertices[i++].Normal = new Vector3(0, sign, 0);
- retval[i++] = new Vector3(sign, 0, 0);
- retval[i++] = new Vector3(sign, 0, 0);
- retval[i++] = new Vector3(sign, 0, 0);
- retval[i++] = new Vector3(sign, 0, 0);
+ vertices[i++].Normal = new Vector3(sign, 0, 0);
+ vertices[i++].Normal = new Vector3(sign, 0, 0);
+ vertices[i++].Normal = new Vector3(sign, 0, 0);
+ vertices[i++].Normal = new Vector3(sign, 0, 0);
}
-
- return retval;
}
- protected virtual Vector3[] GetVertexData()
+
+
+ private void GenerateVertexData(PositionTextureNTB[] vertices)
{
- Vector3[] retval = new Vector3[24];
-
int i = 0;
float length = Length / 2.0f;
for (int sign = -1; sign <= 1; sign += 2)
{
- retval[i++] = new Vector3(length, length, sign * length);
- retval[i++] = new Vector3(length, -length, sign * length);
- retval[i++] = new Vector3(-length, length, sign * length);
- retval[i++] = new Vector3(-length, -length, sign * length);
+ vertices[i++].Position = new Vector3(length, length, sign * length);
+ vertices[i++].Position = new Vector3(length, -length, sign * length);
+ vertices[i++].Position = new Vector3(-length, length, sign * length);
+ vertices[i++].Position = new Vector3(-length, -length, sign * length);
- retval[i++] = new Vector3(length, sign * length, length);
- retval[i++] = new Vector3(length, sign * length, -length);
- retval[i++] = new Vector3(-length, sign * length, length);
- retval[i++] = new Vector3(-length, sign * length, -length);
+ vertices[i++].Position = new Vector3(length, sign * length, length);
+ vertices[i++].Position = new Vector3(length, sign * length, -length);
+ vertices[i++].Position = new Vector3(-length, sign * length, length);
+ vertices[i++].Position = new Vector3(-length, sign * length, -length);
- retval[i++] = new Vector3(sign * length, length, length);
- retval[i++] = new Vector3(sign * length, length, -length);
- retval[i++] = new Vector3(sign * length, -length, length);
- retval[i++] = new Vector3(sign * length, -length, -length);
+ vertices[i++].Position = new Vector3(sign * length, length, length);
+ vertices[i++].Position = new Vector3(sign * length, length, -length);
+ vertices[i++].Position = new Vector3(sign * length, -length, length);
+ vertices[i++].Position = new Vector3(sign * length, -length, -length);
}
- for (i = 0; i < retval.Length; i++)
- retval[i] += Location;
-
- return retval;
+ for (i = 0; i < vertices.Length; i++)
+ vertices[i].Position += Location;
}
- protected virtual Vector2[] GetTextureCoords()
+ private void GenerateTexCoordData(PositionTextureNTB[] vertices)
{
- Vector2[] retval = new Vector2[24];
-
int i = 0;
for (int face = 0; face < 6; face++)
{
- retval[i++] = new Vector2(0, 0);
- retval[i++] = new Vector2(0, 1);
- retval[i++] = new Vector2(1, 0);
- retval[i++] = new Vector2(1, 1);
+ vertices[i++].Texture = new Vector2(0, 0);
+ vertices[i++].Texture = new Vector2(0, 1);
+ vertices[i++].Texture = new Vector2(1, 0);
+ vertices[i++].Texture = new Vector2(1, 1);
}
-
- return retval;
}
}
}
\ No newline at end of file
Modified: branches/agate3d-3.2/AgateLib/Geometry/Builders/Terrain.cs
===================================================================
--- branches/agate3d-3.2/AgateLib/Geometry/Builders/Terrain.cs 2009-04-28 01:26:55 UTC (rev 924)
+++ branches/agate3d-3.2/AgateLib/Geometry/Builders/Terrain.cs 2009-04-28 08:25:11 UTC (rev 925)
@@ -3,6 +3,7 @@
using System.Linq;
using System.Text;
using AgateLib.DisplayLib;
+using AgateLib.Geometry.VertexTypes;
namespace AgateLib.Geometry.Builders
{
@@ -17,7 +18,7 @@
Height = 1;
MaxPeak = 1;
- VertexType = VertexLayout.PositionNormalTexture;
+ VertexType = PositionTextureNormal.VertexLayout;
}
/// <summary>
@@ -61,9 +62,9 @@
VertexBuffer retval = new VertexBuffer(VertexType, vertices.Length);
retval.WriteVertexData(vertices);
- retval.WriteTextureCoords(texture);
- retval.WriteNormalData(normal);
- retval.WriteIndices(indices);
+ //retval.WriteTextureCoords(texture);
+ //retval.WriteNormalData(normal);
+ //retval.WriteIndices(indices);
return retval;
}
Added: branches/agate3d-3.2/AgateLib/Geometry/VertexTypes/PositionTextureNTB.cs
===================================================================
--- branches/agate3d-3.2/AgateLib/Geometry/VertexTypes/PositionTextureNTB.cs (rev 0)
+++ branches/agate3d-3.2/AgateLib/Geometry/VertexTypes/PositionTextureNTB.cs 2009-04-28 08:25:11 UTC (rev 925)
@@ -0,0 +1,33 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Runtime.InteropServices;
+using System.Text;
+
+namespace AgateLib.Geometry.VertexTypes
+{
+ [StructLayout(LayoutKind.Sequential, Pack = 1)]
+ public struct PositionTextureNTB
+ {
+ public Vector3 Position;
+ public Vector2 Texture;
+ public Vector3 Normal;
+ public Vector3 Tangent;
+ public Vector3 Bitangent;
+
+ public static VertexLayout VertexLayout
+ {
+ get
+ {
+ return new VertexLayout
+ {
+ new VertexElementDesc(VertexElementDataType.Float3, VertexElement.Position),
+ new VertexElementDesc(VertexElementDataType.Float2, VertexElement.Texture),
+ new VertexElementDesc(VertexElementDataType.Float3, VertexElement.Normal),
+ new VertexElementDesc(VertexElementDataType.Float3, VertexElement.Tangent),
+ new VertexElementDesc(VertexElementDataType.Float3, VertexElement.Bitangent),
+ };
+ }
+ }
+ }
+}
Added: branches/agate3d-3.2/AgateLib/Geometry/VertexTypes/PositionTextureNormal.cs
===================================================================
--- branches/agate3d-3.2/AgateLib/Geometry/VertexTypes/PositionTextureNormal.cs (rev 0)
+++ branches/agate3d-3.2/AgateLib/Geometry/VertexTypes/PositionTextureNormal.cs 2009-04-28 08:25:11 UTC (rev 925)
@@ -0,0 +1,29 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Runtime.InteropServices;
+using System.Text;
+
+namespace AgateLib.Geometry.VertexTypes
+{
+ [StructLayout(LayoutKind.Sequential, Pack = 1)]
+ public class PositionTextureNormal
+ {
+ public Vector3 Position;
+ public Vector2 Texture;
+ public Vector3 Normal;
+
+ public static VertexLayout VertexLayout
+ {
+ get
+ {
+ return new VertexLayout
+ {
+ new VertexElementDesc(VertexElementDataType.Float3, VertexElement.Position),
+ new VertexElementDesc(VertexElementDataType.Float2, VertexElement.Texture),
+ new VertexElementDesc(VertexElementDataType.Float3, VertexElement.Normal),
+ };
+ }
+ }
+ }
+}
Added: branches/agate3d-3.2/AgateLib/Geometry/VertexTypes/VertexLayout.cs
===================================================================
--- branches/agate3d-3.2/AgateLib/Geometry/VertexTypes/VertexLayout.cs (rev 0)
+++ branches/agate3d-3.2/AgateLib/Geometry/VertexTypes/VertexLayout.cs 2009-04-28 08:25:11 UTC (rev 925)
@@ -0,0 +1,254 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace AgateLib.Geometry.VertexTypes
+{
+ public class VertexLayout : IList<VertexElementDesc>
+ {
+ List<VertexElementDesc> items = new List<VertexElementDesc>();
+
+ public int VertexSize
+ {
+ get
+ {
+ return this.Sum(x => x.ItemSize);
+ }
+ }
+
+ public VertexElementDesc GetElement(VertexElement element)
+ {
+ for (int i = 0; i < Count; i++)
+ {
+ if (this[i].ElementType == element)
+ return this[i];
+ }
+
+ throw new AgateException("Element {0} not found.", element);
+ }
+
+ public bool ContainsElement(VertexElement element)
+ {
+ return items.Any(x => x.ElementType == element);
+ }
+ public bool ContainsElement(string attributeName)
+ {
+ return items.Any(x => x.ElementType == VertexElement.Attribute && x.AttributeString == attributeName);
+ }
+ public int ElementByteIndex(VertexElement element)
+ {
+ int size = 0;
+
+ for (int i = 0; i < Count; i++)
+ {
+ if (this[i].ElementType == element)
+ return size;
+
+ size += this[i].ItemSize;
+ }
+
+ throw new AgateException("Could not find the element {0} in the vertex layout.", element);
+ }
+ public int ElementByteIndex(string attributeName)
+ {
+
+ int size = 0;
+
+ for (int i = 0; i < Count; i++)
+ {
+ if (this[i].ElementType == VertexElement.Attribute &&
+ this[i].AttributeString == attributeName)
+ {
+ return size;
+ }
+
+ size += SizeOf(this[i].DataType);
+ }
+
+ throw new AgateException("Could not find the attribute {0} in the vertex layout.", attributeName);
+ }
+
+ public static int SizeOf(VertexElementDataType vertexElementType)
+ {
+ switch (vertexElementType)
+ {
+ case VertexElementDataType.Float1: return 1 * sizeof(float);
+ case VertexElementDataType.Float2: return 2 * sizeof(float);
+ case VertexElementDataType.Float3: return 3 * sizeof(float);
+ case VertexElementDataType.Float4: return 4 * sizeof(float);
+
+ default: throw new NotImplementedException();
+ }
+ }
+
+ /*
+
+ public VertexLayout PositionNormal
+ {
+ get
+ {
+ return new VertexLayout
+ {
+ new VertexMember(VertexMemberType.Float3, VertexMemberUsage.Position),
+ new VertexMember(VertexMemberType.Float3, VertexMemberUsage.Normal),
+ };
+ }
+ }
+ public VertexLayout PositionTexture
+ {
+ get
+ {
+ return new VertexLayout
+ {
+ new VertexMember(VertexMemberType.Float3, VertexMemberUsage.Position),
+ new VertexMember(VertexMemberType.Float2, VertexMemberUsage.Texture),
+ };
+ }
+ }
+ */
+
+ #region --- IList<VertexMember> Members ---
+
+ int IList<VertexElementDesc>.IndexOf(VertexElementDesc item)
+ {
+ return items.IndexOf(item);
+ }
+ void IList<VertexElementDesc>.Insert(int index, VertexElementDesc item)
+ {
+ items.Insert(index, item);
+ }
+ public void RemoveAt(int index)
+ {
+ items.RemoveAt(index);
+ }
+ public VertexElementDesc this[int index]
+ {
+ get { return items[index]; }
+ set { items[index] = value; }
+ }
+
+ #endregion
+ #region --- ICollection<VertexMember> Members ---
+
+ public void Add(VertexElementDesc item)
+ {
+ items.Add(item);
+ }
+ public void Clear()
+ {
+ items.Clear();
+ }
+ bool ICollection<VertexElementDesc>.Contains(VertexElementDesc item)
+ {
+ return items.Contains(item);
+ }
+ public void CopyTo(VertexElementDesc[] array, int arrayIndex)
+ {
+ items.CopyTo(array, arrayIndex);
+ }
+
+ public int Count
+ {
+ get { return items.Count; }
+ }
+
+ bool ICollection<VertexElementDesc>.IsReadOnly
+ {
+ get { return false; }
+ }
+
+ bool ICollection<VertexElementDesc>.Remove(VertexElementDesc item)
+ {
+ return items.Remove(item);
+ }
+
+ #endregion
+ #region --- IEnumerable<VertexMember> Members ---
+
+ IEnumerator<VertexElementDesc> IEnumerable<VertexElementDesc>.GetEnumerator()
+ {
+ return items.GetEnumerator();
+ }
+
+ #endregion
+ #region --- IEnumerable Members ---
+
+ System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
+ {
+ return items.GetEnumerator();
+ }
+
+ #endregion
+
+ }
+ public class VertexElementDesc
+ {
+ VertexElement mDef;
+ string mAttributeString;
+
+ public VertexElementDesc(VertexElementDataType type, VertexElement def)
+ {
+ if (def == VertexElement.Attribute)
+ throw new AgateException("Use the (VertexMemberType, string) overload instead.");
+
+ DataType = type;
+ ElementType = def;
+ }
+ public VertexElementDesc(VertexElementDataType type, string attributeName)
+ {
+ DataType = type;
+ ElementType = VertexElement.Attribute;
+ AttributeString = attributeName;
+ }
+
+ public VertexElementDataType DataType { get; private set; }
+ public VertexElement ElementType
+ {
+ get { return mDef; }
+ private set
+ {
+ mDef = value;
+
+ if (mDef != VertexElement.Attribute)
+ mAttributeString = null;
+ }
+ }
+
+ public string AttributeString
+ {
+ get { return mAttributeString; }
+ private set
+ {
+ mAttributeString = value;
+ mDef = VertexElement.Attribute;
+ }
+ }
+
+ public int ItemSize
+ {
+ get { return VertexLayout.SizeOf(DataType); }
+ }
+ }
+
+ public enum VertexElementDataType
+ {
+ Float1,
+ Float2,
+ Float3,
+ Float4,
+ }
+ public enum VertexElement
+ {
+ Position,
+ Normal,
+ Tangent,
+ Bitangent,
+ Color,
+ Texture,
+ Texture1,
+ Texture2,
+ Texture3,
+ Attribute,
+ }
+}
Modified: branches/agate3d-3.2/AgateLib/ImplementationBase/DisplayImpl.cs
===================================================================
--- branches/agate3d-3.2/AgateLib/ImplementationBase/DisplayImpl.cs 2009-04-28 01:26:55 UTC (rev 924)
+++ branches/agate3d-3.2/AgateLib/ImplementationBase/DisplayImpl.cs 2009-04-28 08:25:11 UTC (rev 925)
@@ -596,11 +596,17 @@
protected internal abstract void HideCursor();
- protected internal virtual VertexBufferImpl CreateVertexBuffer(VertexLayout layout, int vertexCount)
+ protected internal virtual VertexBufferImpl CreateVertexBuffer(
+ Geometry.VertexTypes.VertexLayout layout, int vertexCount)
{
throw new AgateException("Cannot create a vertex buffer with a driver that does not support 3D.");
}
+ protected internal virtual IndexBufferImpl CreateIndexBuffer(IndexBufferType type, int size)
+ {
+ throw new AgateException("Cannot create an index buffer with a driver that does not support 3D.");
+ }
+
public virtual Matrix4 MatrixProjection
{
get { throw new AgateException("3D is not supported."); }
@@ -644,5 +650,6 @@
ShaderCompiler.Disable();
}
+
}
}
Added: branches/agate3d-3.2/AgateLib/ImplementationBase/IndexBufferImpl.cs
===================================================================
--- branches/agate3d-3.2/AgateLib/ImplementationBase/IndexBufferImpl.cs (rev 0)
+++ branches/agate3d-3.2/AgateLib/ImplementationBase/IndexBufferImpl.cs 2009-04-28 08:25:11 UTC (rev 925)
@@ -0,0 +1,18 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using AgateLib.DisplayLib;
+
+namespace AgateLib.ImplementationBase
+{
+ public abstract class IndexBufferImpl
+ {
+ public abstract void WriteIndices(short[] indices);
+ public abstract void WriteIndices(int[] indices);
+
+ public abstract int Count { get; }
+
+ public abstract IndexBufferType IndexType { get; }
+ }
+}
Modified: branches/agate3d-3.2/AgateLib/ImplementationBase/VertexBufferImpl.cs
===================================================================
--- branches/agate3d-3.2/AgateLib/ImplementationBase/VertexBufferImpl.cs 2009-04-28 01:26:55 UTC (rev 924)
+++ branches/agate3d-3.2/AgateLib/ImplementationBase/VertexBufferImpl.cs 2009-04-28 08:25:11 UTC (rev 925)
@@ -13,27 +13,14 @@
Textures = new TextureList();
}
- public abstract void WriteVertexData(Vector3[] data);
- public abstract void WriteTextureCoords(Vector2[] texCoords);
- public abstract void WriteNormalData(Vector3[] data);
- public abstract void WriteIndices(short[] indices);
- public abstract void WriteAttributeData(string attributeName, Vector3[] data);
+ public abstract void Write<T>(T[] vertices);
public abstract int VertexCount { get; }
- public abstract int IndexCount { get; }
- public virtual bool Indexed { get; set; }
-
public virtual PrimitiveType PrimitiveType { get; set; }
public TextureList Textures { get; set; }
- public virtual void Draw()
- {
- Draw(0, Indexed ? IndexCount : VertexCount);
- }
public abstract void Draw(int start, int count);
-
-
-
+ public abstract void DrawIndexed(IndexBuffer indexbuffer, int start, int count);
}
}
Modified: branches/agate3d-3.2/Drivers/AgateOTK/GL_Display.cs
===================================================================
--- branches/agate3d-3.2/Drivers/AgateOTK/GL_Display.cs 2009-04-28 01:26:55 UTC (rev 924)
+++ branches/agate3d-3.2/Drivers/AgateOTK/GL_Display.cs 2009-04-28 08:25:11 UTC (rev 925)
@@ -22,13 +22,12 @@
using System.IO;
using System.Text;
using System.Runtime.InteropServices;
-
using AgateLib.BitmapFont;
using AgateLib.DisplayLib;
using AgateLib.Drivers;
using AgateLib.Geometry;
+using AgateLib.Geometry.VertexTypes;
using AgateLib.ImplementationBase;
-
using OpenTK.Graphics;
using PixelFormat = AgateLib.DisplayLib.PixelFormat;
@@ -101,8 +100,12 @@
}
protected override VertexBufferImpl CreateVertexBuffer(VertexLayout layout, int vertexCount)
{
- return new GL_VertexBuffer(layout);
+ return new GL_VertexBuffer(layout, vertexCount);
}
+ protected override IndexBufferImpl CreateIndexBuffer(IndexBufferType type, int size)
+ {
+ return new GL_IndexBuffer(type, size);
+ }
public override SurfaceImpl CreateSurface(Size surfaceSize)
{
Added: branches/agate3d-3.2/Drivers/AgateOTK/GL_IndexBuffer.cs
===================================================================
--- branches/agate3d-3.2/Drivers/AgateOTK/GL_IndexBuffer.cs (rev 0)
+++ branches/agate3d-3.2/Drivers/AgateOTK/GL_IndexBuffer.cs 2009-04-28 08:25:11 UTC (rev 925)
@@ -0,0 +1,119 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Runtime.InteropServices;
+using System.Text;
+using AgateLib.DisplayLib;
+using AgateLib.ImplementationBase;
+using OpenTK.Graphics;
+
+namespace AgateOTK
+{
+ class GL_IndexBuffer : IndexBufferImpl
+ {
+ int mCount;
+ IndexBufferType mType;
+ int mBufferID;
+
+ public GL_IndexBuffer(IndexBufferType type, int count)
+ {
+ mCount = count;
+ mType = type;
+
+ CreateBuffer();
+ }
+
+ private void CreateBuffer()
+ {
+ GL.GenBuffers(1, out mBufferID);
+ }
+
+ public override int Count
+ {
+ get { return mCount; }
+ }
+ public override IndexBufferType IndexType
+ {
+ get { return mType; }
+ }
+ public int BufferID
+ {
+ get { return mBufferID; }
+ }
+
+ public void Bind()
+ {
+ GL.BindBuffer(BufferTarget.ElementArrayBuffer, mBufferID);
+ }
+
+ private short[] ConvertToInt16(int[] indices)
+ {
+ short[] retval = new short[indices.Length];
+
+ int i = 0;
+
+ try
+ {
+ checked
+ {
+ for (i = 0; i < retval.Length; i++)
+ {
+ retval[i] = (short)indices[i];
+ }
+ }
+ }
+ catch (OverflowException ex)
+ {
+ throw new AgateLib.AgateException(ex, string.Format(
+ "A 16 bit index buffer cannot contain values greater than {0}, " +
+ "but there is a value of {1} at index {2}.",
+ short.MaxValue, indices[i], i));
+ }
+
+ return retval;
+ }
+
+ unsafe public override void WriteIndices(int[] indices)
+ {
+ if (indices.Length != Count)
+ throw new AgateLib.AgateException(
+ "The size of the passed array must match the size of the index buffer.");
+
+ if (mType == IndexBufferType.Int16)
+ {
+ WriteIndices(ConvertToInt16(indices));
+ return;
+ }
+
+ Bind();
+
+ fixed (int* ptr = indices)
+ {
+ GL.BufferData(
+ BufferTarget.ElementArrayBuffer,
+ (IntPtr)(indices.Length * Marshal.SizeOf(typeof(int))),
+ (IntPtr)ptr,
+ BufferUsageHint.StaticDraw);
+ }
+ }
+
+ unsafe public override void WriteIndices(short[] indices)
+ {
+ if (indices.Length != Count)
+ throw new AgateLib.AgateException(
+ "The size of the passed array must match the size of the index buffer.");
+
+ Bind();
+
+ fixed (short* ptr = indices)
+ {
+ GL.BufferData(
+ BufferTarget.ElementArrayBuffer,
+ (IntPtr)(indices.Length * Marshal.SizeOf(typeof(short))),
+ (IntPtr)ptr,
+ BufferUsageHint.StaticDraw);
+ }
+ }
+
+ }
+}
Modified: branches/agate3d-3.2/Drivers/AgateOTK/GL_VertexBuffer.cs
===================================================================
--- branches/agate3d-3.2/Drivers/AgateOTK/GL_VertexBuffer.cs 2009-04-28 01:26:55 UTC (rev 924)
+++ branches/agate3d-3.2/Drivers/AgateOTK/GL_VertexBuffer.cs 2009-04-28 08:25:11 UTC (rev 925)
@@ -3,10 +3,11 @@
using System.Runtime.InteropServices;
using System.Text;
using AgateLib;
+using AgateLib.DisplayLib;
using AgateLib.Geometry;
+using AgateLib.Geometry.VertexTypes;
using AgateLib.ImplementationBase;
using OpenTK.Graphics;
-using AgateLib.DisplayLib;
namespace AgateOTK
{
@@ -23,139 +24,67 @@
public int ComponentCount;
}
- int mVertexCount, mIndexCount;
+ int mVertexCount;
int mVertexBufferID;
- int mIndexBufferID;
- int mTexCoordBufferID;
- int mNormalBufferID;
+
List<AttributeData> mAttributeBuffers = new List<AttributeData>();
- VertexLayout layout;
+ VertexLayout mLayout;
- public GL_VertexBuffer(VertexLayout layout)
+ public GL_VertexBuffer(VertexLayout layout, int count)
{
mDisplay = Display.Impl as GL_Display;
mState = mDisplay.State;
- this.layout = layout;
+ mVertexCount = count;
+ mLayout = layout;
+
+ GL.GenBuffers(1, out mVertexBufferID);
}
- // FYI: use BufferTarget.ElementArrayBuffer to bind to an index buffer.
- private int CreateBuffer(Vector3[] data)
+ public override void Write<T>(T[] vertices)
{
- int bufferID;
- GL.GenBuffers(1, out bufferID);
- GL.BindBuffer(BufferTarget.ArrayBuffer, bufferID);
+ GL.BindBuffer(BufferTarget.ArrayBuffer, mVertexBufferID);
+ int size = vertices.Length * Marshal.SizeOf(typeof(T));
- unsafe
- {
- fixed (Vector3* ptr = data)
- {
- GL.BufferData(
- BufferTarget.ArrayBuffer,
- (IntPtr)(data.Length * Marshal.SizeOf(typeof(Vector3))),
- (IntPtr)ptr,
- BufferUsageHint.StaticDraw);
- }
- }
+ GCHandle h = GCHandle.Alloc(vertices, GCHandleType.Pinned);
- GL.BindBuffer(BufferTarget.ArrayBuffer, 0);
- return bufferID;
- }
- private int CreateBuffer(Vector2[] data)
- {
- int bufferID;
- GL.GenBuffers(1, out bufferID);
- GL.BindBuffer(BufferTarget.ArrayBuffer, bufferID);
+ IntPtr arrayptr = Marshal.UnsafeAddrOfPinnedArrayElement(vertices, 0);
unsafe
{
- fixed (Vector2* ptr = data)
- {
- GL.BufferData(
- BufferTarget.ArrayBuffer,
- (IntPtr)(data.Length * Marshal.SizeOf(typeof(Vector2))),
- (IntPtr)ptr,
- BufferUsageHint.StaticDraw);
- }
- }
+ byte* ptr = (byte*)arrayptr;
- GL.BindBuffer(BufferTarget.ArrayBuffer, 0);
- return bufferID;
- }
- private int CreateIndexBuffer(short[] data)
- {
- int bufferID;
- GL.GenBuffers(1, out bufferID);
- GL.BindBuffer(BufferTarget.ElementArrayBuffer, bufferID);
-
- unsafe
- {
- fixed (short* ptr = data)
- {
- GL.BufferData(
- BufferTarget.ElementArrayBuffer,
- (IntPtr)(data.Length * Marshal.SizeOf(typeof(short))),
- (IntPtr)ptr,
- BufferUsageHint.StaticDraw);
- }
+ GL.BufferData(
+ BufferTarget.ArrayBuffer,
+ (IntPtr)(vertices.Length * Marshal.SizeOf(typeof(T))),
+ (IntPtr)ptr,
+ BufferUsageHint.StaticDraw);
}
- GL.BindBuffer(BufferTarget.ElementArrayBuffer, 0);
- return bufferID;
- }
- public override void WriteVertexData(Vector3[] data)
- {
- mVertexBufferID = CreateBuffer(data);
- mVertexCount = data.Length;
- }
- public override void WriteTextureCoords(Vector2[] texCoords)
- {
- mTexCoordBufferID = CreateBuffer(texCoords);
- }
- public override void WriteNormalData(Vector3[] data)
- {
- mNormalBufferID = CreateBuffer(data);
- }
- public override void WriteIndices(short[] indices)
- {
- mIndexBufferID = CreateIndexBuffer(indices);
- mIndexCount = indices.Length;
- }
- public override void WriteAttributeData(string attributeName, Vector3[] data)
- {
- AttributeData d = new AttributeData { Name = attributeName };
+ h.Free();
- d.BufferID = CreateBuffer(data);
- d.Type = VertexAttribPointerType.Float;
- d.ComponentCount = 3;
-
- mAttributeBuffers.Add(d);
}
+
public override void Draw(int start, int count)
{
+ GL.BindBuffer(BufferTarget.ArrayBuffer, mVertexBufferID);
SetClientStates();
BeginMode beginMode = SelectBeginMode();
- if (Indexed)
- {
- GL.BindBuffer(BufferTarget.ElementArrayBuffer, mIndexBufferID);
- GL.IndexPointer(IndexPointerType.Short, 0, (IntPtr)start);
+ GL.DrawArrays(beginMode, start, count);
+ }
+ public override void DrawIndexed(IndexBuffer indexbuffer, int start, int count)
+ {
+ GL_IndexBuffer gl_indexbuffer = (GL_IndexBuffer) indexbuffer.Impl;
- GL.EnableClientState(EnableCap.VertexArray);
- GL.BindBuffer(BufferTarget.ArrayBuffer, mVertexBufferID);
- GL.VertexPointer(3, VertexPointerType.Float, 0, (IntPtr)0);
+ GL.BindBuffer(BufferTarget.ElementArrayBuffer, gl_indexbuffer.BufferID);
+ GL.IndexPointer(IndexPointerType.Short, 0, (IntPtr)start);
- GL.DrawElements(beginMode, count, DrawElementsType.UnsignedShort, (IntPtr)0);
- }
- else
- {
- GL.EnableClientState(EnableCap.VertexArray);
- GL.BindBuffer(BufferTarget.ArrayBuffer, mVertexBufferID);
- GL.VertexPointer(3, VertexPointerType.Float, 0, (IntPtr)start);
+ GL.BindBuffer(BufferTarget.ArrayBuffer, mVertexBufferID);
+ SetClientStates();
- GL.DrawArrays(beginMode, start, count);
- }
-
+ BeginMode beginMode = SelectBeginMode();
+ GL.DrawElements(beginMode, count, DrawElementsType.UnsignedShort, (IntPtr)0);
}
private void SetAttributes()
@@ -190,30 +119,42 @@
{
GL.Disable(EnableCap.Texture2D);
GL.DisableClientState(EnableCap.TextureCoordArray);
- GL.BindTexture(TextureTarget.Texture2D, 0);
}
if (HasNormals)
{
GL.EnableClientState(EnableCap.NormalArray);
- GL.BindBuffer(BufferTarget.ArrayBuffer, mNormalBufferID);
- GL.NormalPointer(NormalPointerType.Float, 0, IntPtr.Zero);
+ GL.NormalPointer(NormalPointerType.Float, mLayout.VertexSize,
+ (IntPtr) mLayout.ElementByteIndex(VertexElement.Normal));
}
else
{
GL.DisableClientState(EnableCap.NormalArray);
}
+ if (HasPositions)
+ {
+ GL.EnableClientState(EnableCap.VertexArray);
+ GL.VertexPointer(
+ PositionSize / sizeof(float), VertexPointerType.Float, mLayout.VertexSize,
+ (IntPtr)mLayout.ElementByteIndex(VertexElement.Position));
+ }
+
SetAttributes();
}
private void SetTextures()
{
GL.Enable(EnableCap.Texture2D);
- GL.EnableClientState(EnableCap.TextureCoordArray);
- GL.BindBuffer(BufferTarget.ArrayBuffer, mTexCoordBufferID);
- GL.TexCoordPointer(2, TexCoordPointerType.Float, 0, IntPtr.Zero);
+ if (HasTextureCoords)
+ {
+ GL.EnableClientState(EnableCap.TextureCoordArray);
+ GL.TexCoordPointer(
+ 2, TexCoordPointerType.Float, mLayout.VertexSize,
+ (IntPtr)mLayout.ElementByteIndex(VertexElement.Texture));
+ }
+
GlslShader shader = Display.Shader as GlslShader;
if (Textures.ActiveTextures > 1)
@@ -276,10 +217,6 @@
System.Diagnostics.Debug.Print("Error: {0}", err);
}
- public override int IndexCount
- {
- get { return mIndexCount; }
- }
public override int VertexCount
{
get { return mVertexCount; }
@@ -291,11 +228,24 @@
}
public bool HasTextureCoords
{
- get { return mTexCoordBufferID != 0; }
+ get { return mLayout.ContainsElement(VertexElement.Texture); }
}
public bool HasNormals
{
- get { return mNormalBufferID != 0; }
+ get { return mLayout.ContainsElement(VertexElement.Normal); }
}
+ public bool HasPositions
+ {
+ get { return mLayout.ContainsElement(VertexElement.Position); }
+ }
+ public int PositionSize
+ {
+ get
+ {
+ VertexElementDesc d = mLayout.GetElement(VertexElement.Position);
+
+ return VertexLayout.SizeOf(d.DataType);
+ }
+ }
}
}
Modified: branches/agate3d-3.2/Tests/Display3D/Glsl.cs
===================================================================
--- branches/agate3d-3.2/Tests/Display3D/Glsl.cs 2009-04-28 01:26:55 UTC (rev 924)
+++ branches/agate3d-3.2/Tests/Display3D/Glsl.cs 2009-04-28 08:25:11 UTC (rev 925)
@@ -85,28 +85,31 @@
double frequency = 2 * Math.PI / 5;
const float size = 25;
+ //var shader = ShaderCompiler.CompileShader(ShaderLanguage.Glsl,
+ // Shaders.PerPixelLighting_vertex, Shaders.PerPixelLighting_fragment);
+ var shader = ShaderCompiler.CompileShader(ShaderLanguage.Glsl,
+ File.ReadAllText("Data/shaders/BumpMap_vertex.txt"),
+ File.ReadAllText("Data/shaders/BumpMap_fragment.txt"));
+ //var shader = ShaderCompiler.CompileShader(ShaderLanguage.Glsl,
+ // Shaders.BumpMap_vertex, Shaders.PerPixelLighting_fragment);
+
//HeightMapTerrain b = new HeightMapTerrain(height.ReadPixels());
//b.Width = size;
//b.Height = size;
//b.MaxPeak = 1;
CubeBuilder b = new CubeBuilder();
- b.VertexType = VertexLayout.PositionNormalTangentBitangentTexture;
+ //b.VertexType = VertexLayout.PositionNormalTangentBitangentTexture;
b.Length = size;
+ b.CreateVertexBuffer();
- VertexBuffer buffer = b.CreateVertexBuffer();
+ IndexBuffer index = b.IndexBuffer;
+ VertexBuffer buffer = b.VertexBuffer;
buffer.Textures[0] = texture;
buffer.Textures[1] = new Surface(
PixelBuffer.NormalMapFromHeightMap(height.ReadPixels(), 2.0f));
buffer.Textures[1].SaveTo("normal.png");
- //var shader = ShaderCompiler.CompileShader(ShaderLanguage.Glsl,
- // Shaders.PerPixelLighting_vertex, Shaders.PerPixelLighting_fragment);
- var shader = ShaderCompiler.CompileShader(ShaderLanguage.Glsl,
- File.ReadAllText("Data/shaders/BumpMap_vertex.txt"),
- File.ReadAllText("Data/shaders/BumpMap_fragment.txt"));
- //var shader = ShaderCompiler.CompileShader(ShaderLanguage.Glsl,
- // Shaders.BumpMap_vertex, Shaders.PerPixelLighting_fragment);
-
+
resetmouse();
Mouse.Hide();
@@ -164,7 +167,7 @@
Display.MatrixWorld =
Matrix4.Translation(-size / 2, -size / 2, 0) * Matrix4.RotateZ((float)(frequency * time));
- buffer.Draw();
+ buffer.DrawIndexed(index);
Debug.Print("x, y, z = {0}", eye.ToString());
Debug.Print("angle = {0}", phi * 180 / Math.PI);
Modified: branches/agate3d-3.2/Tests/Display3D/Matrices.cs
===================================================================
--- branches/agate3d-3.2/Tests/Display3D/Matrices.cs 2009-04-28 01:26:55 UTC (rev 924)
+++ branches/agate3d-3.2/Tests/Display3D/Matrices.cs 2009-04-28 08:25:11 UTC (rev 925)
@@ -56,8 +56,9 @@
CubeBuilder cube = new CubeBuilder();
cube.Length = 58;
cube.Location = new Vector3(cube.Length / 2, cube.Length / 2, 0);
+ cube.CreateVertexBuffer();
- VertexBuffer b = cube.CreateVertexBuffer();
+ VertexBuffer b = cube.VertexBuffer;
b.Textures[0] = surf;
int lastMyMatrix = matrixIndex - 1;
Modified: branches/agate3d-3.2/Tests/Display3D/Test3d.cs
===================================================================
--- branches/agate3d-3.2/Tests/Display3D/Test3d.cs 2009-04-28 01:26:55 UTC (rev 924)
+++ branches/agate3d-3.2/Tests/Display3D/Test3d.cs 2009-04-28 08:25:11 UTC (rev 925)
@@ -64,8 +64,9 @@
CubeBuilder cube = new CubeBuilder();
cube.Length = 4;
+ cube.CreateVertexBuffer();
- VertexBuffer b = cube.CreateVertexBuffer();
+ VertexBuffer b = cube.VertexBuffer;
b.Textures[0] = surf;
int lastMyMatrix = matrixIndex - 1;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ka...@us...> - 2009-04-28 01:26:59
|
Revision: 924
http://agate.svn.sourceforge.net/agate/?rev=924&view=rev
Author: kanato
Date: 2009-04-28 01:26:55 +0000 (Tue, 28 Apr 2009)
Log Message:
-----------
Add missing shaders and make 3D tests work.
Modified Paths:
--------------
branches/agate3d-3.2/Drivers/AgateOTK/GL_Surface.cs
branches/agate3d-3.2/Tests/Display3D/Glsl.cs
branches/agate3d-3.2/Tests/Display3D/Matrices.cs
branches/agate3d-3.2/Tests/Display3D/Test3d.cs
Added Paths:
-----------
branches/agate3d-3.2/Tests/Data/bg-bricks-heightmap.png
branches/agate3d-3.2/Tests/Data/shaders/
branches/agate3d-3.2/Tests/Data/shaders/BumpMap_fragment.txt
branches/agate3d-3.2/Tests/Data/shaders/BumpMap_vertex.txt
branches/agate3d-3.2/Tests/Data/shaders/PerPixelLighting_fragment.txt
branches/agate3d-3.2/Tests/Data/shaders/PerPixelLighting_vertex.txt
Modified: branches/agate3d-3.2/Drivers/AgateOTK/GL_Surface.cs
===================================================================
--- branches/agate3d-3.2/Drivers/AgateOTK/GL_Surface.cs 2009-04-28 01:08:32 UTC (rev 923)
+++ branches/agate3d-3.2/Drivers/AgateOTK/GL_Surface.cs 2009-04-28 01:26:55 UTC (rev 924)
@@ -167,7 +167,6 @@
public override void Dispose()
{
ReleaseTextureRef();
-
}
public override void Draw(SurfaceState state)
Added: branches/agate3d-3.2/Tests/Data/bg-bricks-heightmap.png
===================================================================
(Binary files differ)
Property changes on: branches/agate3d-3.2/Tests/Data/bg-bricks-heightmap.png
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added: branches/agate3d-3.2/Tests/Data/shaders/BumpMap_fragment.txt
===================================================================
--- branches/agate3d-3.2/Tests/Data/shaders/BumpMap_fragment.txt (rev 0)
+++ branches/agate3d-3.2/Tests/Data/shaders/BumpMap_fragment.txt 2009-04-28 01:26:55 UTC (rev 924)
@@ -0,0 +1,46 @@
+varying vec4 diffuse,ambientGlobal, ambient;
+varying vec3 normal,lightDir,halfVector;
+varying float dist;
+uniform sampler2D texture0;
+uniform sampler2D texture1;
+
+void main()
+{
+ vec3 n,halfV,viewV,ldir;
+ float NdotL,NdotHV;
+ vec4 color = ambientGlobal;
+ float att;
+
+ /* a fragment shader can't write a varying variable, hence we need
+ a new variable to store the normalized interpolated normal */
+ n = normalize(normal);
+
+ // calculate the bumpmap properties
+ vec4 bumpcolor = texture2D(texture1,gl_TexCoord[0].st);
+ bumpcolor = bumpcolor * 2.0 - 1.0;
+ n = normalize(bumpcolor.rgb);
+ //n = vec3(0.707,0,0.707);
+
+ /* compute the dot product between normal and normalized lightdir */
+ NdotL = max(dot(n,normalize(lightDir)),0.0);
+
+ if (NdotL > 0.0) {
+ att = 1.0 / (gl_LightSource[0].constantAttenuation +
+ gl_LightSource[0].linearAttenuation * dist +
+ gl_LightSource[0].quadraticAttenuation * dist * dist);
+
+ color += att * (diffuse * NdotL + ambient);
+
+ halfV = normalize(halfVector);
+ NdotHV = max(dot(n,halfV),0.0);
+ color += att * gl_FrontMaterial.specular * gl_LightSource[0].specular *
+ pow(NdotHV,gl_FrontMaterial.shininess);
+ }
+
+ vec4 texcolor = texture2D(texture0,gl_TexCoord[0].st);
+
+ color.rgb *= texcolor.rgb;
+
+ gl_FragColor = color;
+}
+
Added: branches/agate3d-3.2/Tests/Data/shaders/BumpMap_vertex.txt
===================================================================
--- branches/agate3d-3.2/Tests/Data/shaders/BumpMap_vertex.txt (rev 0)
+++ branches/agate3d-3.2/Tests/Data/shaders/BumpMap_vertex.txt 2009-04-28 01:26:55 UTC (rev 924)
@@ -0,0 +1,43 @@
+
+attribute vec3 tangent; //The inverse tangent to the geometry
+attribute vec3 bitangent; //The inverse binormal to the geometry
+
+varying vec4 diffuse,ambientGlobal,ambient;
+varying vec3 normal,lightDir,halfVector;
+varying float dist;
+
+void main()
+{
+ vec3 aux;
+
+ normal = normalize(gl_Normal);
+
+ // Building the matrix Eye Space -> Tangent Space
+ vec3 n = normalize (gl_NormalMatrix * gl_Normal);
+ vec3 t = normalize (gl_NormalMatrix * tangent);
+ vec3 b = normalize (gl_NormalMatrix * bitangent);
+
+ vec4 evPos = gl_ModelViewMatrix * gl_Vertex;
+ vec3 lightVec = vec3(gl_LightSource[0].position.xyz - evPos.xyz);
+
+ vec3 v;
+ v.x = dot(lightVec, t);
+ v.y = dot(lightVec, b);
+ v.z = dot(lightVec, n);
+ lightDir = normalize(v);
+
+ dist = length(lightVec);
+
+ halfVector = normalize(gl_LightSource[0].halfVector.xyz);
+
+ /* Compute the diffuse, ambient and globalAmbient terms */
+ diffuse = gl_FrontMaterial.diffuse * gl_LightSource[0].diffuse;
+
+ /* The ambient terms have been separated since one of them */
+ /* suffers attenuation */
+ ambient = gl_FrontMaterial.ambient * gl_LightSource[0].ambient;
+ ambientGlobal = gl_LightModel.ambient * gl_FrontMaterial.ambient;
+
+ gl_Position = ftransform();
+ gl_TexCoord[0] = gl_MultiTexCoord0;
+}
Added: branches/agate3d-3.2/Tests/Data/shaders/PerPixelLighting_fragment.txt
===================================================================
--- branches/agate3d-3.2/Tests/Data/shaders/PerPixelLighting_fragment.txt (rev 0)
+++ branches/agate3d-3.2/Tests/Data/shaders/PerPixelLighting_fragment.txt 2009-04-28 01:26:55 UTC (rev 924)
@@ -0,0 +1,40 @@
+varying vec4 diffuse,ambientGlobal, ambient;
+varying vec3 normal,lightDir,halfVector;
+varying float dist;
+uniform sampler2D texture0;
+
+
+void main()
+{
+ vec3 n,halfV,viewV,ldir;
+ float NdotL,NdotHV;
+ vec4 color = ambientGlobal;
+ float att;
+
+ /* a fragment shader can't write a varying variable, hence we need
+ a new variable to store the normalized interpolated normal */
+ n = normalize(normal);
+
+ /* compute the dot product between normal and normalized lightdir */
+ NdotL = max(dot(n,normalize(lightDir)),0.0);
+
+ if (NdotL > 0.0) {
+ att = 1.0 / (gl_LightSource[0].constantAttenuation +
+ gl_LightSource[0].linearAttenuation * dist +
+ gl_LightSource[0].quadraticAttenuation * dist * dist);
+
+ color += att * (diffuse * NdotL + ambient);
+
+ halfV = normalize(halfVector);
+ NdotHV = max(dot(n,halfV),0.0);
+ color += att * gl_FrontMaterial.specular * gl_LightSource[0].specular *
+ pow(NdotHV,gl_FrontMaterial.shininess);
+ }
+
+ vec4 texcolor = texture2D(texture0,gl_TexCoord[0].st);
+
+ color.rgb *= texcolor.rgb;
+
+ gl_FragColor = color;
+}
+
Added: branches/agate3d-3.2/Tests/Data/shaders/PerPixelLighting_vertex.txt
===================================================================
--- branches/agate3d-3.2/Tests/Data/shaders/PerPixelLighting_vertex.txt (rev 0)
+++ branches/agate3d-3.2/Tests/Data/shaders/PerPixelLighting_vertex.txt 2009-04-28 01:26:55 UTC (rev 924)
@@ -0,0 +1,31 @@
+varying vec4 diffuse,ambientGlobal,ambient;
+varying vec3 normal,lightDir,halfVector;
+varying float dist;
+
+void main()
+{
+ vec4 ecPos;
+ vec3 aux;
+
+ normal = normalize(gl_NormalMatrix * gl_Normal);
+
+ /* these are the new lines of code to compute the light's direction */
+ ecPos = gl_ModelViewMatrix * gl_Vertex;
+ aux = vec3(gl_LightSource[0].position-ecPos);
+ lightDir = normalize(aux);
+ dist = length(aux);
+
+ halfVector = normalize(gl_LightSource[0].halfVector.xyz);
+
+ /* Compute the diffuse, ambient and globalAmbient terms */
+ diffuse = gl_FrontMaterial.diffuse * gl_LightSource[0].diffuse;
+
+ /* The ambient terms have been separated since one of them */
+ /* suffers attenuation */
+ ambient = gl_FrontMaterial.ambient * gl_LightSource[0].ambient;
+ ambientGlobal = gl_LightModel.ambient * gl_FrontMaterial.ambient;
+
+
+ gl_Position = ftransform();
+ gl_TexCoord[0] = gl_MultiTexCoord0;
+}
Modified: branches/agate3d-3.2/Tests/Display3D/Glsl.cs
===================================================================
--- branches/agate3d-3.2/Tests/Display3D/Glsl.cs 2009-04-28 01:08:32 UTC (rev 923)
+++ branches/agate3d-3.2/Tests/Display3D/Glsl.cs 2009-04-28 01:26:55 UTC (rev 924)
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
+using System.IO;
using System.Linq;
using System.Text;
using AgateLib;
@@ -10,19 +11,29 @@
using AgateLib.Geometry;
using AgateLib.InputLib;
-namespace Glsl
+namespace Tests.Display3D.Glsl
{
- public class Glsl
+ public class Glsl: IAgateTest
{
- /// <summary>
- /// The main entry point for the application.
- /// </summary>
- [STAThread]
- static void Main(string[] args)
+ #region IAgateTest Members
+
+ public string Name
{
- new Glsl().Run(args);
+ get { return "Glsl"; }
}
+ public string Category
+ {
+ get { return "Display 3D"; }
+ }
+
+ void IAgateTest.Main(string[] args)
+ {
+ Run(args);
+ }
+
+ #endregion
+
bool rotating = false;
const float velocity = 0.04f;
const float mousevelocity = 0.004f;
@@ -46,11 +57,6 @@
}
private void Run(string[] args)
{
- // These two lines are used by AgateLib tests to locate
- // driver plugins and images.
- AgateLib.AgateFileProvider.Assemblies.AddPath("../Drivers");
- AgateLib.AgateFileProvider.Images.AddPath("../../../Tests/TestImages");
-
using (AgateSetup setup = new AgateSetup(args))
{
setup.Initialize(true, false, false);
@@ -93,12 +99,12 @@
PixelBuffer.NormalMapFromHeightMap(height.ReadPixels(), 2.0f));
buffer.Textures[1].SaveTo("normal.png");
- ShaderProgram shader = null;
//var shader = ShaderCompiler.CompileShader(ShaderLanguage.Glsl,
// Shaders.PerPixelLighting_vertex, Shaders.PerPixelLighting_fragment);
+ var shader = ShaderCompiler.CompileShader(ShaderLanguage.Glsl,
+ File.ReadAllText("Data/shaders/BumpMap_vertex.txt"),
+ File.ReadAllText("Data/shaders/BumpMap_fragment.txt"));
//var shader = ShaderCompiler.CompileShader(ShaderLanguage.Glsl,
- // Shaders.BumpMap_vertex, Shaders.BumpMap_fragment);
- //var shader = ShaderCompiler.CompileShader(ShaderLanguage.Glsl,
// Shaders.BumpMap_vertex, Shaders.PerPixelLighting_fragment);
resetmouse();
Modified: branches/agate3d-3.2/Tests/Display3D/Matrices.cs
===================================================================
--- branches/agate3d-3.2/Tests/Display3D/Matrices.cs 2009-04-28 01:08:32 UTC (rev 923)
+++ branches/agate3d-3.2/Tests/Display3D/Matrices.cs 2009-04-28 01:26:55 UTC (rev 924)
@@ -8,19 +8,28 @@
using AgateLib.Geometry.Builders;
using AgateLib.InputLib;
-namespace TestMatrices
+namespace Tests.Display3D.TestMatrices
{
- public class Matrices
+ public class Matrices : IAgateTest
{
- /// <summary>
- /// The main entry point for the application.
- /// </summary>
- [STAThread]
- static void Main(string[] args)
+ #region IAgateTest Members
+
+ public string Name
{
- new Matrices().Run(args);
+ get { return "Matrices"; }
}
+ public string Category
+ {
+ get { return "Display 3D"; }
+ }
+
+ void IAgateTest.Main(string[] args)
+ {
+ Run(args);
+ }
+
+ #endregion
static int matrixIndex = 1;
static int move, turn;
Modified: branches/agate3d-3.2/Tests/Display3D/Test3d.cs
===================================================================
--- branches/agate3d-3.2/Tests/Display3D/Test3d.cs 2009-04-28 01:08:32 UTC (rev 923)
+++ branches/agate3d-3.2/Tests/Display3D/Test3d.cs 2009-04-28 01:26:55 UTC (rev 924)
@@ -9,15 +9,34 @@
using AgateLib.DisplayLib;
using AgateLib.InputLib;
-namespace Test3D
+namespace Tests.Display3D.Test3D
{
- class Test3d
+ class Test3d : IAgateTest
{
- static int matrixIndex = 1;
- static int move, turn;
+ #region IAgateTest Members
- static void Main(string[] args)
+ public string Name
{
+ get { return "Test 3D"; }
+ }
+
+ public string Category
+ {
+ get { return "Display 3D"; }
+ }
+
+ void IAgateTest.Main(string[] args)
+ {
+ Run(args);
+ }
+
+ #endregion
+
+ int matrixIndex = 1;
+ int move, turn;
+
+ void Run(string[] args)
+ {
System.IO.FileStream fs = new System.IO.FileStream(@"c:\cube.obj", System.IO.FileMode.Open, System.IO.FileAccess.Read);
AgateLib.Meshes.Loaders.Obj.OBJFileRepresentation objRep = new AgateLib.Meshes.Loaders.Obj.OBJFileRepresentation(fs);
@@ -150,19 +169,19 @@
}
}
- private static Vector3 CalculateLookDirection(float facingAngle)
+ private Vector3 CalculateLookDirection(float facingAngle)
{
return new Vector3(Math.Cos(facingAngle), Math.Sin(facingAngle), 0);
}
- private static Vector3 CalculateLookTarget(Vector3 position, float facingAngle)
+ private Vector3 CalculateLookTarget(Vector3 position, float facingAngle)
{
Vector3 lookTarget = position;
lookTarget += new Vector3(Math.Cos(facingAngle), Math.Sin(facingAngle), 0);
return lookTarget;
}
- static void Keyboard_KeyUp(InputEventArgs e)
+ void Keyboard_KeyUp(InputEventArgs e)
{
if (e.KeyCode == KeyCode.Up || e.KeyCode == KeyCode.Down)
move = 0;
@@ -170,7 +189,7 @@
turn = 0;
}
- static void Keyboard_KeyDown(AgateLib.InputLib.InputEventArgs e)
+ void Keyboard_KeyDown(AgateLib.InputLib.InputEventArgs e)
{
if (e.KeyCode == AgateLib.InputLib.KeyCode.Space)
matrixIndex++;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ka...@us...> - 2009-04-28 01:08:39
|
Revision: 923
http://agate.svn.sourceforge.net/agate/?rev=923&view=rev
Author: kanato
Date: 2009-04-28 01:08:32 +0000 (Tue, 28 Apr 2009)
Log Message:
-----------
Initial commit of merging agate-3d branch.
Modified Paths:
--------------
branches/agate3d-3.2/AgateLib/AgateException.cs
branches/agate3d-3.2/AgateLib/DisplayLib/Display.cs
branches/agate3d-3.2/AgateLib/DisplayLib/PixelBuffer.cs
branches/agate3d-3.2/AgateLib/Drivers/IDesktopDriver.cs
branches/agate3d-3.2/AgateLib/Geometry/Builders/Cube.cs
branches/agate3d-3.2/AgateLib/Geometry/Color.cs
branches/agate3d-3.2/AgateLib/Geometry/Rectangle.cs
branches/agate3d-3.2/AgateLib/Geometry/RectangleF.cs
branches/agate3d-3.2/AgateLib/Geometry/Vector3.cs
branches/agate3d-3.2/AgateLib/ImplementationBase/DisplayImpl.cs
branches/agate3d-3.2/AgateLib/ImplementationBase/IDisplayCaps.cs
branches/agate3d-3.2/AgateLib/InputLib/Mouse.cs
branches/agate3d-3.2/AgateLib/Resources/AgateResourceCollection.cs
branches/agate3d-3.2/AgateLib/Resources/AgateResourceException.cs
branches/agate3d-3.2/AgateLib/Resources/AgateResourceLoader.cs
branches/agate3d-3.2/Build/monodevelop.sh
branches/agate3d-3.2/Drivers/AgateDrawing/Drawing_Display.cs
branches/agate3d-3.2/Drivers/AgateLib.WinForms/Icons.Designer.cs
branches/agate3d-3.2/Drivers/AgateMDX/DrawBuffer.cs
branches/agate3d-3.2/Drivers/AgateMDX/MDX1_Display.cs
branches/agate3d-3.2/Drivers/AgateOTK/GL_Display.cs
branches/agate3d-3.2/Drivers/AgateOTK/GL_GameWindow.cs
branches/agate3d-3.2/Drivers/AgateOTK/GL_Surface.cs
branches/agate3d-3.2/Drivers/AgateOTK/OpenTK.Utilities.dll
branches/agate3d-3.2/Drivers/AgateOTK/OpenTK.dll
branches/agate3d-3.2/Drivers/AgateOTK/OpenTK.xml
branches/agate3d-3.2/Drivers/AgateOTK/Otk_Reporter.cs
branches/agate3d-3.2/Drivers/AgateSDL/Reporter.cs
Added Paths:
-----------
branches/agate3d-3.2/AgateLib/DisplayLib/PrimitiveType.cs
branches/agate3d-3.2/AgateLib/DisplayLib/Shaders/
branches/agate3d-3.2/AgateLib/DisplayLib/Shaders/PixelShader.cs
branches/agate3d-3.2/AgateLib/DisplayLib/Shaders/ShaderCompiler.cs
branches/agate3d-3.2/AgateLib/DisplayLib/Shaders/ShaderLanguage.cs
branches/agate3d-3.2/AgateLib/DisplayLib/Shaders/ShaderProgram.cs
branches/agate3d-3.2/AgateLib/DisplayLib/Shaders/VertexShader.cs
branches/agate3d-3.2/AgateLib/DisplayLib/VertexBuffer.cs
branches/agate3d-3.2/AgateLib/Geometry/Builders/
branches/agate3d-3.2/AgateLib/Geometry/Builders/Terrain.cs
branches/agate3d-3.2/AgateLib/Geometry/Matrix4.cs
branches/agate3d-3.2/AgateLib/Geometry/Vector4.cs
branches/agate3d-3.2/AgateLib/ImplementationBase/ShaderCompilerImpl.cs
branches/agate3d-3.2/AgateLib/ImplementationBase/VertexBufferImpl.cs
branches/agate3d-3.2/AgateLib/Meshes/
branches/agate3d-3.2/AgateLib/Meshes/Loaders/
branches/agate3d-3.2/AgateLib/Meshes/Loaders/Obj/
branches/agate3d-3.2/AgateLib/Meshes/Loaders/Obj/OBJFileRepresentation.cs
branches/agate3d-3.2/AgateLib/Meshes/Loaders/Obj/Parser.cs
branches/agate3d-3.2/AgateLib/Meshes/Loaders/Obj/TokenTypes.cs
branches/agate3d-3.2/Drivers/AgateMDX/MDX1_VertexBuffer.cs
branches/agate3d-3.2/Drivers/AgateOTK/ArbShader.cs
branches/agate3d-3.2/Drivers/AgateOTK/GL_VertexBuffer.cs
branches/agate3d-3.2/Drivers/AgateOTK/GlslFragmentProgram.cs
branches/agate3d-3.2/Drivers/AgateOTK/GlslShader.cs
branches/agate3d-3.2/Drivers/AgateOTK/GlslShaderCompiler.cs
branches/agate3d-3.2/Drivers/AgateOTK/GlslVertexProgram.cs
branches/agate3d-3.2/Drivers/AgateOTK/OtkShader.cs
branches/agate3d-3.2/Tests/Display3D/
branches/agate3d-3.2/Tests/Display3D/Glsl.cs
branches/agate3d-3.2/Tests/Display3D/Matrices.cs
branches/agate3d-3.2/Tests/Display3D/Test3d.cs
Removed Paths:
-------------
branches/agate3d-3.2/AgateLib/DisplayLib/Shaders/PixelShader.cs
branches/agate3d-3.2/AgateLib/DisplayLib/Shaders/ShaderCompiler.cs
branches/agate3d-3.2/AgateLib/DisplayLib/Shaders/ShaderLanguage.cs
branches/agate3d-3.2/AgateLib/DisplayLib/Shaders/ShaderProgram.cs
branches/agate3d-3.2/AgateLib/DisplayLib/Shaders/VertexShader.cs
branches/agate3d-3.2/AgateLib/Meshes/Loaders/
branches/agate3d-3.2/AgateLib/Meshes/Loaders/Obj/OBJFileRepresentation.cs
branches/agate3d-3.2/AgateLib/Meshes/Loaders/Obj/Parser.cs
branches/agate3d-3.2/AgateLib/Meshes/Loaders/Obj/TokenTypes.cs
Property Changed:
----------------
branches/agate3d-3.2/
branches/agate3d-3.2/AgateLib/
branches/agate3d-3.2/AgateLib/AgateSetup.cs
branches/agate3d-3.2/AgateLib/AudioLib/
branches/agate3d-3.2/AgateLib/AudioLib/Audio.cs
branches/agate3d-3.2/AgateLib/BitmapFont/FontMetrics.cs
branches/agate3d-3.2/AgateLib/BitmapFont/GlyphMetrics.cs
branches/agate3d-3.2/AgateLib/Core.cs
branches/agate3d-3.2/AgateLib/DisplayLib/
branches/agate3d-3.2/AgateLib/DisplayLib/Display.cs
branches/agate3d-3.2/AgateLib/DisplayLib/StringTransformer.cs
branches/agate3d-3.2/AgateLib/Drivers/AgateDriverReporter.cs
branches/agate3d-3.2/AgateLib/Drivers/IDesktopDriver.cs
branches/agate3d-3.2/AgateLib/ImplementationBase/
branches/agate3d-3.2/AgateLib/ImplementationBase/AudioImpl.cs
branches/agate3d-3.2/AgateLib/InputLib/
branches/agate3d-3.2/AgateLib/Resources/AgateResourceCollection.cs
branches/agate3d-3.2/AgateLib/Resources/AgateResourceLoader.cs
branches/agate3d-3.2/AgateLib/Resources/BitmapFontResource.cs
branches/agate3d-3.2/AgateLib/Timing.cs
branches/agate3d-3.2/AgateLib/Utility/Platform.cs
branches/agate3d-3.2/Build/monodevelop.sh
branches/agate3d-3.2/Drivers/
branches/agate3d-3.2/Drivers/AgateDrawing/Drawing_Reporter.cs
branches/agate3d-3.2/Drivers/AgateLib.WinForms/
branches/agate3d-3.2/Drivers/AgateSDL/
branches/agate3d-3.2/Drivers/AgateSDL/Audio/SDL_Audio.cs
branches/agate3d-3.2/Drivers/AgateSDL/Audio/SDL_Music.cs
branches/agate3d-3.2/Drivers/AgateSDL/Audio/SDL_SoundBuffer.cs
branches/agate3d-3.2/Drivers/AgateSDL/Audio/SDL_SoundBufferSession.cs
branches/agate3d-3.2/Drivers/AgateSDL/Reporter.cs
branches/agate3d-3.2/Examples/BallBuster.Net/OpenTK.dll.config
branches/agate3d-3.2/Tools/FontCreator/SaveFont.Designer.cs
branches/agate3d-3.2/Tools/FontCreator/SaveFont.cs
branches/agate3d-3.2/Tools/FontCreator/SaveFont.resx
branches/agate3d-3.2/Tools/FontCreator/frmFontCreator.Designer.cs
branches/agate3d-3.2/Tools/FontCreator/frmFontCreator.cs
branches/agate3d-3.2/Tools/FontCreator/frmFontCreator.resx
branches/agate3d-3.2/Tools/PackedSpriteCreator/SpriteEditor.Designer.cs
branches/agate3d-3.2/Tools/PackedSpriteCreator/SpriteEditor.cs
branches/agate3d-3.2/Tools/PackedSpriteCreator/SpriteEditor.resx
branches/agate3d-3.2/Tools/PackedSpriteCreator/SpritePacker.cs
Property changes on: branches/agate3d-3.2
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/agate-3d:659
/branches/build:424-517
/branches/font:778-916
/branches/merge-tests:806-810
/branches/registrar:595-599
/branches/sprites:463-513
+ /branches/agate-3d:629-702,840-864
/branches/build:424-517
/branches/font:778-916
/branches/merge-tests:806-810
/branches/registrar:595-599
/branches/sprites:463-513
Property changes on: branches/agate3d-3.2/AgateLib
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/agate-3d/AgateLib:659
/branches/build/AgateLib:447-517
/branches/font/AgateLib:778-916
/branches/merge-tests/AgateLib:806-810
/branches/registrar/AgateLib:595-599
/branches/sprites/AgateLib:463-513
+ /branches/agate-3d/AgateLib:629-702,840-864
/branches/build/AgateLib:447-517
/branches/font/AgateLib:778-916
/branches/merge-tests/AgateLib:806-810
/branches/registrar/AgateLib:595-599
/branches/sprites/AgateLib:463-513
Modified: branches/agate3d-3.2/AgateLib/AgateException.cs
===================================================================
--- branches/agate3d-3.2/AgateLib/AgateException.cs 2009-04-27 05:52:15 UTC (rev 922)
+++ branches/agate3d-3.2/AgateLib/AgateException.cs 2009-04-28 01:08:32 UTC (rev 923)
@@ -46,10 +46,21 @@
/// <summary>
/// Constructs an AgateException.
/// </summary>
- public AgateException(string message, Exception inner) : base(message, inner) { }
+ public AgateException(Exception inner, string message) : base(message, inner) { }
/// <summary>
+ /// Constructs an AgateException, calling string.Format on the arguments.
+ /// </summary>
+ public AgateException(string format, params object[] args)
+ : base(string.Format(format, args)) { }
+ /// <summary>
/// Constructs an AgateException.
/// </summary>
+ public AgateException(Exception inner, string format, params object[] args)
+ : base(string.Format(format, args), inner) { }
+
+ /// <summary>
+ /// Deserializes an AgateException.
+ /// </summary>
protected AgateException(
System.Runtime.Serialization.SerializationInfo info,
System.Runtime.Serialization.StreamingContext context)
@@ -93,4 +104,4 @@
System.Runtime.Serialization.StreamingContext context)
: base(info, context) { }
}
-}
+}
\ No newline at end of file
Property changes on: branches/agate3d-3.2/AgateLib/AgateSetup.cs
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/agate-3d/AgateLib/AgateSetup.cs:659
/branches/build/AgateLib/AgateSetup.cs:501-517
/branches/font/AgateLib/AgateSetup.cs:778-916
/branches/merge-tests/AgateLib/AgateSetup.cs:806-810
/branches/registrar/AgateLib/AgateSetup.cs:595-599
/branches/sprites/AgateLib/AgateSetup.cs:463-513
+ /branches/agate-3d/AgateLib/AgateSetup.cs:629-702,840-864
/branches/build/AgateLib/AgateSetup.cs:501-517
/branches/font/AgateLib/AgateSetup.cs:778-916
/branches/merge-tests/AgateLib/AgateSetup.cs:806-810
/branches/registrar/AgateLib/AgateSetup.cs:595-599
/branches/sprites/AgateLib/AgateSetup.cs:463-513
Property changes on: branches/agate3d-3.2/AgateLib/AudioLib
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/agate-3d/AgateLib/AudioLib:659
/branches/font/AgateLib/AudioLib:778-916
/branches/merge-tests/AgateLib/AudioLib:806-810
/branches/registrar/AgateLib/AudioLib:595-599
/branches/sprites/AgateLib/AudioLib:463-513
+ /branches/agate-3d/AgateLib/AudioLib:629-702,840-864
/branches/font/AgateLib/AudioLib:778-916
/branches/merge-tests/AgateLib/AudioLib:806-810
/branches/registrar/AgateLib/AudioLib:595-599
/branches/sprites/AgateLib/AudioLib:463-513
Property changes on: branches/agate3d-3.2/AgateLib/AudioLib/Audio.cs
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/agate-3d/AgateLib/AudioLib/Audio.cs:659
/branches/build/AgateLib/AudioLib/Audio.cs:501-517
/branches/font/AgateLib/AudioLib/Audio.cs:778-916
/branches/merge-tests/AgateLib/AudioLib/Audio.cs:806-810
/branches/registrar/AgateLib/AudioLib/Audio.cs:595-599
/branches/sprites/AgateLib/AudioLib/Audio.cs:463-513
+ /branches/agate-3d/AgateLib/AudioLib/Audio.cs:629-702,840-864
/branches/build/AgateLib/AudioLib/Audio.cs:501-517
/branches/font/AgateLib/AudioLib/Audio.cs:778-916
/branches/merge-tests/AgateLib/AudioLib/Audio.cs:806-810
/branches/registrar/AgateLib/AudioLib/Audio.cs:595-599
/branches/sprites/AgateLib/AudioLib/Audio.cs:463-513
Property changes on: branches/agate3d-3.2/AgateLib/BitmapFont/FontMetrics.cs
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/agate-3d/AgateLib/BitmapFont/FontMetrics.cs:659
/branches/font/AgateLib/BitmapFont/FontMetrics.cs:778-916
/branches/merge-tests/AgateLib/BitmapFont/FontMetrics.cs:806-810
+ /branches/agate-3d/AgateLib/BitmapFont/FontMetrics.cs:629-702,840-864
/branches/font/AgateLib/BitmapFont/FontMetrics.cs:778-916
/branches/merge-tests/AgateLib/BitmapFont/FontMetrics.cs:806-810
Property changes on: branches/agate3d-3.2/AgateLib/BitmapFont/GlyphMetrics.cs
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/agate-3d/AgateLib/BitmapFont/GlyphMetrics.cs:659
/branches/build/AgateLib/Resources/GlyphMetrics.cs:447-517
/branches/font/AgateLib/BitmapFont/GlyphMetrics.cs:778-916
/branches/merge-tests/AgateLib/BitmapFont/GlyphMetrics.cs:806-810
/branches/registrar/AgateLib/Resources/GlyphMetrics.cs:595-599
/branches/sprites/AgateLib/Resources/GlyphMetrics.cs:463-513
+ /branches/agate-3d/AgateLib/BitmapFont/GlyphMetrics.cs:629-702,840-864
/branches/build/AgateLib/Resources/GlyphMetrics.cs:447-517
/branches/font/AgateLib/BitmapFont/GlyphMetrics.cs:778-916
/branches/merge-tests/AgateLib/BitmapFont/GlyphMetrics.cs:806-810
/branches/registrar/AgateLib/Resources/GlyphMetrics.cs:595-599
/branches/sprites/AgateLib/Resources/GlyphMetrics.cs:463-513
Property changes on: branches/agate3d-3.2/AgateLib/Core.cs
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/agate-3d/AgateLib/Core.cs:659
/branches/build/AgateLib/Core.cs:501-517
/branches/font/AgateLib/Core.cs:778-916
/branches/merge-tests/AgateLib/Core.cs:806-810
/branches/registrar/AgateLib/Core.cs:595-599
/branches/sprites/AgateLib/Core.cs:463-513
+ /branches/agate-3d/AgateLib/Core.cs:629-702,840-864
/branches/build/AgateLib/Core.cs:501-517
/branches/font/AgateLib/Core.cs:778-916
/branches/merge-tests/AgateLib/Core.cs:806-810
/branches/registrar/AgateLib/Core.cs:595-599
/branches/sprites/AgateLib/Core.cs:463-513
Property changes on: branches/agate3d-3.2/AgateLib/DisplayLib
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/agate-3d/AgateLib/DisplayLib:659
/branches/font/AgateLib/DisplayLib:778-916
/branches/merge-tests/AgateLib/DisplayLib:806-810
/branches/registrar/AgateLib/DisplayLib:595-599
/branches/sprites/AgateLib/DisplayLib:463-513
+ /branches/agate-3d/AgateLib/DisplayLib:629-702,840-864
/branches/font/AgateLib/DisplayLib:778-916
/branches/merge-tests/AgateLib/DisplayLib:806-810
/branches/registrar/AgateLib/DisplayLib:595-599
/branches/sprites/AgateLib/DisplayLib:463-513
Modified: branches/agate3d-3.2/AgateLib/DisplayLib/Display.cs
===================================================================
--- branches/agate3d-3.2/AgateLib/DisplayLib/Display.cs 2009-04-27 05:52:15 UTC (rev 922)
+++ branches/agate3d-3.2/AgateLib/DisplayLib/Display.cs 2009-04-28 01:08:32 UTC (rev 923)
@@ -91,7 +91,11 @@
impl.Initialize();
mSurfacePacker = new SurfacePacker();
+ }
+ private static ShaderCompilerImpl CreateShaderCompiler()
+ {
+ return impl.CreateShaderCompiler();
}
/// <summary>
/// Disposes of the Display.
@@ -125,6 +129,12 @@
}
}
+ public static Shaders.ShaderProgram Shader
+ {
+ get { return impl.Shader; }
+ set { impl.Shader = value; }
+ }
+
/// <summary>
/// Delegate type for functions which are called when Display.Dispose is called
/// at the end of execution of the program.
@@ -522,9 +532,31 @@
{
if (pts.Length % 2 == 1)
throw new ArgumentException("pts argument is not an even number of points!");
-
impl.DrawLineSegments(pts, color);
}
+
+ #region --- Matrix Settings ---
+
+ public static Matrix4 MatrixProjection
+ {
+ get { return impl.MatrixProjection; }
+ set { impl.MatrixProjection = value; }
+ }
+ public static Matrix4 MatrixView
+ {
+ get { return impl.MatrixView; }
+ set { impl.MatrixView = value; }
+ }
+ public static Matrix4 MatrixWorld
+ {
+ get { return impl.MatrixWorld; }
+ set { impl.MatrixWorld = value; }
+ }
+
+
+ #endregion
+
+
/// <summary>
/// Draws the outline of a rectangle.
/// </summary>
@@ -661,6 +693,4 @@
}
}
-
-
}
Property changes on: branches/agate3d-3.2/AgateLib/DisplayLib/Display.cs
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/agate-3d/AgateLib/DisplayLib/Display.cs:659
/branches/build/AgateLib/DisplayLib/Display.cs:501-517
/branches/font/AgateLib/DisplayLib/Display.cs:778-916
/branches/merge-tests/AgateLib/DisplayLib/Display.cs:806-810
/branches/registrar/AgateLib/DisplayLib/Display.cs:595-599
/branches/sprites/AgateLib/DisplayLib/Display.cs:463-513
+ /branches/agate-3d/AgateLib/DisplayLib/Display.cs:629-702,840-864
/branches/build/AgateLib/DisplayLib/Display.cs:501-517
/branches/font/AgateLib/DisplayLib/Display.cs:778-916
/branches/merge-tests/AgateLib/DisplayLib/Display.cs:806-810
/branches/registrar/AgateLib/DisplayLib/Display.cs:595-599
/branches/sprites/AgateLib/DisplayLib/Display.cs:463-513
Modified: branches/agate3d-3.2/AgateLib/DisplayLib/PixelBuffer.cs
===================================================================
--- branches/agate3d-3.2/AgateLib/DisplayLib/PixelBuffer.cs 2009-04-27 05:52:15 UTC (rev 922)
+++ branches/agate3d-3.2/AgateLib/DisplayLib/PixelBuffer.cs 2009-04-28 01:08:32 UTC (rev 923)
@@ -30,7 +30,7 @@
/// construct or modify surface data programmatically.
/// </summary>
[Serializable]
- public sealed class PixelBuffer
+ public sealed class PixelBuffer : ICloneable
{
#region --- Private Data ---
@@ -174,6 +174,14 @@
{
this.CopyFrom(buffer, srcRect, new Point(0, 0), false);
}
+ /// <summary>
+ /// Returns a deep copy of the PixelBuffer object.
+ /// </summary>
+ /// <returns></returns>
+ public PixelBuffer Clone()
+ {
+ return new PixelBuffer(this, new Rectangle(0, 0, Width, Height));
+ }
/// <summary>
/// Loads image data from a file and returns a PixelBuffer.
@@ -985,8 +993,106 @@
}
#endregion
+ #region --- ICloneable Members ---
+ object ICloneable.Clone()
+ {
+ return Clone();
+ }
+ #endregion
+ #region --- Normal Map conversion routines ---
+
+ /// <summary>
+ /// Creates a normal map by interpreting the pixel data in the passed buffer
+ /// as a height map.
+ /// </summary>
+ /// <param name="buffer"></param>
+ /// <returns></returns>
+ public static PixelBuffer NormalMapFromHeightMap(PixelBuffer buffer)
+ {
+ return NormalMapFromHeightMap(buffer, 1.0f);
+ }
+ /// <summary>
+ /// Creates a normal map by interpreting the pixel data in the passed buffer
+ /// as a height map.
+ /// </summary>
+ /// <param name="buffer"></param>
+ /// <param name="normalStr">The weight for the x-y components of the normals in
+ /// the normal map. Smaller values make the normal map more subtle.
+ /// Values in the range 0.5f to 3.0f are reasonable.</param>
+ /// <returns></returns>
+ public static PixelBuffer NormalMapFromHeightMap(PixelBuffer buffer, float normalStr)
+ {
+ int[,] heights = new int[buffer.Width, buffer.Height];
+
+ for (int j = 0; j < buffer.Height; j++)
+ {
+ for (int i = 0; i < buffer.Width; i++)
+ {
+ heights[i, j] = (int)(buffer.GetPixel(i, j).Intensity * short.MaxValue);
+ }
+ }
+
+ PixelBuffer retval = new PixelBuffer(buffer.PixelFormat, buffer.Size);
+ int[,] square = new int[3, 3];
+
+ for (int j = 0; j < retval.Height; j++)
+ {
+ for (int i = 0; i < retval.Width; i++)
+ {
+ GetSquare(square, heights, i, j);
+
+ // sobel operator:
+ int diffx = square[0, 0] - square[2, 0] +
+ 2 * (square[0, 1] - square[2, 1]) +
+ square[0, 2] - square[2, 0];
+
+ int diffy = square[0, 0] + 2 * square[1, 0] + square[0, 2] +
+ -square[0, 2] - 2 * square[1, 2] - square[2, 2];
+
+ Vector3 vec = new Vector3(diffx / (float)short.MaxValue, diffy / (float)short.MaxValue, 0);
+ vec *= normalStr;
+ vec.Z = 1;
+
+ vec = vec.Normalize();
+ vec = vec / 2;
+ vec.X += 0.5f; vec.Y += 0.5f; vec.Z += 0.5f;
+ Color clr = Color.FromArgb((int)(vec.X * 255),
+ (int)(vec.Y * 255),
+ (int)(vec.Z * 255));
+
+ retval.SetPixel(i, j, clr);
+ }
+ }
+
+ return retval;
+ }
+
+ private static void GetSquare(int[,] square, int[,] heights, int x, int y)
+ {
+ for (int j = -1; j <= 1; j++)
+ {
+ for (int i = -1; i <= 1; i++)
+ {
+ int val = GetValueWrap(heights, x + i, y + j);
+
+ square[i + 1, j + 1] = val;
+ }
+ }
+ }
+
+ private static int GetValueWrap(int[,] heights, int x, int y)
+ {
+ if (x < 0) x += heights.GetUpperBound(0) + 1;
+ if (y < 0) y += heights.GetUpperBound(1) + 1;
+ if (x > heights.GetUpperBound(0)) x -= heights.GetUpperBound(0) + 1;
+ if (y > heights.GetUpperBound(1)) y -= heights.GetUpperBound(1) + 1;
+
+ return heights[x, y];
+ }
+
+ #endregion
}
}
Added: branches/agate3d-3.2/AgateLib/DisplayLib/PrimitiveType.cs
===================================================================
--- branches/agate3d-3.2/AgateLib/DisplayLib/PrimitiveType.cs (rev 0)
+++ branches/agate3d-3.2/AgateLib/DisplayLib/PrimitiveType.cs 2009-04-28 01:08:32 UTC (rev 923)
@@ -0,0 +1,13 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace AgateLib.DisplayLib
+{
+ public enum PrimitiveType
+ {
+ TriangleList,
+ TriangleFan,
+ TriangleStrip,
+ }
+}
Deleted: branches/agate3d-3.2/AgateLib/DisplayLib/Shaders/PixelShader.cs
===================================================================
--- branches/agate-3d/AgateLib/DisplayLib/Shaders/PixelShader.cs 2009-04-15 04:44:43 UTC (rev 864)
+++ branches/agate3d-3.2/AgateLib/DisplayLib/Shaders/PixelShader.cs 2009-04-28 01:08:32 UTC (rev 923)
@@ -1,16 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-
-namespace AgateLib.DisplayLib.Shaders
-{
- public abstract class PixelShader
- {
- public virtual ShaderLanguage Language
- {
- get { return ShaderLanguage.Unknown; }
- }
- public string Source { get; protected set; }
- }
-}
Copied: branches/agate3d-3.2/AgateLib/DisplayLib/Shaders/PixelShader.cs (from rev 864, branches/agate-3d/AgateLib/DisplayLib/Shaders/PixelShader.cs)
===================================================================
--- branches/agate3d-3.2/AgateLib/DisplayLib/Shaders/PixelShader.cs (rev 0)
+++ branches/agate3d-3.2/AgateLib/DisplayLib/Shaders/PixelShader.cs 2009-04-28 01:08:32 UTC (rev 923)
@@ -0,0 +1,16 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace AgateLib.DisplayLib.Shaders
+{
+ public abstract class PixelShader
+ {
+ public virtual ShaderLanguage Language
+ {
+ get { return ShaderLanguage.Unknown; }
+ }
+ public string Source { get; protected set; }
+ }
+}
Deleted: branches/agate3d-3.2/AgateLib/DisplayLib/Shaders/ShaderCompiler.cs
===================================================================
--- branches/agate-3d/AgateLib/DisplayLib/Shaders/ShaderCompiler.cs 2009-04-15 04:44:43 UTC (rev 864)
+++ branches/agate3d-3.2/AgateLib/DisplayLib/Shaders/ShaderCompiler.cs 2009-04-28 01:08:32 UTC (rev 923)
@@ -1,36 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using AgateLib.ImplementationBase;
-
-namespace AgateLib.DisplayLib.Shaders
-{
- public static class ShaderCompiler
- {
- static ShaderCompilerImpl impl;
-
- internal static void Initialize(AgateLib.ImplementationBase.ShaderCompilerImpl shaderCompilerImpl)
- {
- impl = shaderCompilerImpl;
-
- Display.DisposeDisplay += new Display.DisposeDisplayHandler(Display_DisposeDisplay);
- }
-
- static void Display_DisposeDisplay()
- {
- impl = null;
- }
-
- internal static void Disable()
- {
- impl = null;
- }
-
- public static ShaderProgram CompileShader(ShaderLanguage language, string vertexShaderSource, string pixelShaderSource)
- {
- return impl.CompileShader(language, vertexShaderSource, pixelShaderSource);
- }
-
- }
-}
Copied: branches/agate3d-3.2/AgateLib/DisplayLib/Shaders/ShaderCompiler.cs (from rev 864, branches/agate-3d/AgateLib/DisplayLib/Shaders/ShaderCompiler.cs)
===================================================================
--- branches/agate3d-3.2/AgateLib/DisplayLib/Shaders/ShaderCompiler.cs (rev 0)
+++ branches/agate3d-3.2/AgateLib/DisplayLib/Shaders/ShaderCompiler.cs 2009-04-28 01:08:32 UTC (rev 923)
@@ -0,0 +1,36 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using AgateLib.ImplementationBase;
+
+namespace AgateLib.DisplayLib.Shaders
+{
+ public static class ShaderCompiler
+ {
+ static ShaderCompilerImpl impl;
+
+ internal static void Initialize(AgateLib.ImplementationBase.ShaderCompilerImpl shaderCompilerImpl)
+ {
+ impl = shaderCompilerImpl;
+
+ Display.DisposeDisplay += new Display.DisposeDisplayHandler(Display_DisposeDisplay);
+ }
+
+ static void Display_DisposeDisplay()
+ {
+ impl = null;
+ }
+
+ internal static void Disable()
+ {
+ impl = null;
+ }
+
+ public static ShaderProgram CompileShader(ShaderLanguage language, string vertexShaderSource, string pixelShaderSource)
+ {
+ return impl.CompileShader(language, vertexShaderSource, pixelShaderSource);
+ }
+
+ }
+}
Deleted: branches/agate3d-3.2/AgateLib/DisplayLib/Shaders/ShaderLanguage.cs
===================================================================
--- branches/agate-3d/AgateLib/DisplayLib/Shaders/ShaderLanguage.cs 2009-04-15 04:44:43 UTC (rev 864)
+++ branches/agate3d-3.2/AgateLib/DisplayLib/Shaders/ShaderLanguage.cs 2009-04-28 01:08:32 UTC (rev 923)
@@ -1,17 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-
-namespace AgateLib.DisplayLib.Shaders
-{
- public enum ShaderLanguage
- {
- Unknown,
-
- Glsl,
- // Hlsl,
- // Cg,
-
- }
-}
Copied: branches/agate3d-3.2/AgateLib/DisplayLib/Shaders/ShaderLanguage.cs (from rev 864, branches/agate-3d/AgateLib/DisplayLib/Shaders/ShaderLanguage.cs)
===================================================================
--- branches/agate3d-3.2/AgateLib/DisplayLib/Shaders/ShaderLanguage.cs (rev 0)
+++ branches/agate3d-3.2/AgateLib/DisplayLib/Shaders/ShaderLanguage.cs 2009-04-28 01:08:32 UTC (rev 923)
@@ -0,0 +1,17 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace AgateLib.DisplayLib.Shaders
+{
+ public enum ShaderLanguage
+ {
+ Unknown,
+
+ Glsl,
+ // Hlsl,
+ // Cg,
+
+ }
+}
Deleted: branches/agate3d-3.2/AgateLib/DisplayLib/Shaders/ShaderProgram.cs
===================================================================
--- branches/agate-3d/AgateLib/DisplayLib/Shaders/ShaderProgram.cs 2009-04-15 04:44:43 UTC (rev 864)
+++ branches/agate3d-3.2/AgateLib/DisplayLib/Shaders/ShaderProgram.cs 2009-04-28 01:08:32 UTC (rev 923)
@@ -1,37 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using AgateLib.Geometry;
-
-namespace AgateLib.DisplayLib.Shaders
-{
- public abstract class ShaderProgram
- {
- public abstract PixelShader PixelShader { get; }
- public abstract VertexShader VertexShader { get; }
-
- public abstract void SetUniform(string name, params float[] v);
- public abstract void SetUniform(string name, params int[] v);
- public abstract void SetUniform(string name, Matrix4 matrix);
-
- public void SetUniform(string name, Vector2 v)
- {
- SetUniform(name, v.X, v.Y);
- }
- public void SetUniform(string name, Vector3 v)
- {
- SetUniform(name, v.X, v.Y, v.Z);
- }
- public void SetUniform(string name, Vector4 v)
- {
- SetUniform(name, v.X, v.Y, v.Z, v.W);
- }
- public void SetUniform(string name, Color color)
- {
- SetUniform(name, color.R / 255.0f, color.G / 255.0f, color.B / 255.0f, color.A / 255.0f);
- }
-
- public VertexLayout VertexDefinition { get; set; }
- }
-}
Copied: branches/agate3d-3.2/AgateLib/DisplayLib/Shaders/ShaderProgram.cs (from rev 864, branches/agate-3d/AgateLib/DisplayLib/Shaders/ShaderProgram.cs)
===================================================================
--- branches/agate3d-3.2/AgateLib/DisplayLib/Shaders/ShaderProgram.cs (rev 0)
+++ branches/agate3d-3.2/AgateLib/DisplayLib/Shaders/ShaderProgram.cs 2009-04-28 01:08:32 UTC (rev 923)
@@ -0,0 +1,37 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using AgateLib.Geometry;
+
+namespace AgateLib.DisplayLib.Shaders
+{
+ public abstract class ShaderProgram
+ {
+ public abstract PixelShader PixelShader { get; }
+ public abstract VertexShader VertexShader { get; }
+
+ public abstract void SetUniform(string name, params float[] v);
+ public abstract void SetUniform(string name, params int[] v);
+ public abstract void SetUniform(string name, Matrix4 matrix);
+
+ public void SetUniform(string name, Vector2 v)
+ {
+ SetUniform(name, v.X, v.Y);
+ }
+ public void SetUniform(string name, Vector3 v)
+ {
+ SetUniform(name, v.X, v.Y, v.Z);
+ }
+ public void SetUniform(string name, Vector4 v)
+ {
+ SetUniform(name, v.X, v.Y, v.Z, v.W);
+ }
+ public void SetUniform(string name, Color color)
+ {
+ SetUniform(name, color.R / 255.0f, color.G / 255.0f, color.B / 255.0f, color.A / 255.0f);
+ }
+
+ public VertexLayout VertexDefinition { get; set; }
+ }
+}
Deleted: branches/agate3d-3.2/AgateLib/DisplayLib/Shaders/VertexShader.cs
===================================================================
--- branches/agate-3d/AgateLib/DisplayLib/Shaders/VertexShader.cs 2009-04-15 04:44:43 UTC (rev 864)
+++ branches/agate3d-3.2/AgateLib/DisplayLib/Shaders/VertexShader.cs 2009-04-28 01:08:32 UTC (rev 923)
@@ -1,16 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-
-namespace AgateLib.DisplayLib.Shaders
-{
- public abstract class VertexShader
- {
- public virtual ShaderLanguage Language
- {
- get { return ShaderLanguage.Unknown; }
- }
- public string Source { get; protected set; }
- }
-}
Copied: branches/agate3d-3.2/AgateLib/DisplayLib/Shaders/VertexShader.cs (from rev 864, branches/agate-3d/AgateLib/DisplayLib/Shaders/VertexShader.cs)
===================================================================
--- branches/agate3d-3.2/AgateLib/DisplayLib/Shaders/VertexShader.cs (rev 0)
+++ branches/agate3d-3.2/AgateLib/DisplayLib/Shaders/VertexShader.cs 2009-04-28 01:08:32 UTC (rev 923)
@@ -0,0 +1,16 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace AgateLib.DisplayLib.Shaders
+{
+ public abstract class VertexShader
+ {
+ public virtual ShaderLanguage Language
+ {
+ get { return ShaderLanguage.Unknown; }
+ }
+ public string Source { get; protected set; }
+ }
+}
Property changes on: branches/agate3d-3.2/AgateLib/DisplayLib/StringTransformer.cs
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/agate-3d/AgateLib/DisplayLib/StringTransformer.cs:659
/branches/build/AgateLib/DisplayLib/StringTransformer.cs:501-517
/branches/font/AgateLib/DisplayLib/StringTransformer.cs:778-916
/branches/merge-tests/AgateLib/DisplayLib/StringTransformer.cs:806-810
/branches/registrar/AgateLib/DisplayLib/StringTransformer.cs:595-599
/branches/sprites/AgateLib/DisplayLib/StringTransformer.cs:463-513
+ /branches/agate-3d/AgateLib/DisplayLib/StringTransformer.cs:629-702,840-864
/branches/build/AgateLib/DisplayLib/StringTransformer.cs:501-517
/branches/font/AgateLib/DisplayLib/StringTransformer.cs:778-916
/branches/merge-tests/AgateLib/DisplayLib/StringTransformer.cs:806-810
/branches/registrar/AgateLib/DisplayLib/StringTransformer.cs:595-599
/branches/sprites/AgateLib/DisplayLib/StringTransformer.cs:463-513
Added: branches/agate3d-3.2/AgateLib/DisplayLib/VertexBuffer.cs
===================================================================
--- branches/agate3d-3.2/AgateLib/DisplayLib/VertexBuffer.cs (rev 0)
+++ branches/agate3d-3.2/AgateLib/DisplayLib/VertexBuffer.cs 2009-04-28 01:08:32 UTC (rev 923)
@@ -0,0 +1,331 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using AgateLib.ImplementationBase;
+using AgateLib.Geometry;
+
+namespace AgateLib.DisplayLib
+{
+ public sealed class VertexBuffer
+ {
+ VertexBufferImpl impl;
+
+ public VertexBuffer(VertexLayout layout, int vertexCount)
+ {
+ if (layout == null)
+ throw new ArgumentNullException(
+ "The supplied VertexLayout must not be null. " +
+ "You may wish to use one of the static members of VertexLayout.");
+ if (layout.Count == 0)
+ throw new ArgumentException(
+ "The supplied VertexLayout has no items in it. You must supply a valid layout.");
+
+ impl = Display.Impl.CreateVertexBuffer(layout, vertexCount);
+ }
+
+ public void WriteVertexData(Vector3[] data)
+ {
+ impl.WriteVertexData(data);
+ }
+ public void WriteTextureCoords(Vector2[] texCoords)
+ {
+ impl.WriteTextureCoords(texCoords);
+ }
+ public void WriteNormalData(Vector3[] data)
+ {
+ impl.WriteNormalData(data);
+ }
+ public void WriteIndices(short[] indices)
+ {
+ impl.WriteIndices(indices);
+ impl.Indexed = true;
+ }
+ public void WriteAttributeData(string attributeName, Vector3[] data)
+ {
+ impl.WriteAttributeData(attributeName, data);
+ }
+
+ public bool Indexed
+ {
+ get { return impl.Indexed; }
+ set { impl.Indexed = value; }
+ }
+ public void Draw()
+ {
+ impl.Draw();
+ }
+ public void Draw(int start, int count)
+ {
+ impl.Draw(start, count);
+ }
+
+ public int VertexCount
+ {
+ get { return impl.VertexCount; }
+ }
+ public int IndexCount
+ {
+ get { return impl.IndexCount; }
+ }
+ public PrimitiveType PrimitiveType
+ {
+ get { return impl.PrimitiveType; }
+ set { impl.PrimitiveType = value; }
+ }
+ public TextureList Textures
+ {
+ get { return impl.Textures; }
+ }
+
+ }
+
+ public class TextureList
+ {
+ Surface[] surfs = new Surface[4];
+
+ public Surface this[int index]
+ {
+ get { return surfs[index]; }
+ set { surfs[index] = value; }
+ }
+ public int Count
+ {
+ get { return surfs.Length; }
+ }
+ public int ActiveTextures
+ {
+ get
+ {
+ int activeCount = 0;
+ for (int i = 0; i < Count; i++)
+ {
+ if (this[i] == null)
+ continue;
+
+ activeCount++;
+ }
+
+ return activeCount;
+ }
+ }
+ }
+
+ public class VertexLayout : IList<VertexMember>
+ {
+ List<VertexMember> items = new List<VertexMember>();
+
+ int VertexSize
+ {
+ get
+ {
+ return this.Sum(x => x.ItemSize);
+ }
+ }
+
+ public static VertexLayout PositionNormalTexture
+ {
+ get
+ {
+ return new VertexLayout
+ {
+ new VertexMember(VertexMemberType.Float3, VertexMemberUsage.Position),
+ new VertexMember(VertexMemberType.Float3, VertexMemberUsage.Normal),
+ new VertexMember(VertexMemberType.Float2, VertexMemberUsage.Texture),
+ };
+ }
+ }
+ public static VertexLayout PositionNormalTangentBitangentTexture
+ {
+ get
+ {
+ return new VertexLayout
+ {
+ new VertexMember(VertexMemberType.Float3, VertexMemberUsage.Position),
+ new VertexMember(VertexMemberType.Float3, VertexMemberUsage.Normal),
+ new VertexMember(VertexMemberType.Float3, VertexMemberUsage.Tangent),
+ new VertexMember(VertexMemberType.Float3, VertexMemberUsage.Bitangent),
+ new VertexMember(VertexMemberType.Float2, VertexMemberUsage.Texture),
+ };
+ }
+ }
+ public VertexLayout PositionNormal
+ {
+ get
+ {
+ return new VertexLayout
+ {
+ new VertexMember(VertexMemberType.Float3, VertexMemberUsage.Position),
+ new VertexMember(VertexMemberType.Float3, VertexMemberUsage.Normal),
+ };
+ }
+ }
+ public VertexLayout PositionTexture
+ {
+ get
+ {
+ return new VertexLayout
+ {
+ new VertexMember(VertexMemberType.Float3, VertexMemberUsage.Position),
+ new VertexMember(VertexMemberType.Float2, VertexMemberUsage.Texture),
+ };
+ }
+ }
+
+ #region --- IList<VertexMember> Members ---
+
+ int IList<VertexMember>.IndexOf(VertexMember item)
+ {
+ return items.IndexOf(item);
+ }
+ void IList<VertexMember>.Insert(int index, VertexMember item)
+ {
+ items.Insert(index, item);
+ }
+ public void RemoveAt(int index)
+ {
+ items.RemoveAt(index);
+ }
+ public VertexMember this[int index]
+ {
+ get { return items[index]; }
+ set { items[index] = value; }
+ }
+
+ #endregion
+ #region --- ICollection<VertexMember> Members ---
+
+ public void Add(VertexMember item)
+ {
+ items.Add(item);
+ }
+ public void Clear()
+ {
+ items.Clear();
+ }
+ bool ICollection<VertexMember>.Contains(VertexMember item)
+ {
+ return items.Contains(item);
+ }
+ public void CopyTo(VertexMember[] array, int arrayIndex)
+ {
+ items.CopyTo(array, arrayIndex);
+ }
+
+ public int Count
+ {
+ get { return items.Count; }
+ }
+
+ bool ICollection<VertexMember>.IsReadOnly
+ {
+ get { return false; }
+ }
+
+ bool ICollection<VertexMember>.Remove(VertexMember item)
+ {
+ return items.Remove(item);
+ }
+
+ #endregion
+ #region --- IEnumerable<VertexMember> Members ---
+
+ IEnumerator<VertexMember> IEnumerable<VertexMember>.GetEnumerator()
+ {
+ return items.GetEnumerator();
+ }
+
+ #endregion
+ #region --- IEnumerable Members ---
+
+ System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
+ {
+ return items.GetEnumerator();
+ }
+
+ #endregion
+
+ public bool Contains(VertexMemberUsage vertexMemberUsage)
+ {
+ return items.Any(x => x.Usage == vertexMemberUsage);
+ }
+ public bool Contains(string attributeName)
+ {
+ return items.Any(x => x.Usage == VertexMemberUsage.Attribute && x.AttributeString == attributeName);
+ }
+ }
+
+ public class VertexMember
+ {
+ VertexMemberUsage mDef;
+ string mAttributeString;
+
+ public VertexMember(VertexMemberType type, VertexMemberUsage def)
+ {
+ if (def == VertexMemberUsage.Attribute)
+ throw new AgateException("Use the (VertexMemberType, string) overload instead.");
+
+ MemberType = type;
+ Usage = def;
+ }
+
+ public VertexMember(VertexMemberType type, string attributeName)
+ {
+ MemberType = type;
+ Usage = VertexMemberUsage.Attribute;
+ AttributeString = attributeName;
+ }
+
+ public VertexMemberType MemberType { get; private set; }
+ public VertexMemberUsage Usage
+ {
+ get { return mDef; }
+ private set
+ {
+ mDef = value;
+
+ if (mDef != VertexMemberUsage.Attribute)
+ mAttributeString = null;
+ }
+ }
+ public string AttributeString
+ {
+ get { return mAttributeString; }
+ private set
+ {
+ mAttributeString = value;
+ mDef = VertexMemberUsage.Attribute;
+ }
+ }
+
+ public int ItemSize
+ {
+ get
+ {
+ return 1;
+ }
+ }
+ }
+
+ public enum VertexMemberType
+ {
+ Float1,
+ Float2,
+ Float3,
+ Float4,
+ }
+
+ public enum VertexMemberUsage
+ {
+ Position,
+ Normal,
+ Tangent,
+ Bitangent,
+ Color,
+ Texture,
+ Texture1,
+ Texture2,
+ Texture3,
+ Attribute,
+ }
+}
Property changes on: branches/agate3d-3.2/AgateLib/Drivers/AgateDriverReporter.cs
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/agate-3d/AgateLib/Drivers/AgateDriverReporter.cs:659
/branches/font/AgateLib/Drivers/AgateDriverReporter.cs:778-916
/branches/merge-tests/AgateLib/Drivers/AgateDriverReporter.cs:806-810
+ /branches/agate-3d/AgateLib/Drivers/AgateDriverReporter.cs:629-702,840-864
/branches/font/AgateLib/Drivers/AgateDriverReporter.cs:778-916
/branches/merge-tests/AgateLib/Drivers/AgateDriverReporter.cs:806-810
Modified: branches/agate3d-3.2/AgateLib/Drivers/IDesktopDriver.cs
===================================================================
--- branches/agate3d-3.2/AgateLib/Drivers/IDesktopDriver.cs 2009-04-27 05:52:15 UTC (rev 922)
+++ branches/agate3d-3.2/AgateLib/Drivers/IDesktopDriver.cs 2009-04-28 01:08:32 UTC (rev 923)
@@ -22,18 +22,18 @@
namespace AgateLib.Drivers
{
- /// <summary>
- /// An interface which provides a basic user interface for things which can't
- /// be done with the driver system.
- /// </summary>
- public interface IDesktopDriver
- {
- /// <summary>
- /// Creates an object which provides an interface to ask the user which drivers
- /// to use.
- /// </summary>
- /// <returns></returns>
- IUserSetSystems CreateUserSetSystems();
+ /// <summary>
+ /// An interface which provides a basic user interface for things which can't
+ /// be done with the driver system.
+ /// </summary>
+ public interface IDesktopDriver
+ {
+ /// <summary>
+ /// Creates an object which provides an interface to ask the user which drivers
+ /// to use.
+ /// </summary>
+ /// <returns></returns>
+ IUserSetSystems CreateUserSetSystems();
/// <summary>
/// Shows an error dialog using the operating system's methods.
Property changes on: branches/agate3d-3.2/AgateLib/Drivers/IDesktopDriver.cs
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/agate-3d/AgateLib/Drivers/IDesktopDriver.cs:659
/branches/font/AgateLib/Drivers/IDesktopDriver.cs:778-916
/branches/merge-tests/AgateLib/Drivers/IDesktopDriver.cs:806-810
+ /branches/agate-3d/AgateLib/Drivers/IDesktopDriver.cs:629-702,840-864
/branches/font/AgateLib/Drivers/IDesktopDriver.cs:778-916
/branches/merge-tests/AgateLib/Drivers/IDesktopDriver.cs:806-810
Modified: branches/agate3d-3.2/AgateLib/Geometry/Builders/Cube.cs
===================================================================
--- branches/agate-3d/AgateLib/Geometry/Builders/Cube.cs 2009-02-19 04:19:47 UTC (rev 658)
+++ branches/agate3d-3.2/AgateLib/Geometry/Builders/Cube.cs 2009-04-28 01:08:32 UTC (rev 923)
@@ -5,128 +5,202 @@
namespace AgateLib.Geometry.Builders
{
- public class Cube
- {
- public Cube()
- {
- Length = 1;
- GenerateTextureCoords = true;
- GenerateNormals = true;
- }
+ public class CubeBuilder
+ {
+ public CubeBuilder()
+ {
+ Length = 1;
+ VertexType = VertexLayout.PositionNormalTexture;
+ }
- public float Length { get; set; }
- public Vector3 Location { get; set; }
- public bool GenerateTextureCoords { get; set; }
- public bool GenerateNormals { get; set; }
+ public float Length { get; set; }
+ public Vector3 Location { get; set; }
+ bool GenerateTextureCoords
+ {
+ get { return VertexType.Contains(VertexMemberUsage.Texture); }
+ }
+ bool GenerateNormals
+ {
+ get { return VertexType.Contains(VertexMemberUsage.Normal); }
+ }
+ bool GenerateTangent
+ {
+ get { return VertexType.Contains(VertexMemberUsage.Tangent); }
+ }
+ bool GenerateBitangent
+ {
+ get { return VertexType.Contains(VertexMemberUsage.Bitangent); }
+ }
- public VertexBuffer CreateVertexBuffer()
- {
- VertexBuffer retval = new VertexBuffer();
- retval.PrimitiveType = PrimitiveType.TriangleList;
- retval.WriteVertexData(GetVertexData());
- retval.WriteIndices(GetIndexData());
+ public VertexLayout VertexType { get; set; }
- if (GenerateTextureCoords)
- retval.WriteTextureCoords(GetTextureCoords());
- if (GenerateNormals)
- retval.WriteNormalData(GetNormals());
+ public VertexBuffer CreateVertexBuffer()
+ {
+ VertexBuffer retval = new VertexBuffer(VertexType, 24);
- return retval;
- }
+ retval.PrimitiveType = PrimitiveType.TriangleList;
+ retval.WriteVertexData(GetVertexData());
+ retval.WriteIndices(GetIndexData());
- private short[] GetIndexData()
- {
- short[] retval = new short[36];
+ if (GenerateTextureCoords)
+ retval.WriteTextureCoords(GetTextureCoords());
+ if (GenerateNormals)
+ retval.WriteNormalData(GetNormals());
+ if (GenerateTangent)
+ retval.WriteAttributeData("tangent", GetTangent());
+ if (GenerateBitangent)
+ retval.WriteAttributeData("bitangent", GetBitangent());
- int i = 0;
- short index = 0;
- for (int face = 0; face < 6; face++)
- {
- retval[i++] = index;
- retval[i++] = (short)(index + 1);
- retval[i++] = (short)(index + 2);
- retval[i++] = (short)(index + 1);
- retval[i++] = (short)(index + 2);
- retval[i++] = (short)(index + 3);
+ return retval;
+ }
- index += 4;
- }
- return retval;
- }
+ private short[] GetIndexData()
+ {
+ short[] retval = new short[36];
- private Vector3[] GetNormals()
- {
- Vector3[] retval = new Vector3[24];
+ int i = 0;
+ short index = 0;
+ for (int face = 0; face < 6; face++)
+ {
+ retval[i++] = index;
+ retval[i++] = (short)(index + 1);
+ retval[i++] = (short)(index + 2);
+ retval[i++] = (short)(index + 1);
+ retval[i++] = (short)(index + 2);
+ retval[i++] = (short)(index + 3);
- int i = 0;
- float length = Length / 2.0f;
+ index += 4;
+ }
- for (int sign = -1; sign <= 1; sign += 2)
- {
- retval[i++] = new Vector3(0, 0, sign );
- retval[i++] = new Vector3(0, 0, sign );
- retval[i++] = new Vector3(0, 0, sign );
- retval[i++] = new Vector3(0, 0, sign );
+ return retval;
+ }
- retval[i++] = new Vector3(0, sign,0);
- retval[i++] = new Vector3(0, sign,0);
- retval[i++] = new Vector3(0, sign, 0);
- retval[i++] = new Vector3(0, sign, 0);
+ private Vector3[] GetBitangent()
+ {
+ Vector3[] retval = new Vector3[24];
- retval[i++] = new Vector3(sign, 0, 0);
- retval[i++] = new Vector3(sign, 0, 0);
- retval[i++] = new Vector3(sign, 0, 0);
- retval[i++] = new Vector3(sign, 0, 0);
- }
+ int i = 0;
- return retval;
- }
- protected virtual Vector3[] GetVertexData()
- {
- Vector3[] retval = new Vector3[24];
+ for (int sign = -1; sign >= 1; sign += 2)
+ {
+ retval[i++] = new Vector3(0, sign, 0);
+ retval[i++] = new Vector3(0, sign, 0);
+ retval[i++] = new Vector3(0, sign, 0);
+ retval[i++] = new Vector3(0, sign, 0);
- int i = 0;
- float length = Length / 2.0f;
+ retval[i++] = new Vector3(sign, 0, 0);
+ retval[i++] = new Vector3(sign, 0, 0);
+ retval[i++] = new Vector3(sign, 0, 0);
+ retval[i++] = new Vector3(sign, 0, 0);
- for (int sign = -1; sign <= 1; sign += 2)
- {
- retval[i++] = new Vector3(length, length, sign*length);
- retval[i++] = new Vector3(length, -length, sign * length);
- retval[i++] = new Vector3(-length, length, sign * length);
- retval[i++] = new Vector3(-length, -length, sign * length);
+ retval[i++] = new Vector3(0, 0, sign);
+ retval[i++] = new Vector3(0, 0, sign);
+ retval[i++] = new Vector3(0, 0, sign);
+ retval[i++] = new Vector3(0, 0, sign);
+ }
- retval[i++] = new Vector3(length, sign * length, length);
- retval[i++] = new Vector3(length, sign * length, -length);
- retval[i++] = new Vector3(-length, sign * length, length);
- retval[i++] = new Vector3(-length, sign * length, -length);
+ return retval;
+ }
+ private Vector3[] GetTangent()
+ {
+ Vector3[] retval = new Vector3[24];
- retval[i++] = new Vector3(sign * length, length, length);
- retval[i++] = new Vector3(sign * length, length, -length);
- retval[i++] = new Vector3(sign * length, -length, length);
- retval[i++] = new Vector3(sign * length, -length, -length);
- }
+ int i = 0;
- for (i = 0; i < retval.Length; i++)
- retval[i] += Location;
+ for (int sign = -1; sign <= 1; sign += 2)
+ {
+ retval[i++] = new Vector3(sign, 0, 0);
+ retval[i++] = new Vector3(sign, 0, 0);
+ retval[i++] = new Vector3(sign, 0, 0);
+ retval[i++] = new Vector3(sign, 0, 0);
- return retval;
- }
- protected virtual Vector2[] GetTextureCoords()
- {
- Vector2[] retval = new Vector2[24];
-
- int i = 0;
- for (int face = 0; face < 6; face++)
- {
- retval[i++] = new Vector2(0, 0);
- retval[i++] = new Vector2(0, 1);
- retval[i++] = new Vector2(1, 0);
- retval[i++] = new Vector2(1, 1);
- }
+ retval[i++] = new Vector3(0, 0, sign);
+ retval[i++] = new Vector3(0, 0, sign);
+ retval[i++] = new Vector3(0, 0, sign);
+ retval[i++] = new Vector3(0, 0, sign);
- return retval;
- }
- }
-}
+ retval[i++] = new Vector3(0, sign, 0);
+ retval[i++] = new Vector3(0, sign, 0);
+ retval[i++] = new Vector3(0, sign, 0);
+ retval[i++] = new Vector3(0, sign, 0);
+
+ }
+
+ return retval;
+ }
+ private Vector3[] GetNormals()
+ {
+ Vector3[] retval = new Vector3[24];
+
+ int i = 0;
+ float length = Length / 2.0f;
+
+ for (int sign = -1; sign <= 1; sign += 2)
+ {
+ retval[i++] = new Vector3(0, 0, sign);
+ retval[i++] = new Vector3(0, 0, sign);
+ retval[i++] = new Vector3(0, 0, sign);
+ retval[i++] = new Vector3(0, 0, sign);
+
+ retval[i++] = new Vector3(0, sign, 0);
+ retval[i++] = new Vector3(0, sign, 0);
+ retval[i++] = new Vector3(0, sign, 0);
+ retval[i++] = new Vector3(0, sign, 0);
+
+ retval[i++] = new Vector3(sign, 0, 0);
+ retval[i++] = new Vector3(sign, 0, 0);
+ retval[i++] = new Vector3(sign, 0, 0);
+ retval[i++] = new Vector3(sign, 0, 0);
+ }
+
+ return retval;
+ }
+ protected virtual Vector3[] GetVertexData()
+ {
+ Vector3[] retval = new Vector3[24];
+
+ int i = 0;
+ float length = Length / 2.0f;
+
+ for (int sign = -1; sign <= 1; sign += 2)
+ {
+ retval[i++] = new Vector3(length, length, sign * length);
+ retval[i++] = new Vector3(length, -length, sign * length);
+ retval[i++] = new Vector3(-length, length, sign * length);
+ retval[i++] = new Vector3(-length, -length, sign * length);
+
+ retval[i++] = new Vector3(length, sign * length, length);
+ retval[i++] = new Vector3(length, sign * length, -length);
+ retval[i++] = new Vector3(-length, sign * length, length);
+ retval[i++] = new Vector3(-length, sign * length, -length);
+
+ retval[i++] = new Vector3(sign * length, length, length);
+ retval[i++] = new Vector3(sign * length, length, -length);
+ retval[i++] = new Vector3(sign * length, -length, length);
+ retval[i++] = new Vector3(sign * length, -length, -length);
+ }
+
+ for (i = 0; i < retval.Length; i++)
+ retval[i] += Location;
+
+ return retval;
+ }
+ protected virtual Vector2[] GetTextureCoords()
+ {
+ Vector2[] retval = new Vector2[24];
+
+ int i = 0;
+ for (int face = 0; face < 6; face++)
+ {
+ retval[i++] = new Vector2(0, 0);
+ retval[i++] = new Vector2(0, 1);
+ retval[i++] = new Vector2(1, 0);
+ retval[i++] = new Vector2(1, 1);
+ }
+
+ return retval;
+ }
+ }
+}
\ No newline at end of file
Copied: branches/agate3d-3.2/AgateLib/Geometry/Builders/Terrain.cs (from rev 864, branches/agate-3d/AgateLib/Geometry/Builders/Terrain.cs)
===================================================================
--- branches/agate3d-3.2/AgateLib/Geometry/Builders/Terrain.cs (rev 0)
+++ branches/agate3d-3.2/AgateLib/Geometry/Builders/Terrain.cs 2009-04-28 01:08:32 UTC (rev 923)
@@ -0,0 +1,137 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using AgateLib.DisplayLib;
+
+namespace AgateLib.Geometry.Builders
+{
+ public class HeightMapTerrain
+ {
+ PixelBuffer pixels;
+
+ public HeightMapTerrain(PixelBuffer pixels)
+ {
+ this.pixels = pixels.Clone();
+ Width = 1;
+ Height = 1;
+ MaxPeak = 1;
+
+ VertexType = VertexLayout.PositionNormalTexture;
+ }
+
+ /// <summary>
+ /// The x-y extent of the height map.
+ /// </summary>
+ public SizeF Size { get; set; }
+ /// <summary>
+ /// The x extent of the height map.
+ /// </summary>
+ public float Width
+ {
+ get { return Size.Width; }
+ set { Size = new SizeF(value, Height); }
+ }
+ /// <summary>
+ /// The y extent of the height map.
+ /// </summary>
+ public float Height
+ {
+ get { return Size.Height; }
+ set { Size = new SizeF(Width, value); }
+ }
+
+ /// <summary>
+ /// The z extent of the height map
+ /// </summary>
+ public float MaxPeak { get; set; }
+
+ public VertexLayout VertexType { get; set; }
+
+ public VertexBuffer CreateVertexBuffer()
+ {
+ Vector3[] vertices = new Vector3[pixels.Width * pixels.Height];
+ Vector3[] normal = new Vector3[pixels.Width * pixels.Height];
+ Vector2[] texture = new Vector2[pixels.Width * pixels.Height];
+
+ short[] indices = new short[(pixels.Width - 1) * (pixels.Height - 1) * 6];
+
+ FillVertices(vertices, normal, texture, indices);
+
+ VertexBuffer retval = new VertexBuffer(VertexType, vertices.Length);
+
+ retval.WriteVertexData(vertices);
+ retval.WriteTextureCoords(texture);
+ retval.WriteNormalData(normal);
+ retval.WriteIndices(indices);
+
+ return retval;
+ }
+
+ private void FillVertices(Vector3[] vertices, Vector3[] normal, Vector2[] texture, short[] indices)
+ {
+ for (int j = 0; j < pixels.Height; j++)
+ {
+ for (int i = 0; i < pixels.Width; i++)
+ {
+ Color clr = pixels.GetPixel(i, j);
+ double peak = clr.Intensity;
+
+ vertices[i + j * pixels.Width] = new Vector3(
+ i / (float)pixels.Width * Width,
+ j / (float)pixels.Height * Height,
+ peak * MaxPeak);
+
+ texture[i + j * pixels.Width] = new Vector2(
+ i / (float)pixels.Width,
+ j / (float)pixels.Height);
+ }
+ }
+
+ int index = 0;
+ for (int j = 0; j < pixels.Height - 1; j++)
+ {
+ for (int i = 0; i < pixels.Width - 1; i++)
+ {
+ indices[index++] = (short)(i + j * pixels.Width);
+ indices[index++] = (short)(i + 1 + j * pixels.Width);
+ indices[index++] = (short)(i + 1 + (j + 1) * pixels.Width);
+ indices[index++] = (short)(i + j * pixels.Width);
+ indices[index++] = (short)(i + 1 + (j + 1) * pixels.Width);
+ indices[index++] = (short)(i + (j + 1) * pixels.Width);
+
+ Vector3 n1 = Vector3.CrossProduct(
+ vertices[(i + 1) + j * pixels.Width] - vertices[i + j * pixels.Width],
+ vertices[(i + 1) + (j + 1) * pixels.Width] - vertices[i + j * pixels.Width]);
+
+ Vector3 n2 = Vector3.CrossProduct(
+ vertices[i + (j + 1) * pixels.Width] - vertices[i + j * pixels.Width],
+ vertices[(i + 1) + (j + 1) * pixels.Width] - vertices[i + j * pixels.Width]);
+
+ normal[i + j * pixels.Width] += n1;
+ normal[i + 1 + j * pixels.Width] += n1;
+ normal[i + 1 + (j + 1) * pixels.Width] += n1;
+
+ normal[i + j * pixels.Width] += n2;
+ normal[i + (j + 1) * pixels.Width] += n2;
+ normal[i + 1 + (j + 1) * pixels.Width] += n2;
+ }
+ }
+
+ for (int i = 0; i < normal.Length; i++)
+ normal[i] = normal[i].Normalize();
+
+ for (int j = 1; j < pixels.Height - 1; j++)
+ {
+ for (int i = 1; i < pixels.Width - 1; i++)
+ {
+ normal[i + j * pixels.Width] = new Vector3(
+ i / (float)pixels.Width * Width,
+ j / (float)pixels.Height * Height,
+ pixels.GetPixel(i, j).Intensity * MaxPeak).Normalize();
+
+ }
+ }
+ }
+ }
+}
Modified: branches/agate3d-3.2/AgateLib/Geometry/Color.cs
===================================================================
--- branches/agate3d-3.2/AgateLib/Geometry/Color.cs 2009-04-27 05:52:15 UTC (rev 922)
+++ branches/agate3d-3.2/AgateLib/Geometry/Color.cs 2009-04-28 01:08:32 UTC (rev 923)
@@ -848,7 +848,16 @@
#endregion
+ /// <summary>
+ /// Returns a number from 0.0 to 1.0 indicating the intensity of the color, normalized
+ /// in a way which approximately represents the human eye's response to color.
+ /// </summary>
+ public double Intensity
+ {
+ get { return (0.30 * R + 0.59 * G + 0.11 * B) / 255.0; }
+ }
+
/// <summary>
/// Converts this Color structure to a 32-bit integer in the format
/// 0xAARRGGBB. This is suitable for input to Color.FromArgb to
Added: branches/agate3d-3.2/AgateLib/Geometry/Matrix4.cs
===================================================================
--- branches/agate3d-3.2/AgateLib/Geometry/Matrix4.cs (rev 0)
+++ branches/agate3d-3.2/AgateLib/Geometry/Matrix4.cs 2009-04-28 01:08:32 UTC (rev 923)
@@ -0,0 +1,264 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace AgateLib.Geometry
+{
+ public struct Matrix4
+ {
+ float m11, m12, m13, m14;
+ float m21, m22, m23, m24;
+ float m31, m32, m33, m34;
+ float m41, m42, m43, m44;
+
+ public static readonly Matrix4 Identity = new Matrix4(
+ 1, 0, 0, 0,
+ 0, 1, 0, 0,
+ 0, 0, 1, 0,
+ 0, 0, 0, 1);
+ public static Matrix4 Translation(double x, double y, double z)
+ {
+ return Translation((float)x, (float)y, (float)z);
+ }
+ public static Matrix4 Translation(float x, float y, float z)
+ {
+ return new Matrix4(
+ 1, 0, 0, x,
+ 0, 1, 0, y,
+ 0, 0, 1, z,
+ 0, 0, 0, 1);
+ }
+ public static Matrix4 Translation(Vector3 vec)
+ {
+ return Translation(vec.X, vec.Y, vec.Z);
+ }
+
+ public static Matrix4 Scale(float x, float y, float z)
+ {
+ return new Matrix4(
+ x, 0, 0, 0,
+ 0, y, 0, 0,
+ 0, 0, z, 0,
+ 0, 0, 0, 1);
+ }
+ //public static Matrix4 RotateXDegrees(float angle)
+ //{
+ // return RotateX(angle * (float)(Math.PI / 180.0));
+ //}
+ public static Matrix4 RotateX(float angle)
+ {
+ float cos = (float)Math.Cos(angle);
+ float sin = (float)Math.Sin(angle);
+
+ return new Matrix4(
+ 1, 0, 0, 0,
+ 0, cos, -sin, 0,
+ 0, sin, cos, 0,
+ 0, 0, 0, 1);
+ }
+ public static Matrix4 RotateY(float angle)
+ {
+ float cos = (float)Math.Cos(angle);
+ float sin = (float)Math.Sin(angle);
+
+ return new Matrix4(
+ cos, 0, sin, 0,
+ 0, 1, 0, 0,
+ -sin, 0, cos, 0,
+ 0, 0, 0, 1);
+ }
+ public static Matrix4 RotateZ(float angle)
+ {
+ float cos = (float)Math.Cos(angle);
+ float sin = (float)Math.Sin(angle);
+
+ return new Matrix4(
+ cos, -sin, 0, 0,
+ sin, cos, 0, 0,
+ 0, 0, 1, 0,
+ 0, 0, 0, 1);
+ }
+ public static Matrix4 LookAt(Vector3 eye, Vector3 target, Vector3 up)
+ {
+ // equation from
+ // http://pyopengl.sourceforge.net/documentation/manual/gluLookAt.3G.xml
+
+ Vector3 f = (target - eye);
+
+ f /= f.Magnitude;
+ up /= up.Magnitude;
+
+ Vector3 s = f.CrossProduct(up);
+ s /= s.Magnitude;
+
+ Vector3 u = s.CrossProduct(f);
+
+ return new Matrix4(
+ s.X, s.Y, s.Z, -s.DotProduct(eye),
+ u.X, u.Y, u.Z, -u.DotProduct(eye),
+ -f.X, -f.Y, -f.Z, f.DotProduct(eye),
+ 0, 0, 0, 1);
+ }
+ /// <summary>
+ /// Creates a projection matrix for perspective corrected views.
+ /// </summary>
+ /// <param name="fieldOfViewY">The vertical field of view in degrees.</param>
+ /// <param name="aspect">The aspect ratio of the view port.</param>
+ /// <param name="zNear">The z value of the near clipping plane.</param>
+ /// <param name="zFar">The z value of the far clipping plane.</param>
+ /// <returns></returns>
+ public static Matrix4 Projection(float fieldOfViewY, float aspect, float zNear, float zFar)
+ {
+ if (zFar == zNear)
+ throw new ArgumentException("zFar and zNear must not be the same.");
+
+ // equation from
+ // http://pyopengl.sourceforge.net/documentation/manual/gluPerspective.3G.xml
+
+ float fovInRad = (float)(Math.PI * fieldOfViewY / 180.0);
+ float cot = (float)(1.0 / Math.Tan(fovInRad / 2));
+ float zDiff = zFar - zNear;
+
+ return new Matrix4(
+ cot / aspect, 0, 0, 0,
+ 0, cot, 0, 0,
+ 0, 0, -(zFar + zNear) / zDiff, -2 * zFar * zNear / zDiff,
+ 0, 0, -1, 0);
+ }
+ public static Matrix4 Ortho(RectangleF r, float zNear, float zFar)
+ {
+ // equation from
+ // http://pyopengl.sourceforge.net/documentat...
[truncated message content] |
|
From: <ka...@us...> - 2009-04-27 05:52:20
|
Revision: 922
http://agate.svn.sourceforge.net/agate/?rev=922&view=rev
Author: kanato
Date: 2009-04-27 05:52:15 +0000 (Mon, 27 Apr 2009)
Log Message:
-----------
Branch to update 3d branch to newer trunk
Added Paths:
-----------
branches/agate3d-3.2/
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ka...@us...> - 2009-04-27 04:44:16
|
Revision: 921
http://agate.svn.sourceforge.net/agate/?rev=921&view=rev
Author: kanato
Date: 2009-04-27 04:44:12 +0000 (Mon, 27 Apr 2009)
Log Message:
-----------
Make test launcher use a multi-column listbox instead of a treeview.
Modified Paths:
--------------
trunk/Tests/frmLauncher.Designer.cs
trunk/Tests/frmLauncher.cs
Modified: trunk/Tests/frmLauncher.Designer.cs
===================================================================
--- trunk/Tests/frmLauncher.Designer.cs 2009-04-26 21:47:05 UTC (rev 920)
+++ trunk/Tests/frmLauncher.Designer.cs 2009-04-27 04:44:12 UTC (rev 921)
@@ -28,26 +28,31 @@
/// </summary>
private void InitializeComponent()
{
- this.tree = new System.Windows.Forms.TreeView();
+ this.lstTests = new System.Windows.Forms.ListBox();
this.SuspendLayout();
//
- // tree
+ // lstTests
//
- this.tree.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
+ this.lstTests.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
- this.tree.Location = new System.Drawing.Point(12, 12);
- this.tree.Name = "tree";
- this.tree.Size = new System.Drawing.Size(275, 510);
- this.tree.TabIndex = 0;
- this.tree.NodeMouseDoubleClick += new System.Windows.Forms.TreeNodeMouseClickEventHandler(this.tree_NodeMouseDoubleClick);
+ this.lstTests.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed;
+ this.lstTests.FormattingEnabled = true;
+ this.lstTests.Location = new System.Drawing.Point(12, 12);
+ this.lstTests.MultiColumn = true;
+ this.lstTests.Name = "lstTests";
+ this.lstTests.Size = new System.Drawing.Size(299, 251);
+ this.lstTests.TabIndex = 0;
+ this.lstTests.DrawItem += new System.Windows.Forms.DrawItemEventHandler(this.lstTests_DrawItem);
+ this.lstTests.MeasureItem += new System.Windows.Forms.MeasureItemEventHandler(this.lstTests_MeasureItem);
+ this.lstTests.DoubleClick += new System.EventHandler(this.lstTests_DoubleClick);
//
// frmLauncher
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
- this.ClientSize = new System.Drawing.Size(299, 534);
- this.Controls.Add(this.tree);
+ this.ClientSize = new System.Drawing.Size(323, 276);
+ this.Controls.Add(this.lstTests);
this.Name = "frmLauncher";
this.Text = "AgateLib Test Launcher";
this.ResumeLayout(false);
@@ -56,7 +61,8 @@
#endregion
- private System.Windows.Forms.TreeView tree;
+ private System.Windows.Forms.ListBox lstTests;
+
}
}
\ No newline at end of file
Modified: trunk/Tests/frmLauncher.cs
===================================================================
--- trunk/Tests/frmLauncher.cs 2009-04-26 21:47:05 UTC (rev 920)
+++ trunk/Tests/frmLauncher.cs 2009-04-27 04:44:12 UTC (rev 921)
@@ -15,12 +15,13 @@
class TestInfo
{
public string Name { get; set; }
+ public string Category { get; set; }
public Type Class { get; set; }
}
- Dictionary<string, List<TestInfo>> tests = new Dictionary<string, List<TestInfo>>();
+ List<TestInfo> tests = new List<TestInfo>();
+ Font bold;
-
public frmLauncher()
{
InitializeComponent();
@@ -28,28 +29,31 @@
Icon = AgateLib.WinForms.FormUtil.AgateLibIcon;
LoadTests();
+
+ bold = new Font(lstTests.Font, FontStyle.Bold | FontStyle.Italic);
}
private void FillList()
{
- foreach (string key in tests.Keys)
+ tests.Sort((x, y) =>
{
- TreeNode n = new TreeNode { Text = key };
- int index = tree.Nodes.Add(n);
+ if (x.Class == y.Class)
+ return x.Name.CompareTo(y.Name);
+ else
+ return x.Category.CompareTo(y.Category);
+ });
- AddChildren(tests[key], index);
+ string lastCategory = null;
- n.Expand();
- }
-
- tree.Sort();
- }
-
- private void AddChildren(List<TestInfo> tests, int nodeIndex)
- {
foreach (var test in tests)
{
- tree.Nodes[nodeIndex].Nodes.Add(new TreeNode { Text = test.Name, Tag = test });
+ if (test.Category != lastCategory)
+ {
+ lstTests.Items.Add(test.Category);
+ lastCategory = test.Category;
+ }
+
+ this.lstTests.Items.Add(test);
}
}
@@ -73,17 +77,12 @@
{
IAgateTest obj = (IAgateTest)Activator.CreateInstance(t);
- if (tests.ContainsKey(obj.Category) == false)
- {
- tests[obj.Category] = new List<TestInfo>();
- }
-
- tests[obj.Category].Add(new TestInfo { Name = obj.Name, Class = t });
+ tests.Add(new TestInfo { Name = obj.Name, Category = obj.Category, Class = t });
}
- private void tree_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e)
+ private void lstTests_DoubleClick(object sender, EventArgs e)
{
- TestInfo t = e.Node.Tag as TestInfo;
+ TestInfo t = lstTests.SelectedItem as TestInfo;
if (t == null)
return;
@@ -122,5 +121,44 @@
this.Activate();
}
}
+
+ private void lstTests_DrawItem(object sender, DrawItemEventArgs e)
+ {
+ object item = lstTests.Items[e.Index];
+ const int indent = 15;
+
+ e.DrawBackground();
+
+ PointF loc = e.Bounds.Location;
+ Brush b = new SolidBrush(e.ForeColor);
+
+ if (item is string)
+ {
+ e.Graphics.DrawString((string)item, bold, b, loc);
+ }
+ else if (item is TestInfo)
+ {
+ TestInfo t = item as TestInfo;
+ loc.X += indent;
+
+ e.Graphics.DrawString(t.Name, lstTests.Font, b, loc);
+
+ var size = e.Graphics.MeasureString(t.Name, lstTests.Font);
+
+ size.Width += indent + 5;
+
+ if (lstTests.ColumnWidth < size.Width)
+ lstTests.ColumnWidth = (int) size.Width;
+ }
+
+ e.DrawFocusRectangle();
+ }
+
+ private void lstTests_MeasureItem(object sender, MeasureItemEventArgs e)
+ {
+
+ }
+
+
}
}
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ac...@us...> - 2009-04-26 21:47:24
|
Revision: 920
http://agate.svn.sourceforge.net/agate/?rev=920&view=rev
Author: accagon
Date: 2009-04-26 21:47:05 +0000 (Sun, 26 Apr 2009)
Log Message:
-----------
Add GravityManipulator, calculation is missing
Add PixelParticle
Added Paths:
-----------
branches/particles/AgateLib/Particles/GravityManipulator.cs
branches/particles/AgateLib/Particles/PixelParticle.cs
Added: branches/particles/AgateLib/Particles/GravityManipulator.cs
===================================================================
--- branches/particles/AgateLib/Particles/GravityManipulator.cs (rev 0)
+++ branches/particles/AgateLib/Particles/GravityManipulator.cs 2009-04-26 21:47:05 UTC (rev 920)
@@ -0,0 +1,77 @@
+// The contents of this file are subject to the Mozilla Public License
+// Version 1.1 (the "License"); you may not use this file except in
+// compliance with the License. You may obtain a copy of the License at
+// http://www.mozilla.org/MPL/
+//
+// Software distributed under the License is distributed on an "AS IS"
+// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+// License for the specific language governing rights and limitations
+// under the License.
+//
+// The Original Code is AgateLib.Particles.
+//
+// The Initial Developer of the Original Code is Marcel Hauf
+// Portions created by Marcel Hauf are Copyright (C) 2009.
+// All Rights Reserved.
+//
+// Contributor(s): Marcel Hauf.
+//
+using System;
+using System.Collections.Generic;
+
+using AgateLib.Geometry;
+
+namespace AgateLib.Particles
+{
+ /// <summary>
+ /// A gravity particle manipulator.
+ /// </summary>
+ public class GravityManipulator
+ {
+ private float mStrength = 1f;
+ private Vector2 mPosition = Vector2.Empty;
+
+ /// <value>
+ /// Gets or sets the strength.
+ /// </value>
+ public float Strength
+ {
+ get { return mStrength; }
+ set { mStrength = value; }
+ }
+
+ /// <value>
+ /// Gets or sets the position.
+ /// </value>
+ public Vector2 Position
+ {
+ get { return mPosition; }
+ set { mPosition = value; }
+ }
+
+ /// <summary>
+ /// Constructs a gravitiy manipulator.
+ /// </summary>
+ /// <param name="position"></param>
+ /// <param name="strength"></param>
+ public GravityManipulator(Vector2 position, float strength)
+ {
+ mPosition = position;
+ mStrength = strength;
+ }
+
+ /// <summary>
+ /// Subscribe to a particle emitter.
+ /// </summary>
+ /// <param name="emitter"></param>
+ public void SubscribeToEmitter(ParticleEmitter emitter)
+ {
+ emitter.UpdateParticles += Manipulate;
+ }
+
+ internal void Manipulate(List<Particle> particles, float time_ms)
+ {
+ // TODO: add missing calculation to gravity manipulator
+ }
+ }
+}
Added: branches/particles/AgateLib/Particles/PixelParticle.cs
===================================================================
--- branches/particles/AgateLib/Particles/PixelParticle.cs (rev 0)
+++ branches/particles/AgateLib/Particles/PixelParticle.cs 2009-04-26 21:47:05 UTC (rev 920)
@@ -0,0 +1,57 @@
+// The contents of this file are subject to the Mozilla Public License
+// Version 1.1 (the "License"); you may not use this file except in
+// compliance with the License. You may obtain a copy of the License at
+// http://www.mozilla.org/MPL/
+//
+// Software distributed under the License is distributed on an "AS IS"
+// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+// License for the specific language governing rights and limitations
+// under the License.
+//
+// The Original Code is AgateLib.Particles.
+//
+// The Initial Developer of the Original Code is Marcel Hauf
+// Portions created by Marcel Hauf are Copyright (C) 2009.
+// All Rights Reserved.
+//
+// Contributor(s): Marcel Hauf.
+//
+using System;
+
+using AgateLib.DisplayLib;
+using AgateLib.Geometry;
+
+namespace AgateLib.Particles
+{
+ /// <summary>
+ /// A particle which draws one pixel.
+ /// </summary>
+ public class PixelParticle : Particle
+ {
+ internal PixelBuffer mPixelBuffer = new PixelBuffer(PixelFormat.Any, new Size(1,1));
+
+ /// <value>
+ /// Gets or sets the color.
+ /// </value>
+ public Color Color
+ {
+ get { return mPixelBuffer.GetPixel(0,0); }
+ set {
+ mPixelBuffer.SetPixel(0,0, value);
+ base.Surface = new Surface(mPixelBuffer);
+ }
+ }
+
+ /// <summary>
+ /// Constructs a PixelParticle.
+ /// </summary>
+ /// <param name="color">
+ /// The color of the particle.
+ /// </param>
+ public PixelParticle(Color color)
+ {
+ mPixelBuffer.SetPixel(0,0, color);
+ base.Surface = new Surface(mPixelBuffer);
+ }
+ }
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ac...@us...> - 2009-04-26 21:37:53
|
Revision: 919
http://agate.svn.sourceforge.net/agate/?rev=919&view=rev
Author: accagon
Date: 2009-04-26 21:37:42 +0000 (Sun, 26 Apr 2009)
Log Message:
-----------
Add Particle and ParticleEmitter base class
Added Paths:
-----------
branches/particles/AgateLib/Particles/
branches/particles/AgateLib/Particles/Particle.cs
branches/particles/AgateLib/Particles/ParticleEmitter.cs
Added: branches/particles/AgateLib/Particles/Particle.cs
===================================================================
--- branches/particles/AgateLib/Particles/Particle.cs (rev 0)
+++ branches/particles/AgateLib/Particles/Particle.cs 2009-04-26 21:37:42 UTC (rev 919)
@@ -0,0 +1,155 @@
+// The contents of this file are subject to the Mozilla Public License
+// Version 1.1 (the "License"); you may not use this file except in
+// compliance with the License. You may obtain a copy of the License at
+// http://www.mozilla.org/MPL/
+//
+// Software distributed under the License is distributed on an "AS IS"
+// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+// License for the specific language governing rights and limitations
+// under the License.
+//
+// The Original Code is AgateLib.Particles.
+//
+// The Initial Developer of the Original Code is Marcel Hauf
+// Portions created by Marcel Hauf are Copyright (C) 2009.
+// All Rights Reserved.
+//
+// Contributor(s): Marcel Hauf.
+//
+using System;
+
+using AgateLib.DisplayLib;
+using AgateLib.Geometry;
+
+namespace AgateLib.Particles
+{
+ /// <summary>
+ /// Base class for particles.
+ /// </summary>
+ public class Particle
+ {
+ private float mLife = 10f;
+ private Condition mCondition = Condition.Empty;
+ private bool mIsDead = false;
+
+ private ISurface mSurface;
+
+ private Vector2 mAcceleration = Vector2.Empty;
+ private Vector2 mPosition = Vector2.Empty;
+ private Vector2 mVelocity = Vector2.Empty;
+
+ /// <value>
+ /// Gets or sets the life.
+ /// Life is stored in seconds.
+ /// </value>
+ public float Life
+ {
+ get { return mLife; }
+ set { mLife = value; }
+ }
+
+ /// <value>
+ /// Gets the condition.
+ /// </value>
+ public Condition Condition
+ {
+ get { return mCondition; }
+ }
+
+ /// <value>
+ /// Is particle dead.
+ /// </value>
+ public bool IsDead
+ {
+ get { return mIsDead; }
+ }
+
+ /// <value>
+ /// Gets or sets the surface.
+ /// </value>
+ public ISurface Surface
+ {
+ get { return mSurface; }
+ set { mSurface = value; }
+ }
+
+ /// <value>
+ /// Gets or sets the acceleration.
+ /// </value>
+ public Vector2 Acceleration
+ {
+ get { return mAcceleration; }
+ set { mAcceleration = value; }
+ }
+
+ /// <value>
+ /// Gets or sets the position.
+ /// </value>
+ public Vector2 Position
+ {
+ get { return mPosition; }
+ set { mPosition = value; }
+ }
+
+ /// <value>
+ /// Gets or sets the velocity.
+ /// </value>
+ public Vector2 Velocity
+ {
+ get { return mVelocity; }
+ set { mVelocity = value; }
+ }
+
+ /// <summary>
+ /// Draws the particle on screen.
+ /// </summary>
+ public virtual void Draw()
+ {
+ mSurface.Draw(mPosition.X, mPosition.Y);
+ }
+
+ /// <summary>
+ /// Updates the particle.
+ /// </summary>
+ /// <param name="time_ms">
+ /// Passed time in milliseconds since last update.
+ /// </param>
+ public virtual void Update(float time_ms)
+ {
+ // passed time in seconds
+ float time = time_ms/1000;
+ mLife -= time;
+
+ if(mLife <= 0)
+ {
+ mIsDead = true;
+ mCondition = Condition.Dead;
+ }
+
+ // Euler method
+ // v = v + a * dt
+ // x = x + v * dt
+ // mVelocity = mVelocity + mAcceleration * time;
+ // mPosition = mPosition + mVelocity * time;
+
+ // verlet integration
+ // xi+1 = xi + (xi - xi-1) + a * dt * dt
+ // mPosition = mPosition + (mPosition + mPosition - 1) + mAcceleration * time * time;
+
+ // timer correct verlet integration
+ // xi+1 = xi + (xi - xi-1) * (dti / dti-1) + a * dti * dti
+ // mPosition = mPosition + (mPosition - mPosition - 1) * (time / time - 1) + mAcceleration * time * time;
+ }
+ }
+
+ /// <summary>
+ /// Condition of a particle.
+ /// </summary>
+ [Flags]
+ public enum Condition
+ {
+ Empty = 0,
+ Dead = 1,
+ ALive = 2
+ }
+}
Added: branches/particles/AgateLib/Particles/ParticleEmitter.cs
===================================================================
--- branches/particles/AgateLib/Particles/ParticleEmitter.cs (rev 0)
+++ branches/particles/AgateLib/Particles/ParticleEmitter.cs 2009-04-26 21:37:42 UTC (rev 919)
@@ -0,0 +1,70 @@
+// The contents of this file are subject to the Mozilla Public License
+// Version 1.1 (the "License"); you may not use this file except in
+// compliance with the License. You may obtain a copy of the License at
+// http://www.mozilla.org/MPL/
+//
+// Software distributed under the License is distributed on an "AS IS"
+// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+// License for the specific language governing rights and limitations
+// under the License.
+//
+// The Original Code is AgateLib.Particles.
+//
+// The Initial Developer of the Original Code is Marcel Hauf
+// Portions created by Marcel Hauf are Copyright (C) 2009.
+// All Rights Reserved.
+//
+// Contributor(s): Marcel Hauf.
+//
+using System;
+using System.Collections.Generic;
+
+using AgateLib.Geometry;
+
+namespace AgateLib.Particles
+{
+ /// <summary>
+ /// Updates particles.
+ /// Provides a list of particles and passed time in milliseconds since last update.
+ /// </summary>
+ public delegate void UpdateParticles(List<Particle> particles, float time_ms);
+
+ /// <summary>
+ /// Base class for particle emitters.
+ /// </summary>
+ public abstract class ParticleEmitter : Particle
+ {
+ private List<Particle> mParticles = new List<Particle>();
+
+ /// <summary>
+ /// Delegate to update particles.
+ /// Particle manipulators should subscribe here.
+ /// </summary>
+ public UpdateParticles UpdateParticles;
+
+ /// <summary>
+ /// Overridden draw method.
+ /// Draws each particle.
+ /// </summary>
+ public override void Draw ()
+ {
+ mParticles.ForEach(delegate(Particle mParticle)
+ {
+ mParticle.Draw();
+ });
+ }
+
+ /// <summary>
+ /// Overridden update method.
+ /// Updates and manipulates each particle.
+ /// </summary>
+ /// <param name="time_ms">
+ /// Passed time in milliseconds since last update.
+ /// </param>
+ public override void Update (float time_ms)
+ {
+ UpdateParticles(mParticles, time_ms);
+ base.Update (time_ms);
+ }
+ }
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ac...@us...> - 2009-04-26 21:18:58
|
Revision: 918
http://agate.svn.sourceforge.net/agate/?rev=918&view=rev
Author: accagon
Date: 2009-04-26 21:18:48 +0000 (Sun, 26 Apr 2009)
Log Message:
-----------
Created branch for particle system support.
Added Paths:
-----------
branches/particles/
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ka...@us...> - 2009-04-25 21:46:43
|
Revision: 917
http://agate.svn.sourceforge.net/agate/?rev=917&view=rev
Author: kanato
Date: 2009-04-25 21:46:26 +0000 (Sat, 25 Apr 2009)
Log Message:
-----------
Integrate font branch for new text layout engine.
Modified Paths:
--------------
trunk/AgateLib/BitmapFont/BitmapFontImpl.cs
trunk/AgateLib/DisplayLib/Cache/FontStateCache.cs
trunk/AgateLib/DisplayLib/Cache/SurfaceStateCache.cs
trunk/AgateLib/DisplayLib/FontSurface.cs
trunk/AgateLib/DisplayLib/ISurface.cs
trunk/AgateLib/DisplayLib/OriginAlignment.cs
trunk/AgateLib/DisplayLib/Surface.cs
trunk/AgateLib/Drivers/IDesktopDriver.cs
trunk/AgateLib/Drivers/NullInputImpl.cs
trunk/AgateLib/Geometry/Rectangle.cs
trunk/AgateLib/ImplementationBase/FontSurfaceImpl.cs
trunk/AgateLib/ImplementationBase/SurfaceImpl.cs
trunk/AgateLib/Sprites/IFrameList.cs
trunk/AgateLib/Sprites/Sprite.cs
trunk/AgateLib/Sprites/SpriteFrame.cs
trunk/Drivers/AgateDrawing/Drawing_FontSurface.cs
trunk/Drivers/AgateDrawing/Drawing_Surface.cs
trunk/Drivers/AgateMDX/MDX1_FontSurface.cs
trunk/Drivers/AgateMDX/MDX1_Surface.cs
trunk/Drivers/AgateOTK/GL_Surface.cs
Added Paths:
-----------
trunk/AgateLib/DisplayLib/Cache/
trunk/AgateLib/DisplayLib/FontState.cs
trunk/AgateLib/DisplayLib/SurfaceState.cs
trunk/AgateLib/DisplayLib/TextLayout.cs
trunk/Tests/Fonts/TextLayout.cs
Property Changed:
----------------
trunk/
trunk/AgateLib/
trunk/AgateLib/AgateFileProvider.cs
trunk/AgateLib/AgateSetup.cs
trunk/AgateLib/AudioLib/
trunk/AgateLib/AudioLib/Audio.cs
trunk/AgateLib/BitmapFont/FontMetrics.cs
trunk/AgateLib/BitmapFont/GlyphMetrics.cs
trunk/AgateLib/Core.cs
trunk/AgateLib/DisplayLib/
trunk/AgateLib/DisplayLib/Display.cs
trunk/AgateLib/DisplayLib/StringTransformer.cs
trunk/AgateLib/Drivers/AgateDriverReporter.cs
trunk/AgateLib/Drivers/IDesktopDriver.cs
trunk/AgateLib/ImplementationBase/
trunk/AgateLib/ImplementationBase/AudioImpl.cs
trunk/AgateLib/InputLib/
trunk/AgateLib/Resources/AgateResourceCollection.cs
trunk/AgateLib/Resources/AgateResourceLoader.cs
trunk/AgateLib/Resources/BitmapFontResource.cs
trunk/AgateLib/Sprites/Sprite.cs
trunk/AgateLib/Sprites/SpriteFrame.cs
trunk/AgateLib/Timing.cs
trunk/AgateLib/Utility/Platform.cs
trunk/Build/monodevelop.sh
trunk/Drivers/
trunk/Drivers/AgateDrawing/Drawing_Reporter.cs
trunk/Drivers/AgateLib.WinForms/
trunk/Drivers/AgateSDL/
trunk/Drivers/AgateSDL/Audio/SDL_Audio.cs
trunk/Drivers/AgateSDL/Audio/SDL_Music.cs
trunk/Drivers/AgateSDL/Audio/SDL_SoundBuffer.cs
trunk/Drivers/AgateSDL/Audio/SDL_SoundBufferSession.cs
trunk/Drivers/AgateSDL/Input/SDL_Input.cs
trunk/Drivers/AgateSDL/Reporter.cs
trunk/Examples/BallBuster.Net/OpenTK.dll.config
trunk/Tools/FontCreator/CreateFont.Designer.cs
trunk/Tools/FontCreator/CreateFont.cs
trunk/Tools/FontCreator/CreateFont.resx
trunk/Tools/FontCreator/EditGlyphs.Designer.cs
trunk/Tools/FontCreator/EditGlyphs.cs
trunk/Tools/FontCreator/EditGlyphs.resx
trunk/Tools/FontCreator/SaveFont.Designer.cs
trunk/Tools/FontCreator/SaveFont.cs
trunk/Tools/FontCreator/SaveFont.resx
trunk/Tools/FontCreator/frmFontCreator.Designer.cs
trunk/Tools/FontCreator/frmFontCreator.cs
trunk/Tools/FontCreator/frmFontCreator.resx
trunk/Tools/PackedSpriteCreator/SpriteEditor.Designer.cs
trunk/Tools/PackedSpriteCreator/SpriteEditor.cs
trunk/Tools/PackedSpriteCreator/SpriteEditor.resx
trunk/Tools/PackedSpriteCreator/SpritePacker.cs
Property changes on: trunk
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/agate-3d:659
/branches/build:424-517
/branches/merge-tests:806-810
/branches/registrar:595-599
/branches/sprites:463-513
+ /branches/agate-3d:659
/branches/build:424-517
/branches/font:778-916
/branches/merge-tests:806-810
/branches/registrar:595-599
/branches/sprites:463-513
Property changes on: trunk/AgateLib
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/agate-3d/AgateLib:659
/branches/build/AgateLib:447-517
/branches/merge-tests/AgateLib:806-810
/branches/registrar/AgateLib:595-599
/branches/sprites/AgateLib:463-513
+ /branches/agate-3d/AgateLib:659
/branches/build/AgateLib:447-517
/branches/font/AgateLib:778-916
/branches/merge-tests/AgateLib:806-810
/branches/registrar/AgateLib:595-599
/branches/sprites/AgateLib:463-513
Property changes on: trunk/AgateLib/AgateFileProvider.cs
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/build/AgateLib/Utility/AgateFileProvider.cs:447-517
/branches/merge-tests/AgateLib/AgateFileProvider.cs:806-810
/branches/registrar/AgateLib/Utility/AgateFileProvider.cs:595-599
/branches/sprites/AgateLib/Utility/AgateFileProvider.cs:463-513
+ /branches/build/AgateLib/Utility/AgateFileProvider.cs:447-517
/branches/font/AgateLib/AgateFileProvider.cs:778-916
/branches/merge-tests/AgateLib/AgateFileProvider.cs:806-810
/branches/registrar/AgateLib/Utility/AgateFileProvider.cs:595-599
/branches/sprites/AgateLib/Utility/AgateFileProvider.cs:463-513
Property changes on: trunk/AgateLib/AgateSetup.cs
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/agate-3d/AgateLib/AgateSetup.cs:659
/branches/build/AgateLib/AgateSetup.cs:501-517
/branches/merge-tests/AgateLib/AgateSetup.cs:806-810
/branches/registrar/AgateLib/AgateSetup.cs:595-599
/branches/sprites/AgateLib/AgateSetup.cs:463-513
+ /branches/agate-3d/AgateLib/AgateSetup.cs:659
/branches/build/AgateLib/AgateSetup.cs:501-517
/branches/font/AgateLib/AgateSetup.cs:778-916
/branches/merge-tests/AgateLib/AgateSetup.cs:806-810
/branches/registrar/AgateLib/AgateSetup.cs:595-599
/branches/sprites/AgateLib/AgateSetup.cs:463-513
Property changes on: trunk/AgateLib/AudioLib
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/agate-3d/AgateLib/AudioLib:659
/branches/merge-tests/AgateLib/AudioLib:806-810
/branches/registrar/AgateLib/AudioLib:595-599
/branches/sprites/AgateLib/AudioLib:463-513
+ /branches/agate-3d/AgateLib/AudioLib:659
/branches/font/AgateLib/AudioLib:778-916
/branches/merge-tests/AgateLib/AudioLib:806-810
/branches/registrar/AgateLib/AudioLib:595-599
/branches/sprites/AgateLib/AudioLib:463-513
Property changes on: trunk/AgateLib/AudioLib/Audio.cs
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/agate-3d/AgateLib/AudioLib/Audio.cs:659
/branches/build/AgateLib/AudioLib/Audio.cs:501-517
/branches/merge-tests/AgateLib/AudioLib/Audio.cs:806-810
/branches/registrar/AgateLib/AudioLib/Audio.cs:595-599
/branches/sprites/AgateLib/AudioLib/Audio.cs:463-513
+ /branches/agate-3d/AgateLib/AudioLib/Audio.cs:659
/branches/build/AgateLib/AudioLib/Audio.cs:501-517
/branches/font/AgateLib/AudioLib/Audio.cs:778-916
/branches/merge-tests/AgateLib/AudioLib/Audio.cs:806-810
/branches/registrar/AgateLib/AudioLib/Audio.cs:595-599
/branches/sprites/AgateLib/AudioLib/Audio.cs:463-513
Modified: trunk/AgateLib/BitmapFont/BitmapFontImpl.cs
===================================================================
--- trunk/AgateLib/BitmapFont/BitmapFontImpl.cs 2009-04-25 19:58:56 UTC (rev 916)
+++ trunk/AgateLib/BitmapFont/BitmapFontImpl.cs 2009-04-25 21:46:26 UTC (rev 917)
@@ -20,10 +20,12 @@
using System.Collections.Generic;
using System.Text;
using System.Xml;
+
using AgateLib.DisplayLib;
using AgateLib.Geometry;
using AgateLib.ImplementationBase;
using AgateLib.Resources;
+using AgateLib.DisplayLib.Cache;
namespace AgateLib.BitmapFont
{
@@ -36,12 +38,46 @@
public class BitmapFontImpl : FontSurfaceImpl
{
Surface mSurface;
-
FontMetrics mFontMetrics;
int mCharHeight;
double mAverageCharWidth;
+ #region --- Cache Class ---
+
+ class BitmapFontCache : FontStateCache
+ {
+ public bool NeedsRefresh = true;
+ public RectangleF[] SrcRects;
+ public RectangleF[] DestRects;
+ public int DisplayTextLength;
+
+ protected internal override FontStateCache Clone()
+ {
+ BitmapFontCache cache = new BitmapFontCache();
+
+ cache.SrcRects = (RectangleF[])SrcRects.Clone();
+ cache.DestRects = (RectangleF[])DestRects.Clone();
+
+ return cache;
+ }
+
+ protected internal override void OnTextChanged(FontState fontState)
+ {
+ NeedsRefresh = true;
+ }
+ protected internal override void OnDisplayAlignmentChanged(FontState fontState)
+ {
+ NeedsRefresh = true;
+ }
+ protected internal override void OnLocationChanged(FontState fontState)
+ {
+ NeedsRefresh = true;
+ }
+ }
+
+ #endregion
+
/// <summary>
/// Constructs a BitmapFontImpl, assuming the characters in the given file
/// are all the same size, and are in their ASCII order.
@@ -81,15 +117,6 @@
}
/// <summary>
- /// Gets or sets the interpolation hint for the underlying surface.
- /// </summary>
- public InterpolationMode InterpolationHint
- {
- get { return mSurface.InterpolationHint; }
- set { mSurface.InterpolationHint = value; }
- }
-
- /// <summary>
/// Disposes of the object.
/// </summary>
public override void Dispose()
@@ -152,37 +179,18 @@
mAverageCharWidth = total / (double)count;
}
- /// <summary>
- /// Overrides the base Color method to catch color changes to set them on the surface.
- /// </summary>
- public override Color Color
+ public override Size StringDisplaySize(FontState state, string text)
{
- get
- {
- return base.Color;
- }
- set
- {
- base.Color = value;
-
- mSurface.Color = value;
- }
- }
- /// <summary>
- /// Measures the width of the text.
- /// </summary>
- /// <param name="text"></param>
- /// <returns></returns>
- public override int StringDisplayWidth(string text)
- {
if (string.IsNullOrEmpty(text))
- return 0;
+ return Size.Empty;
+ int CRcount = 0;
+ int i = 0;
double highestLineWidth = 0;
+ // measure width
string[] lines = text.Split('\n');
-
- for (int i = 0; i < lines.Length; i++)
+ for (i = 0; i < lines.Length; i++)
{
string line = lines[i];
double lineWidth = 0;
@@ -194,24 +202,10 @@
if (lineWidth > highestLineWidth)
highestLineWidth = lineWidth;
-
}
- return (int)Math.Ceiling(highestLineWidth * ScaleWidth);
- }
- /// <summary>
- /// Measures the height of the text
- /// </summary>
- /// <param name="text"></param>
- /// <returns></returns>
- public override int StringDisplayHeight(string text)
- {
- if (string.IsNullOrEmpty(text))
- return 0;
-
- int CRcount = 0;
- int i = 0;
-
+ // measure height
+ i = 0;
do
{
i = text.IndexOf('\n', i + 1);
@@ -226,17 +220,9 @@
if (text[text.Length - 1] == '\n')
CRcount--;
- return (int)(mCharHeight * (CRcount + 1) * ScaleHeight);
+ return new Size((int)Math.Ceiling(highestLineWidth * state.ScaleWidth),
+ (int)(mCharHeight * (CRcount + 1) * state.ScaleHeight));
}
- /// <summary>
- /// Measures the size of the text.
- /// </summary>
- /// <param name="text"></param>
- /// <returns></returns>
- public override Size StringDisplaySize(string text)
- {
- return new Size(StringDisplayWidth(text), StringDisplayHeight(text));
- }
/// <summary>
/// Returns the height of characters in the font.
@@ -246,7 +232,8 @@
get { return mCharHeight; }
}
- private void GetRects(string text, RectangleF[] srcRects, RectangleF[] destRects, out int rectCount)
+ private void GetRects(RectangleF[] srcRects, RectangleF[] destRects, out int rectCount,
+ string text, double ScaleHeight, double ScaleWidth)
{
double destX = 0;
double destY = 0;
@@ -271,7 +258,7 @@
case '\n':
destX = 0;
- destY += height * this.ScaleHeight;
+ destY += height * ScaleHeight;
break;
default:
@@ -295,89 +282,71 @@
}
}
- RectangleF[] cacheSrcRects;
- RectangleF[] cacheDestRects;
-
- /// <summary>
- /// Draws the text to the screen.
- /// </summary>
- /// <param name="destX"></param>
- /// <param name="destY"></param>
- /// <param name="text"></param>
- public override void DrawText(int destX, int destY, string text)
+ private static BitmapFontCache GetCache(FontState state)
{
- if (string.IsNullOrEmpty(text))
- return;
+ BitmapFontCache cache = state.Cache as BitmapFontCache;
- if (cacheSrcRects == null || text.Length > cacheSrcRects.Length)
+ if (cache == null)
{
- cacheSrcRects = new RectangleF[text.Length];
- cacheDestRects = new RectangleF[text.Length];
+ cache = new BitmapFontCache();
+ state.Cache = cache;
}
- RectangleF[] srcRects = cacheSrcRects;
- RectangleF[] destRects = cacheDestRects;
-
- DrawTextImpl(destX, destY, text, srcRects, destRects);
- }
-
- private void DrawTextImpl(int destX, int destY, string text,
- RectangleF[] srcRects, RectangleF[] destRects)
- {
- // this variable counts the number of rectangles actually used to display text.
- // It may be less then text.Length because carriage return characters
- // don't need any rects.
- int displayTextLength;
- GetRects(text, srcRects, destRects, out displayTextLength);
-
- if (DisplayAlignment != OriginAlignment.TopLeft)
+ if (cache.SrcRects == null ||
+ cache.SrcRects.Length < state.Text.Length)
{
- Point value = Origin.Calc(DisplayAlignment, StringDisplaySize(text));
-
- destX -= value.X;
- destY -= value.Y;
+ cache.SrcRects = new RectangleF[state.Text.Length];
+ cache.DestRects = new RectangleF[state.Text.Length];
}
- for (int i = 0; i < displayTextLength; i++)
- {
- destRects[i].X += destX;
- destRects[i].Y += destY;
- }
-
- mSurface.DrawRects(srcRects, destRects, 0, displayTextLength);
+ return cache;
}
/// <summary>
/// Draws the text to the screen.
/// </summary>
- /// <param name="destX"></param>
- /// <param name="destY"></param>
- /// <param name="text"></param>
- public override void DrawText(double destX, double destY, string text)
+ /// <param name="state"></param>
+ public override void DrawText(FontState state)
{
- DrawText((int)destX, (int)destY, text);
- }
+ BitmapFontCache cache = GetCache(state);
- /// <summary>
- /// Draws the text to the screen.
- /// </summary>
- /// <param name="destPt"></param>
- /// <param name="text"></param>
- public override void DrawText(Point destPt, string text)
- {
- DrawText(destPt.X, destPt.Y, text);
+ RefreshCache(state, cache);
+
+ mSurface.Color = state.Color;
+ mSurface.DrawRects(cache.SrcRects, cache.DestRects, 0, cache.DisplayTextLength);
}
- /// <summary>
- /// Draws the text to the screen.
- /// </summary>
- /// <param name="destPt"></param>
- /// <param name="text"></param>
- public override void DrawText(PointF destPt, string text)
+ private void RefreshCache(FontState state, BitmapFontCache cache)
{
- DrawText(destPt.X, destPt.Y, text);
- }
+ if (cache.NeedsRefresh)
+ {
+ // this variable counts the number of rectangles actually used to display text.
+ // It may be less then text.Length because carriage return characters
+ // don't need any rects.
+ GetRects(cache.SrcRects, cache.DestRects, out cache.DisplayTextLength,
+ state.Text, state.ScaleHeight, state.ScaleWidth);
+
+ PointF dest = state.Location;
+
+ if (state.DisplayAlignment != OriginAlignment.TopLeft)
+ {
+ Point value = Origin.Calc(state.DisplayAlignment,
+ StringDisplaySize(state, state.Text));
+
+ dest.X -= value.X;
+ dest.Y -= value.Y;
+ }
+
+ for (int i = 0; i < cache.DisplayTextLength; i++)
+ {
+ cache.DestRects[i].X += dest.X;
+ cache.DestRects[i].Y += dest.Y;
+ }
+
+ cache.NeedsRefresh = false;
+ }
+ }
}
/// <summary>
Property changes on: trunk/AgateLib/BitmapFont/FontMetrics.cs
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/agate-3d/AgateLib/BitmapFont/FontMetrics.cs:659
/branches/merge-tests/AgateLib/BitmapFont/FontMetrics.cs:806-810
+ /branches/agate-3d/AgateLib/BitmapFont/FontMetrics.cs:659
/branches/font/AgateLib/BitmapFont/FontMetrics.cs:778-916
/branches/merge-tests/AgateLib/BitmapFont/FontMetrics.cs:806-810
Property changes on: trunk/AgateLib/BitmapFont/GlyphMetrics.cs
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/agate-3d/AgateLib/BitmapFont/GlyphMetrics.cs:659
/branches/build/AgateLib/Resources/GlyphMetrics.cs:447-517
/branches/merge-tests/AgateLib/BitmapFont/GlyphMetrics.cs:806-810
/branches/registrar/AgateLib/Resources/GlyphMetrics.cs:595-599
/branches/sprites/AgateLib/Resources/GlyphMetrics.cs:463-513
+ /branches/agate-3d/AgateLib/BitmapFont/GlyphMetrics.cs:659
/branches/build/AgateLib/Resources/GlyphMetrics.cs:447-517
/branches/font/AgateLib/BitmapFont/GlyphMetrics.cs:778-916
/branches/merge-tests/AgateLib/BitmapFont/GlyphMetrics.cs:806-810
/branches/registrar/AgateLib/Resources/GlyphMetrics.cs:595-599
/branches/sprites/AgateLib/Resources/GlyphMetrics.cs:463-513
Property changes on: trunk/AgateLib/Core.cs
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/agate-3d/AgateLib/Core.cs:659
/branches/build/AgateLib/Core.cs:501-517
/branches/merge-tests/AgateLib/Core.cs:806-810
/branches/registrar/AgateLib/Core.cs:595-599
/branches/sprites/AgateLib/Core.cs:463-513
+ /branches/agate-3d/AgateLib/Core.cs:659
/branches/build/AgateLib/Core.cs:501-517
/branches/font/AgateLib/Core.cs:778-916
/branches/merge-tests/AgateLib/Core.cs:806-810
/branches/registrar/AgateLib/Core.cs:595-599
/branches/sprites/AgateLib/Core.cs:463-513
Property changes on: trunk/AgateLib/DisplayLib
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/agate-3d/AgateLib/DisplayLib:659
/branches/merge-tests/AgateLib/DisplayLib:806-810
/branches/registrar/AgateLib/DisplayLib:595-599
/branches/sprites/AgateLib/DisplayLib:463-513
+ /branches/agate-3d/AgateLib/DisplayLib:659
/branches/font/AgateLib/DisplayLib:778-916
/branches/merge-tests/AgateLib/DisplayLib:806-810
/branches/registrar/AgateLib/DisplayLib:595-599
/branches/sprites/AgateLib/DisplayLib:463-513
Property changes on: trunk/AgateLib/DisplayLib/Display.cs
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/agate-3d/AgateLib/DisplayLib/Display.cs:659
/branches/build/AgateLib/DisplayLib/Display.cs:501-517
/branches/merge-tests/AgateLib/DisplayLib/Display.cs:806-810
/branches/registrar/AgateLib/DisplayLib/Display.cs:595-599
/branches/sprites/AgateLib/DisplayLib/Display.cs:463-513
+ /branches/agate-3d/AgateLib/DisplayLib/Display.cs:659
/branches/build/AgateLib/DisplayLib/Display.cs:501-517
/branches/font/AgateLib/DisplayLib/Display.cs:778-916
/branches/merge-tests/AgateLib/DisplayLib/Display.cs:806-810
/branches/registrar/AgateLib/DisplayLib/Display.cs:595-599
/branches/sprites/AgateLib/DisplayLib/Display.cs:463-513
Added: trunk/AgateLib/DisplayLib/FontState.cs
===================================================================
--- trunk/AgateLib/DisplayLib/FontState.cs (rev 0)
+++ trunk/AgateLib/DisplayLib/FontState.cs 2009-04-25 21:46:26 UTC (rev 917)
@@ -0,0 +1,181 @@
+// The contents of this file are subject to the Mozilla Public License
+// Version 1.1 (the "License"); you may not use this file except in
+// compliance with the License. You may obtain a copy of the License at
+// http://www.mozilla.org/MPL/
+//
+// Software distributed under the License is distributed on an "AS IS"
+// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+// License for the specific language governing rights and limitations
+// under the License.
+//
+// The Original Code is AgateLib.
+//
+// The Initial Developer of the Original Code is Erik Ylvisaker.
+// Portions created by Erik Ylvisaker are Copyright (C) 2006-2009.
+// All Rights Reserved.
+//
+// Contributor(s): Erik Ylvisaker
+//
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using AgateLib.Geometry;
+using AgateLib.DisplayLib.Cache;
+
+namespace AgateLib.DisplayLib
+{
+ public class FontState : ICloneable
+ {
+ private OriginAlignment mAlignment = OriginAlignment.TopLeft;
+ private Color mColor = Color.White;
+ private double mScaleWidth = 1.0;
+ private double mScaleHeight = 1.0;
+ private PointF mLocation;
+ private string mText;
+ private FontStateCache mCache;
+
+ /// <summary>
+ /// Gets or sets the text that is displayed when drawn.
+ /// </summary>
+ public string Text
+ {
+ get { return mText; }
+ set
+ {
+ mText = value;
+
+ if (Cache != null)
+ Cache.OnTextChanged(this);
+ }
+ }
+ /// <summary>
+ /// Gets or sets the location where text is drawn.
+ /// </summary>
+ public PointF Location
+ {
+ get { return mLocation; }
+ set
+ {
+ mLocation = value;
+
+ if (Cache != null)
+ Cache.OnLocationChanged(this);
+ }
+ }
+ /// <summary>
+ /// Sets how to interpret the point given to DrawText methods.
+ /// </summary>
+ public OriginAlignment DisplayAlignment
+ {
+ get { return mAlignment; }
+ set
+ {
+ mAlignment = value;
+
+ if (Cache != null)
+ Cache.OnDisplayAlignmentChanged(this);
+ }
+ }
+ /// <summary>
+ /// Sets the color of the text to be drawn.
+ /// </summary>
+ public Color Color
+ {
+ get { return mColor; }
+ set
+ {
+ mColor = value;
+
+ if (Cache != null)
+ Cache.OnColorChanged(this);
+ }
+ }
+ /// <summary>
+ /// Sets the alpha value of the text to be drawn.
+ /// </summary>
+ public double Alpha
+ {
+ get { return mColor.A / 255.0; }
+ set
+ {
+ if (value < 0) value = 0;
+ if (value > 1.0) value = 1.0;
+
+ mColor = Color.FromArgb((int)(value * 255), mColor);
+
+ if (Cache != null)
+ Cache.OnColorChanged(this);
+ }
+ }
+ /// <summary>
+ /// Gets or sets the amount the width is scaled when the text is drawn.
+ /// 1.0 is no scaling.
+ /// </summary>
+ public double ScaleWidth
+ {
+ get { return mScaleWidth; }
+ set
+ {
+ mScaleWidth = value;
+
+ if (Cache != null)
+ Cache.OnScaleChanged(this);
+ }
+ }
+ /// <summary>
+ /// Gets or sets the amount the height is scaled when the text is drawn.
+ /// 1.0 is no scaling.
+ /// </summary>
+ public double ScaleHeight
+ {
+ get { return mScaleHeight; }
+ set
+ {
+ mScaleHeight = value;
+
+ if (Cache != null)
+ Cache.OnScaleChanged(this);
+ }
+ }
+ /// <summary>
+ /// This value is used by the implementation to optimize rendering this state object.
+ /// Do not set this value unless you know what you are doing, or writing an implementation
+ /// of FontSurfaceImpl.
+ /// </summary>
+ public FontStateCache Cache
+ {
+ get { return mCache; }
+ set { mCache = value; }
+ }
+
+ #region --- ICloneable Members ---
+
+ public FontState Clone()
+ {
+ FontState retval = new FontState();
+
+ retval.mAlignment = mAlignment;
+ retval.mColor = mColor;
+ retval.mScaleWidth = mScaleWidth;
+ retval.mScaleHeight = mScaleHeight;
+ retval.mLocation = mLocation;
+ retval.mText = mText;
+
+ if (mCache != null)
+ {
+ retval.mCache = mCache.Clone();
+ }
+
+ return retval;
+ }
+
+ object ICloneable.Clone()
+ {
+ return Clone();
+ }
+
+ #endregion
+ }
+
+}
\ No newline at end of file
Modified: trunk/AgateLib/DisplayLib/FontSurface.cs
===================================================================
--- trunk/AgateLib/DisplayLib/FontSurface.cs 2009-04-25 19:58:56 UTC (rev 916)
+++ trunk/AgateLib/DisplayLib/FontSurface.cs 2009-04-25 21:46:26 UTC (rev 917)
@@ -18,8 +18,9 @@
//
using System;
using System.Collections.Generic;
+using System.Linq;
using System.Text;
-
+using System.Text.RegularExpressions;
using AgateLib.BitmapFont;
using AgateLib.Geometry;
using AgateLib.ImplementationBase;
@@ -67,6 +68,7 @@
{
internal FontSurfaceImpl impl;
private StringTransformer mTransformer = StringTransformer.None;
+ FontState mState = new FontState();
/// <summary>
/// Creates a FontSurface object from the given fontFamily.
@@ -189,67 +191,80 @@
}
/// <summary>
- /// Sets the interpretation of the draw point used.
+ /// Gets or sets the state of the font object.
/// </summary>
+ public FontState State
+ {
+ get { return mState; }
+ set
+ {
+ if (value == null)
+ throw new ArgumentNullException("Cannot set state to a null value. If you wish to reset the state, set it to a new FontState object.");
+
+ mState = value;
+ }
+ }
+ /// <summary>
+ /// Sets how to interpret the point given to DrawText methods.
+ /// </summary>
public OriginAlignment DisplayAlignment
{
- get { return impl.DisplayAlignment; }
- set { impl.DisplayAlignment = value; }
+ get { return mState.DisplayAlignment; }
+ set { mState.DisplayAlignment = value; }
}
/// <summary>
- /// Sets the color of the font.
+ /// Sets the color of the text to be drawn.
/// </summary>
public Color Color
{
- get { return impl.Color; }
- set { impl.Color = value; }
+ get { return mState.Color; }
+ set { mState.Color = value; }
}
/// <summary>
- /// Sets the transparency of the font.
- /// 0.0 is fully transparent
- /// 1.0 is completely opaque.
+ /// Sets the alpha value of the text to be drawn.
/// </summary>
public double Alpha
{
- get { return impl.Alpha; }
- set { impl.Alpha = value; }
+ get { return mState.Alpha; }
+ set { mState.Alpha = value; }
}
-
/// <summary>
- /// Sets the scale of the font.
+ /// Gets or sets the amount the width is scaled when the text is drawn.
+ /// 1.0 is no scaling.
/// </summary>
- /// <param name="x"></param>
- /// <param name="y"></param>
- public void SetScale(double x, double y)
+ public double ScaleWidth
{
- impl.SetScale(x, y);
+ get { return mState.ScaleWidth; }
+ set { mState.ScaleWidth = value; }
}
/// <summary>
- /// Gets the scale of the font.
+ /// Gets or sets the amount the height is scaled when the text is drawn.
+ /// 1.0 is no scaling.
/// </summary>
- /// <param name="x"></param>
- /// <param name="y"></param>
- public void GetScale(out double x, out double y)
+ public double ScaleHeight
{
- impl.GetScale(out x, out y);
+ get { return mState.ScaleHeight; }
+ set { mState.ScaleHeight = value; }
}
/// <summary>
- /// Gets or sets the amount the width is scaled when the text is drawn.
- /// 1.0 is no scaling.
+ /// Sets ScaleWidth and ScaleHeight.
/// </summary>
- public double ScaleWidth
+ /// <param name="x"></param>
+ /// <param name="y"></param>
+ public void SetScale(double x, double y)
{
- get { return impl.ScaleWidth; }
- set { impl.ScaleWidth = value; }
+ ScaleWidth = x;
+ ScaleHeight = y;
}
/// <summary>
- /// Gets or sets the amount the height is scaled when the text is drawn.
- /// 1.0 is no scaling.
+ /// Gets ScaleWidth and ScaleHeight.
/// </summary>
- public double ScaleHeight
+ /// <param name="x"></param>
+ /// <param name="y"></param>
+ public void GetScale(out double x, out double y)
{
- get { return impl.ScaleHeight; }
- set { impl.ScaleHeight = value; }
+ x = ScaleWidth;
+ y = ScaleHeight;
}
/// <summary>
@@ -257,19 +272,38 @@
/// </summary>
/// <param name="text"></param>
/// <returns></returns>
- public int StringDisplayWidth(string text) { return impl.StringDisplayWidth(text); }
+ public int StringDisplayWidth(string text)
+ {
+ return StringDisplaySize(text).Width;
+ }
/// <summary>
/// Measures the display height of the specified string.
/// </summary>
/// <param name="text"></param>
/// <returns></returns>
- public int StringDisplayHeight(string text) { return impl.StringDisplayHeight(text); }
+ public int StringDisplayHeight(string text)
+ {
+ return StringDisplaySize(text).Height;
+ }
/// <summary>
/// Measures the display size of the specified string.
/// </summary>
/// <param name="text"></param>
/// <returns></returns>
- public Size StringDisplaySize(string text) { return impl.StringDisplaySize(text); }
+ public Size StringDisplaySize(string text)
+ {
+ return impl.StringDisplaySize(mState, text);
+ }
+ /// <summary>
+ /// Measures the display size of the specified string, using the specified state information.
+ /// </summary>
+ /// <param name="state"></param>
+ /// <param name="text"></param>
+ /// <returns></returns>
+ public Size StringDisplaySize(FontState state, string text)
+ {
+ return impl.StringDisplaySize(state, text);
+ }
/// <summary>
/// Gets the height in pixels of a single line of text.
@@ -279,25 +313,20 @@
get { return impl.FontHeight; }
}
+ public TextImageLayout TextImageLayout { get; set; }
+
/// <summary>
/// Draws the specified string at the specified location.
/// </summary>
/// <param name="destX"></param>
/// <param name="destY"></param>
/// <param name="text"></param>
- public void DrawText(int destX, int destY, string text)
- {
- impl.DrawText(destX, destY, mTransformer.Transform(text));
- }
- /// <summary>
- /// Draws the specified string at the specified location.
- /// </summary>
- /// <param name="destX"></param>
- /// <param name="destY"></param>
- /// <param name="text"></param>
public void DrawText(double destX, double destY, string text)
{
- impl.DrawText(destX, destY, mTransformer.Transform(text));
+ mState.Location = new PointF((float)destX, (float)destY);
+ mState.Text = mTransformer.Transform(text);
+
+ DrawText(mState);
}
/// <summary>
/// Draws the specified string at the specified location.
@@ -306,7 +335,10 @@
/// <param name="text"></param>
public void DrawText(Point destPt, string text)
{
- impl.DrawText(destPt.X, destPt.Y, mTransformer.Transform(text));
+ mState.Location = new PointF(destPt.X, destPt.Y);
+ mState.Text = mTransformer.Transform(text);
+
+ DrawText(mState);
}
/// <summary>
/// Draws the specified string at the specified location.
@@ -315,7 +347,10 @@
/// <param name="text"></param>
public void DrawText(PointF destPt, string text)
{
- impl.DrawText(destPt.X, destPt.Y, mTransformer.Transform(text));
+ mState.Location = destPt;
+ mState.Text = mTransformer.Transform(text);
+
+ DrawText(mState);
}
/// <summary>
/// Draws the specified string at the origin.
@@ -323,7 +358,226 @@
/// <param name="text"></param>
public void DrawText(string text)
{
- impl.DrawText(0, 0, mTransformer.Transform(text));
+ mState.Location = PointF.Empty;
+ mState.Text = mTransformer.Transform(text);
+
+ DrawText(mState);
}
+
+ public void DrawText(FontState state)
+ {
+ impl.DrawText(state);
+ }
+
+ Regex substituteMatch = new Regex(@"\{.*?\}|\{\{\}|\{\}\}|\r\n|\n");
+ Regex indexMatch = new Regex(@"[0-9]+:?");
+
+ public void DrawText(int destX, int destY, string formatString, params object[] args)
+ {
+ TextLayout layout = CreateLayout(formatString, args);
+
+ layout.Translate(new Point(destX, destY));
+ layout.DrawAll();
+ }
+
+ public TextLayout CreateLayout(string formatString, object[] args)
+ {
+ var matches = substituteMatch.Matches(formatString);
+
+ if (matches.Count == 0)
+ {
+ return new TextLayout
+ {
+ new LayoutText
+ {
+ Font = this,
+ State = this.State.Clone(),
+ LineIndex = 0,
+ Text = formatString
+ }
+ };
+ }
+
+ int lastIndex = 0;
+ string result = string.Empty;
+ PointF dest;
+
+ dest = PointF.Empty;
+
+ TextLayout layout = new TextLayout();
+ int lineHeight = FontHeight;
+ int spaceAboveLine = 0;
+ int lineIndex = 0;
+ AlterFont currentAlterText = null;
+
+ for (int i = 0; i < matches.Count; i++)
+ {
+ string format = formatString.Substring(matches[i].Index, matches[i].Length);
+
+ result += formatString.Substring(lastIndex, matches[i].Index - lastIndex);
+
+ var argsIndexText = indexMatch.Match(format);
+ int argsIndex;
+
+ if (format == "\r\n" || format == "\n")
+ {
+ PushLayoutText(lineIndex, layout, ref dest, ref lineHeight, ref spaceAboveLine,
+ result, currentAlterText);
+
+ result = string.Empty;
+
+ ShiftLine(layout, spaceAboveLine, lineIndex);
+
+ dest.X = 0;
+ dest.Y += lineHeight;
+
+ lineIndex++;
+ lineHeight = FontHeight;
+
+ spaceAboveLine = 0;
+ }
+ else if (int.TryParse(argsIndexText.ToString(), out argsIndex))
+ {
+ if (argsIndex >= args.Length)
+ {
+ throw new IndexOutOfRangeException(string.Format(
+ "Argument number {0} was specified, but only {1} arguments were given.", argsIndex, args.Length));
+ }
+ object obj = args[argsIndex];
+
+ if (obj is ISurface)
+ {
+ PushLayoutText(lineIndex, layout, ref dest, ref lineHeight, ref spaceAboveLine,
+ result, currentAlterText);
+
+ PushLayoutImage(lineIndex, layout, ref dest, ref lineHeight, ref spaceAboveLine,
+ (ISurface)obj);
+
+ result = string.Empty;
+ }
+ else if (obj is AlterFont)
+ {
+ // push text with the old state
+ PushLayoutText(lineIndex, layout, ref dest, ref lineHeight, ref spaceAboveLine,
+ result, currentAlterText);
+
+ // store the new alter object to affect the state of the next block.
+ currentAlterText = (AlterFont)obj;
+ result = string.Empty;
+ }
+ else
+ {
+ result += ConvertToString(obj, format);
+ }
+ }
+ else if (format.StartsWith("{"))
+ {
+ if (format == "{{}")
+ result += "{";
+ else if (format == "{}}")
+ result += "}";
+ }
+
+ lastIndex = matches[i].Index + matches[i].Length;
+ }
+
+ result += formatString.Substring(lastIndex);
+ PushLayoutText(lineIndex, layout, ref dest, ref lineHeight, ref spaceAboveLine,
+ result, currentAlterText);
+
+ ShiftLine(layout, spaceAboveLine, lineIndex);
+
+ return layout;
+ }
+
+ private static void ShiftLine(TextLayout layout, int lineShift, int lineIndex)
+ {
+ foreach (var item in layout.Where(x => x.LineIndex == lineIndex))
+ {
+ item.Location = new PointF(
+ item.Location.X, item.Location.Y + lineShift);
+ }
+ }
+
+ private void PushLayoutImage(int lineIndex, TextLayout layout,
+ ref PointF dest, ref int lineHeight, ref int spaceAboveLine,
+ ISurface surface)
+ {
+ int newSpaceAbove;
+ LayoutSurface t = new LayoutSurface { Location = dest, Surface = surface, LineIndex = lineIndex };
+ t.State = surface.State.Clone();
+
+ var update = Origin.Calc(DisplayAlignment, surface.SurfaceSize);
+
+ lineHeight = Math.Max(lineHeight, surface.DisplayHeight);
+ dest.X += surface.DisplayWidth;
+
+ switch (TextImageLayout)
+ {
+ case TextImageLayout.InlineTop:
+ break;
+ case TextImageLayout.InlineCenter:
+ newSpaceAbove = (surface.DisplayHeight - FontHeight) / 2;
+ t.Y -= newSpaceAbove;
+ spaceAboveLine = Math.Max(spaceAboveLine, newSpaceAbove);
+
+ break;
+
+ case TextImageLayout.InlineBottom:
+ newSpaceAbove = surface.DisplayHeight - FontHeight;
+ t.Y -= newSpaceAbove;
+ spaceAboveLine = Math.Max(spaceAboveLine, newSpaceAbove);
+
+ break;
+ }
+
+ layout.Add(t);
+ }
+
+ private void PushLayoutText(int lineIndex, TextLayout layout,
+ ref PointF dest, ref int lineHeight, ref int spaceAboveLine,
+ string text, AlterFont alter)
+ {
+ if (string.IsNullOrEmpty(text))
+ return;
+
+ LayoutText t = new LayoutText
+ {
+ Font = this,
+ State = State.Clone(),
+ Location = dest,
+ Text = text,
+ LineIndex = lineIndex
+ };
+
+ if (alter != null)
+ {
+ alter.ModifyState(t.State);
+ }
+
+ var size = StringDisplaySize(t.State, text);
+ var update = Origin.Calc(DisplayAlignment, size);
+
+ int newSpaceAbove = size.Height - FontHeight;
+ t.Y -= newSpaceAbove;
+ spaceAboveLine = Math.Max(spaceAboveLine, newSpaceAbove);
+
+ dest.X += size.Width;
+
+ layout.Add(t);
+ }
+
+ private string ConvertToString(object obj, string format)
+ {
+ return obj.ToString();
+ }
+
}
+
+ public enum TextImageLayout
+ {
+ InlineTop,
+ InlineCenter,
+ InlineBottom,
+ }
}
Modified: trunk/AgateLib/DisplayLib/ISurface.cs
===================================================================
--- trunk/AgateLib/DisplayLib/ISurface.cs 2009-04-25 19:58:56 UTC (rev 916)
+++ trunk/AgateLib/DisplayLib/ISurface.cs 2009-04-25 21:46:26 UTC (rev 917)
@@ -134,5 +134,9 @@
/// Gets the width of the surface data in pixels.
/// </summary>
int SurfaceWidth { get; }
+
+ SurfaceState State { get; }
+
+ void Draw(SurfaceState State);
}
}
Modified: trunk/AgateLib/DisplayLib/OriginAlignment.cs
===================================================================
--- trunk/AgateLib/DisplayLib/OriginAlignment.cs 2009-04-25 19:58:56 UTC (rev 916)
+++ trunk/AgateLib/DisplayLib/OriginAlignment.cs 2009-04-25 21:46:26 UTC (rev 917)
@@ -64,6 +64,12 @@
/// Point indicates bottom-right.
/// </summary>
BottomRight = 0x33,
+
+ /// <summary>
+ /// Specified indicates that the value in question is specified through
+ /// some other means.
+ /// </summary>
+ Specified = 0xFF,
}
}
Property changes on: trunk/AgateLib/DisplayLib/StringTransformer.cs
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/agate-3d/AgateLib/DisplayLib/StringTransformer.cs:659
/branches/build/AgateLib/DisplayLib/StringTransformer.cs:501-517
/branches/merge-tests/AgateLib/DisplayLib/StringTransformer.cs:806-810
/branches/registrar/AgateLib/DisplayLib/StringTransformer.cs:595-599
/branches/sprites/AgateLib/DisplayLib/StringTransformer.cs:463-513
+ /branches/agate-3d/AgateLib/DisplayLib/StringTransformer.cs:659
/branches/build/AgateLib/DisplayLib/StringTransformer.cs:501-517
/branches/font/AgateLib/DisplayLib/StringTransformer.cs:778-916
/branches/merge-tests/AgateLib/DisplayLib/StringTransformer.cs:806-810
/branches/registrar/AgateLib/DisplayLib/StringTransformer.cs:595-599
/branches/sprites/AgateLib/DisplayLib/StringTransformer.cs:463-513
Modified: trunk/AgateLib/DisplayLib/Surface.cs
===================================================================
--- trunk/AgateLib/DisplayLib/Surface.cs 2009-04-25 19:58:56 UTC (rev 916)
+++ trunk/AgateLib/DisplayLib/Surface.cs 2009-04-25 21:46:26 UTC (rev 917)
@@ -91,6 +91,7 @@
public sealed class Surface : IRenderTarget, IDisposable, ISurface
{
SurfaceImpl impl;
+ SurfaceState mState = new SurfaceState();
/// <summary>
/// Creates a surface object from a resource.
@@ -188,8 +189,6 @@
}
/// <summary>
/// Creates a surface object and to be ready to attach to an implemented object.
- /// Throws an Exception if there is a passed impl.
- /// (This is not intended for use by applications).
/// </summary>
/// <param name="fromImpl"></param>
internal Surface(SurfaceImpl fromImpl)
@@ -205,6 +204,7 @@
impl = fromImpl;
}
+
/// <summary>
/// Destroyes unmanaged resources associated with this surface.
/// </summary>
@@ -286,20 +286,29 @@
/// <summary>
+ /// Gets or sets the state of the surface.
+ /// </summary>
+ public SurfaceState State
+ {
+ get { return mState; }
+ set { mState = value; }
+ }
+
+ /// <summary>
/// Get or sets the width of the surface in pixels when it will be displayed on screen.
/// </summary>
public int DisplayWidth
{
- get { return impl.DisplayWidth; }
- set { impl.DisplayWidth = value; }
+ get { return (int)(mState.ScaleWidth * SurfaceWidth); }
+ set { ScaleWidth = value / (double)SurfaceWidth; }
}
/// <summary>
/// Gets or sets the height of the surface in pixels when it is displayed on screen.
/// </summary>
public int DisplayHeight
{
- get { return impl.DisplayHeight; }
- set { impl.DisplayHeight = value; }
+ get { return (int)(mState.ScaleHeight * SurfaceHeight); }
+ set { ScaleHeight = value / (double)SurfaceHeight; }
}
/// <summary>
/// Gets or sets the Size of the area used by this surface when displayed on screen.
@@ -323,11 +332,19 @@
/// Alpha value for displaying this surface.
/// Valid values range from 0.0 (completely transparent) to 1.0 (completely opaque).
/// Internally stored as a byte, so granularity is only 1/255.0.
+ /// If a gradient is used, getting this property returns the alpha value for the top left
+ /// corner of the gradient.
/// </summary>
public double Alpha
{
- get { return impl.Alpha; }
- set { impl.Alpha = value; }
+ get { return Color.A / 255.0; }
+ set
+ {
+ Gradient g = mState.ColorGradient;
+ g.SetAlpha(value);
+
+ mState.ColorGradient = g;
+ }
}
/// <summary>
/// Gets or sets the rotation angle in radians.
@@ -335,8 +352,8 @@
/// </summary>
public double RotationAngle
{
- get { return impl.RotationAngle; }
- set { impl.RotationAngle = value; }
+ get { return mState.RotationAngle; }
+ set { mState.RotationAngle = value; }
}
/// <summary>
/// Gets or sets the rotation angle in degrees.
@@ -352,16 +369,16 @@
/// </summary>
public OriginAlignment RotationCenter
{
- get { return impl.RotationCenter; }
- set { impl.RotationCenter = value; }
+ get { return mState.RotationCenter; }
+ set { mState.RotationCenter = value; }
}
/// <summary>
/// Gets or sets the point where the surface is aligned to when drawn.
/// </summary>
public OriginAlignment DisplayAlignment
{
- get { return impl.DisplayAlignment; }
- set { impl.DisplayAlignment = value; }
+ get { return mState.DisplayAlignment; }
+ set { mState.DisplayAlignment = value; }
}
/// <summary>
@@ -374,8 +391,8 @@
/// </summary>
public double ScaleWidth
{
- get { return impl.ScaleWidth; }
- set { impl.ScaleWidth = value; }
+ get { return mState.ScaleWidth; }
+ set { mState.ScaleWidth = value; }
}
/// <summary>
/// Gets or sets the amount the height is scaled when this surface is drawn.
@@ -383,8 +400,8 @@
/// </summary>
public double ScaleHeight
{
- get { return impl.ScaleHeight; }
- set { impl.ScaleHeight = value; }
+ get { return mState.ScaleHeight; }
+ set { mState.ScaleHeight = value; }
}
/// <summary>
/// Sets the amount of scaling when this surface is drawn.
@@ -398,7 +415,8 @@
/// <param name="height"></param>
public void SetScale(double width, double height)
{
- impl.SetScale(width, height);
+ ScaleWidth = width;
+ ScaleHeight = height;
}
/// <summary>
/// Gets the amount of scaling when this surface is drawn.
@@ -412,7 +430,8 @@
/// <param name="height"></param>
public void GetScale(out double width, out double height)
{
- impl.GetScale(out width, out height);
+ width = mState.ScaleWidth;
+ height = mState.ScaleHeight;
}
@@ -424,25 +443,24 @@
/// </summary>
public Color Color
{
- get { return impl.Color; }
- set { impl.Color = value; }
+ get { return mState.Color; }
+ set { mState.Color = value; }
}
/// <summary>
/// Gets or sets the gradient for this surface.
/// </summary>
public Gradient ColorGradient
{
- get { return impl.ColorGradient; }
- set { impl.ColorGradient = value; }
+ get { return mState.ColorGradient; }
+ set { mState.ColorGradient = value; }
}
-
/// <summary>
/// Increments the rotation angle of this surface.
/// </summary>
/// <param name="radians">Value in radians to increase the rotation by.</param>
public void IncrementRotationAngle(double radians)
{
- impl.IncrementRotationAngle(radians);
+ mState.RotationAngle += radians;
}
/// <summary>
/// Increments the rotation angle of this surface. Value supplied is in degrees.
@@ -450,7 +468,7 @@
/// <param name="degrees"></param>
public void IncrementRotationAngleDegrees(double degrees)
{
- impl.IncrementRotationAngleDegrees(degrees);
+ mState.IncrementRotationAngleDegrees(degrees);
}
#endregion
@@ -474,7 +492,10 @@
/// <param name="destY"></param>
public void Draw(int destX, int destY)
{
- impl.Draw((float)destX, (float)destY);
+ mState.DrawInstances.SetCount(1);
+ mState.DrawInstances[0] = new SurfaceDrawInstance(new PointF(destX, destY));
+
+ impl.Draw(State);
}
/// <summary>
/// Draws this surface to the screen at the specified point,
@@ -485,7 +506,10 @@
/// <param name="destY"></param>
public void Draw(float destX, float destY)
{
- impl.Draw(destX, destY);
+ mState.DrawInstances.SetCount(1);
+ mState.DrawInstances[0] = new SurfaceDrawInstance(new PointF(destX, destY));
+
+ impl.Draw(State);
}
/// <summary>
/// Draws this surface to the screen at the specified point,
@@ -495,7 +519,7 @@
/// <param name="destPt"></param>
public void Draw(Point destPt)
{
- impl.Draw(destPt.X, destPt.Y);
+ Draw(destPt.X, destPt.Y);
}
/// <summary>
/// Draws this surface to the screen at the specified point,
@@ -505,7 +529,7 @@
/// <param name="destPt"></param>
public void Draw(Vector2 destPt)
{
- impl.Draw(destPt.X, destPt.Y);
+ Draw(destPt.X, destPt.Y);
}
/// <summary>
/// Draws this surface to the screen at the specified point,
@@ -515,7 +539,7 @@
/// <param name="destPt"></param>
public void Draw(PointF destPt)
{
- impl.Draw(destPt.X, destPt.Y);
+ Draw(destPt.X, destPt.Y);
}
/// <summary>
/// Draws this surface to the screen at the specified point,
@@ -529,7 +553,7 @@
/// to the top-left of the surface.</param>
public void Draw(PointF destPt, PointF rotationCenter)
{
- impl.Draw(destPt.X, destPt.Y, rotationCenter.X, rotationCenter.Y);
+ Draw(destPt, Rectangle.Empty, rotationCenter);
}
/// <summary>
/// Draws this surface to the screen at the specified point,
@@ -540,20 +564,33 @@
/// </summary>
public void Draw(float destX, float destY, float rotationCenterX, float rotationCenterY)
{
- impl.Draw(destX, destY, rotationCenterX, rotationCenterY);
+ Draw(new PointF(destX, destY), new PointF(rotationCenterX, rotationCenterY));
}
- /// <summary>
- /// Draws this surface to the screen at the specified point,
- /// using all the state information defined in the properties
- /// of this surface.
- /// Ignores the value of RotationCenter and uses the specified
- /// point to rotate around instead.
- /// </summary>
- public void Draw(float x, float y, Rectangle srcRect, float rotationCenterX, float rotationCenterY)
+ internal void Draw(PointF destPt, Rectangle srcRect, PointF rotationCenter)
{
- impl.Draw(x, y, srcRect, rotationCenterX, rotationCenterY);
+ OriginAlignment oldrotation = State.RotationCenter;
+ PointF oldcenter = State.RotationCenterLocation;
+
+ State.RotationCenter = OriginAlignment.Specified;
+ State.RotationCenterLocation = rotationCenter;
+
+ State.DrawInstances.SetCount(1);
+ State.DrawInstances[0] = new SurfaceDrawInstance(destPt, srcRect);
+
+ impl.Draw(State);
+
+ State.RotationCenterLocation = oldcenter;
+ State.RotationCenter = oldrotation;
}
+
+ public void Draw(SurfaceState state)
+ {
+ // TODO: fix this
+ impl.Draw(state);
+ }
+
+ SurfaceState rectState;
/// <summary>
/// Draws a portion of this surface to the specified destination
/// rectangle.
@@ -566,7 +603,22 @@
/// <param name="destRect"></param>
public void Draw(Rectangle srcRect, Rectangle destRect)
{
- impl.Draw(srcRect, destRect);
+ if (rectState == null)
+ rectState = State.Clone();
+ else
+ State.CopyTo(rectState, false);
+
+ rectState.RotationAngle = 0;
+ rectState.ScaleWidth = destRect.Width / (double)srcRect.Width;
+ rectState.ScaleHeight = destRect.Height / (double)srcRect.Height;
+
+ rectState.DrawInstances[0] = new SurfaceDrawInstance
+ {
+ SourceRect = srcRect,
+ DestLocation = new PointF(destRect.X, destRect.Y),
+ };
+
+ impl.Draw(rectState);
}
/// <summary>
@@ -580,9 +632,29 @@
/// <param name="destRect"></param>
public void Draw(Rectangle destRect)
{
- impl.Draw(destRect);
+ Draw(new Rectangle(0, 0, SurfaceWidth, SurfaceHeight), destRect);
}
+ void Draw(RectangleF srcRect, RectangleF destRect)
+ {
+ if (rectState == null)
+ rectState = State.Clone();
+ else
+ State.CopyTo(rectState, false);
+
+ rectState.RotationAngle = 0;
+ rectState.ScaleWidth = destRect.Width / (double)srcRect.Width;
+ rectState.ScaleHeight = destRect.Height / (double)srcRect.Height;
+
+ rectState.DrawInstances[0] = new SurfaceDrawInstance
+ {
+ SourceRect = Rectangle.Round(srcRect),
+ DestLocation = new PointF(destRect.X, destRect.Y),
+ };
+
+ impl.Draw(rectState);
+ }
+
/// <summary>
/// Draws the surface using an array of source and destination rectangles.
/// This method will throw an exception if the two arrays are not the same size.
@@ -596,7 +668,8 @@
throw new ArgumentException(
"Source and dest rect arrays are not the same size! Use overload which indicates length of arrays to use.");
}
- impl.DrawRects(srcRects, destRects, 0, srcRects.Length);
+
+ DrawRects(srcRects, destRects, 0, srcRects.Length);
}
/// <summary>
/// Draws the surface using an array of source and destination rectangles.
@@ -611,7 +684,8 @@
throw new ArgumentException(
"Source and dest rect arrays are not the same size! Use overload which indicates length of arrays to use.");
}
- impl.DrawRects(srcRects, destRects, 0, srcRects.Length);
+
+ DrawRects(srcRects, destRects, 0, srcRects.Length);
}
/// <summary>
@@ -624,7 +698,9 @@
/// <param name="length">Number of elements in the arrays to use.</param>
public void DrawRects(Rectangle[] srcRects, Rectangle[] destRects, int start, int length)
{
- impl.DrawRects(srcRects, destRects, start, length);
+ // TODO: optimize this
+ for (int i = start; i < length; i++)
+ Draw(srcRects[i], destRects[i]);
}
/// <summary>
/// Draws the surface using an array of source and destination rectangles.
@@ -636,7 +712,9 @@
/// <param name="length">Number of elements in the arrays to use.</param>
public void DrawRects(RectangleF[] srcRects, RectangleF[] destRects, int start, int length)
{
- impl.DrawRects(srcRects, destRects, start, length);
+ // TODO: optimize this
+ for (int i = start; i < length; i++)
+ Draw(srcRects[i], destRects[i]);
}
#endregion
@@ -863,5 +941,6 @@
#endregion
+
}
}
Added: trunk/AgateLib/DisplayLib/SurfaceState.cs
===================================================================
--- trunk/AgateLib/DisplayLib/SurfaceState.cs (rev 0)
+++ trunk/AgateLib/DisplayLib/SurfaceState.cs 2009-04-25 21:46:26 UTC (rev 917)
@@ -0,0 +1,265 @@
+// The contents of this file are subject to the Mozilla Public License
+// Version 1.1 (the "License"); you may not use this file except in
+// compliance with the License. You may obtain a copy of the License at
+// http://www.mozilla.org/MPL/
+//
+// Software distributed under the License is distributed on an "AS IS"
+// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+// License for the specific language governing rights and limitations
+// under the License.
+//
+// The Original Code is AgateLib.
+//
+// The Initial Developer of the Original Code is Erik Ylvisaker.
+// Portions created by Erik Ylvisaker are Copyright (C) 2006-2009.
+// All Rights Reserved.
+//
+// Contributor(s): Erik Ylvisaker
+//
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using AgateLib.Geometry;
+using AgateLib.DisplayLib.Cache;
+
+namespace AgateLib.DisplayLib
+{
+ public class SurfaceState
+ {
+ private SurfaceStateCache mCache;
+ private double mScaleWidth = 1.0;
+ private double mScaleHeight = 1.0;
+ private OriginAlignment mAlignment = OriginAlignment.TopLeft;
+ private double mRotation = 0;
+ private OriginAlignment mRotationSpot = OriginAlignment.Center;
+ private PointF mRotationCenter = new PointF();
+ private Gradient mGradient = new Gradient(Color.White);
+ private DrawInstanceList mDrawInstances = new DrawInstanceList();
+
+ public SurfaceState()
+ {
+ mDrawInstances.Add(new SurfaceDrawInstance());
+ }
+ public SurfaceState Clone()
+ {
+ SurfaceState retval = new SurfaceState();
+ CopyTo(retval, true);
+
+ return retval;
+ }
+ public void CopyTo(SurfaceState target, bool copyDrawInstances)
+ {
+ target.ScaleWidth = mScaleWidth;
+ target.ScaleHeight = mScaleHeight;
+ target.DisplayAlignment = mAlignment;
+ target.RotationAngle = mRotation;
+ target.RotationCenter = mRotationSpot;
+ target.ColorGradient = mGradient;
+
+ if (copyDrawInstances)
+ {
+ target.mDrawInstances.Clear();
+ target.mDrawInstances.Capacity = mDrawInstances.Count;
+ target.mDrawInstances.AddRange(mDrawInstances);
+ }
+ }
+
+ /// <summary>
+ /// Location the surface will be drawn.
+ /// </summary>
+ public DrawInstanceList DrawInstances
+ {
+ get { return mDrawInstances; }
+ set { mDrawInstances = value; }
+ }
+
+ /// <summary>
+ /// Alpha value for displaying this surface.
+ /// Valid values range from 0.0 (completely transparent) to 1.0 (completely opaque).
+ /// Internally stored as a byte, so granularity is only 1/255.0.
+ /// If a gradient is used, getting this property returns the alpha value for the top left
+ /// corner of the gradient.
+ /// </summary>
+ public double Alpha
+ {
+ get { return Color.A / 255.0; }
+ set
+ {
+ mGradient.SetAlpha(value);
+ }
+ }
+ /// <summary>
+ /// Gets or sets the rotation angle in radians.
+ /// Positive angles indicate rotation in the Counter-Clockwise direction.
+ /// </summary>
+ public double RotationAngle
+ {
+ get { return mRotation; }
+ set { mRotation = value % (2 * Math.PI); }
+ }
+ /// <summary>
+ /// Gets or sets the rotation angle in degrees.
+ /// Positive angles indicate rotation in the Counter-Clockwise direction.
+ /// </summary>
+ public double RotationAngleDegrees
+ {
+ get { return RotationAngle * 180.0 / Math.PI; }
+ set { RotationAngle = value * Math.PI / 180.0; }
+ }
+ /// <summary>
+ /// Gets or sets the point on the surface which is used to rotate around.
+ /// </summary>
+ public OriginAlignment RotationCenter
+ {
+ get { return mRotationSpot; }
+ set { mRotationSpot = value; }
+ }
+ /// <summary>
+ /// Specifies the point in screen space the surface is rotated around. This value
+ /// is only used if RotationCenter is set to OriginAlignment.Specified. Setting this
+ /// value will set the RotationCenter to OriginAlignment.Specified.
+ /// </summary>
+ public PointF RotationCenterLocation
+ {
+ get { return mRotationCenter; }
+ set
+ {
+ mRotationSpot = OriginAlignment.Specified;
+ mRotationCenter = value;
+ }
+ }
+ /// <summary>
+ /// Gets or sets the point where the surface is aligned to when drawn.
+ /// </summary>
+ public OriginAlignment DisplayAlignment
+ {
+ get { return mAlignment; }
+ set { mAlignment = value; }
+ }
+
+ /// <summary>
+ /// Gets or sets the amount the width is scaled when this surface is drawn.
+ /// 1.0 is no scaling.
+ /// Scale values can be negative, this causes the surface to be mirrored
+ /// in that direction. This does not affect how the surface is aligned;
+ /// eg. if DisplayAlignment is top-left and ScaleWidth < 0, the surface
+ /// will still be drawn to the right of the point supplied to Draw(Point).
+ /// </summary>
+ public double ScaleWidth
+ {
+ get { return mScaleWidth; }
+ set { mScaleWidth = value; }
+ }
+ /// <summary>
+ /// Gets or sets the amount the height is scaled when this surface is drawn.
+ /// 1.0 is no scaling.
+ /// </summary>
+ public double ScaleHeight
+ {
+ get { return mScaleHeight; }
+ set { mScaleHeight = value; }
+ }
+
+ /// <summary>
+ /// Gets or sets the multiplicative color for this surface.
+ /// Setting this is equivalent to setting the ColorGradient property
+ /// with a gradient with the same color in all corners. If a gradient
+ /// is being used, getting this property returns the top-left color in the gradient.
+ /// </summary>
+ public Color Color
+ {
+ get { return mGradient.TopLeft; }
+ set { mGradient = new Gradient(value); }
+ }
+ /// <summary>
+ /// Gets or sets the gradient for this surface.
+ /// </summary>
+ public Gradient ColorGradient
+ {
+ get { return mGradient; }
+ set { mGradient = value; }
+ }
+
+ /// <summary>
+ /// Increments the rotation angle of this surface. Value supplied is in degrees.
+ /// </summary>
+ /// <param name="degrees"></param>
+ public void IncrementRotationAngleDegrees(double degrees)
+ {
+ mRotation += degrees * Math.PI / 180.0;
+ }
+
+ /// <summary>
+ /// The cache is used by the display implementation to store data to improve performance
+ /// when drawing with this state object. Do not set this value unless you are writing
+ /// a driver or otherwise know what you are doing.
+ /// </summary>
+ public SurfaceStateCache Cache
+ {
+ get { return mCache; }
+ set { mCache = value; }
+ }
+
+ public SizeF GetDisplaySize(Size surfaceSize)
+ {
+ return new SizeF(
+ (float)ScaleWidth * surfaceSize.Width,
+ (float)ScaleHeight * surfaceSize.Height);
+ }
+ public PointF GetRotationCenter(SizeF displaySize)
+ {
+ if (RotationCenter == OriginAlignment.Specified)
+ return RotationCenterLocation;
+ else
+ return Origin.CalcF(RotationCenter, displaySize);
+ }
+ }
+
+ public struct SurfaceDrawInstance
+ {
+ public SurfaceDrawInstance(PointF location) : this()
+ {
+ DestLocation = location;
+ }
+ public SurfaceDrawInstance(PointF location, Rectangle sourceRect) : this()
+ {
+ DestLocation = location;
+ SourceRect = sourceRect;
+ }
+
+ public PointF DestLocation { get; set; }
+ /// <summary>
+ /// If SourceRect is empty (all values are zero), then it is ignored.
+ /// </summary>
+ public Rectangle SourceRect { get; set; }
+
+ /// <summary>
+ /// Gets the actual source rectangle that should be used when drawing from the surface.
+ /// </summary>
+ /// <param name="surfaceSize"></param>
+ /// <returns></returns>
+ public Rectangle GetSourceRect(Size surfaceSize)
+ {
+ if (SourceRect == Rectangle.Empty)
+ return new Rectangle(Point.Empty, surfaceSize);
+ else
+ return SourceRect;
+ }
+ }
+
+ public class DrawInstanceList : List<SurfaceDrawInstance>
+ {
+ public void SetCount(int newCount)
+ {
+ if (Count == newCount)
+ return;
+
+ while (Count < newCount)
+ Add(new SurfaceDrawInstance());
+
+ if (Count > newCount)
+ RemoveRange(newCount, Count - newCount);
+ }
+ }
+}
Added: trunk/AgateLib/DisplayLib/TextLayout.cs
===================================================================
--- trunk/AgateLib/DisplayLib/TextLayout.cs (rev 0)
+++ trunk/AgateLib/DisplayLib/TextLayout.cs 2009-04-25 21:46:26 UTC (rev 917)
@@ -0,0 +1,138 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using AgateLib.Geometry;
+
+namespace AgateLib.DisplayLib
+{
+ public class TextLayout : List<LayoutItem>
+ {
+ public void DrawAll()
+ {
+ foreach (LayoutItem item in this)
+ {
+ item.Draw();
+ }
+ }
+
+ public void Translate(Point dist)
+ {
+ foreach (LayoutItem item in this)
+ {
+ item.Location = new PointF(
+ item.Location.X + dist.X,
+ item.Location.Y + dist.Y);
+ }
+ }
+ }
+
+ public abstract class LayoutItem
+ {
+ public abstract void Draw();
+ public abstract PointF Location { get; set; }
+ public float X
+ {
+ get { return Location.X; }
+ set { Location = new PointF(value, Location.Y); }
+ }
+ public float Y
+ {
+ get { return Location.Y; }
+ set { Location = new PointF(Location.X, value); }
+ }
+ public int LineIndex { get; set; }
+ }
+
+ public class LayoutText : LayoutItem
+ {
+ public FontSu...
[truncated message content] |
|
From: <ka...@us...> - 2009-04-25 19:59:07
|
Revision: 916
http://agate.svn.sourceforge.net/agate/?rev=916&view=rev
Author: kanato
Date: 2009-04-25 19:58:56 +0000 (Sat, 25 Apr 2009)
Log Message:
-----------
Update formatting to use tabs instead of spaces.
Modified Paths:
--------------
branches/font/AgateLib/BitmapFont/BitmapFontImpl.cs
branches/font/AgateLib/BitmapFont/BitmapFontOptions.cs
branches/font/AgateLib/DisplayLib/ISprite.cs
branches/font/AgateLib/DisplayLib/ISurface.cs
branches/font/AgateLib/DisplayLib/OriginAlignment.cs
branches/font/AgateLib/DisplayLib/Surface.cs
branches/font/AgateLib/Geometry/Rectangle.cs
branches/font/AgateLib/Sprites/Sprite.cs
branches/font/AgateLib/Sprites/SpriteFrame.cs
branches/font/Drivers/AgateDrawing/Drawing_FontSurface.cs
branches/font/Drivers/AgateDrawing/Drawing_Surface.cs
branches/font/Drivers/AgateMDX/MDX1_FontSurface.cs
branches/font/Drivers/AgateMDX/MDX1_Surface.cs
branches/font/Drivers/AgateOTK/GL_Surface.cs
Modified: branches/font/AgateLib/BitmapFont/BitmapFontImpl.cs
===================================================================
--- branches/font/AgateLib/BitmapFont/BitmapFontImpl.cs 2009-04-25 19:43:50 UTC (rev 915)
+++ branches/font/AgateLib/BitmapFont/BitmapFontImpl.cs 2009-04-25 19:58:56 UTC (rev 916)
@@ -331,7 +331,7 @@
if (state.DisplayAlignment != OriginAlignment.TopLeft)
{
- Point value = Origin.Calc(state.DisplayAlignment,
+ Point value = Origin.Calc(state.DisplayAlignment,
StringDisplaySize(state, state.Text));
dest.X -= value.X;
Modified: branches/font/AgateLib/BitmapFont/BitmapFontOptions.cs
===================================================================
--- branches/font/AgateLib/BitmapFont/BitmapFontOptions.cs 2009-04-25 19:43:50 UTC (rev 915)
+++ branches/font/AgateLib/BitmapFont/BitmapFontOptions.cs 2009-04-25 19:58:56 UTC (rev 916)
@@ -25,253 +25,253 @@
namespace AgateLib.BitmapFont
{
- /// <summary>
- /// Class which indicates how a bitmap font should be generated
- /// from an operating system font.
- /// </summary>
- public class BitmapFontOptions
- {
- /// <summary>
- /// Class which represents a range of characters
- /// </summary>
- public class CharacterRange
- {
- private char mStartChar;
- private char mEndChar;
+ /// <summary>
+ /// Class which indicates how a bitmap font should be generated
+ /// from an operating system font.
+ /// </summary>
+ public class BitmapFontOptions
+ {
+ /// <summary>
+ /// Class which represents a range of characters
+ /// </summary>
+ public class CharacterRange
+ {
+ private char mStartChar;
+ private char mEndChar;
- /// <summary>
- /// Constructs a character range.
- /// </summary>
- /// <param name="startChar"></param>
- /// <param name="endChar"></param>
- public CharacterRange(char startChar, char endChar)
- {
- if (mEndChar < mStartChar)
- throw new ArgumentException("endChar must not be less than startChar.");
+ /// <summary>
+ /// Constructs a character range.
+ /// </summary>
+ /// <param name="startChar"></param>
+ /// <param name="endChar"></param>
+ public CharacterRange(char startChar, char endChar)
+ {
+ if (mEndChar < mStartChar)
+ throw new ArgumentException("endChar must not be less than startChar.");
- mStartChar = startChar;
- mEndChar = endChar;
- }
+ mStartChar = startChar;
+ mEndChar = endChar;
+ }
- /// <summary>
- /// Last char in the range.
- /// </summary>
- public char EndChar
- {
- get { return mEndChar; }
- set
- {
- mEndChar = value;
+ /// <summary>
+ /// Last char in the range.
+ /// </summary>
+ public char EndChar
+ {
+ get { return mEndChar; }
+ set
+ {
+ mEndChar = value;
- if (value < mStartChar)
- throw new ArgumentException("EndChar must be less than StartChar.");
- }
- }
- /// <summary>
- /// First char in the range.
- /// </summary>
- public char StartChar
- {
- get { return mStartChar; }
- set
- {
- mStartChar = value;
+ if (value < mStartChar)
+ throw new ArgumentException("EndChar must be less than StartChar.");
+ }
+ }
+ /// <summary>
+ /// First char in the range.
+ /// </summary>
+ public char StartChar
+ {
+ get { return mStartChar; }
+ set
+ {
+ mStartChar = value;
- if (mStartChar > mEndChar)
- mEndChar = mStartChar;
- }
- }
+ if (mStartChar > mEndChar)
+ mEndChar = mStartChar;
+ }
+ }
- }
+ }
- private string mFamily;
- private float mSize;
- private FontStyle mStyle;
- private bool mUseTextRenderer = true;
- private bool mCreateBorder;
- private Color mBorderColor = Color.FromArgb(128, Color.Black);
- private BitmapFontEdgeOptions mEdgeOptions;
- private List<CharacterRange> mRanges = new List<CharacterRange>();
+ private string mFamily;
+ private float mSize;
+ private FontStyle mStyle;
+ private bool mUseTextRenderer = true;
+ private bool mCreateBorder;
+ private Color mBorderColor = Color.FromArgb(128, Color.Black);
+ private BitmapFontEdgeOptions mEdgeOptions;
+ private List<CharacterRange> mRanges = new List<CharacterRange>();
- /// <summary>
- /// Constructs a BitmapFontOptions object using a 10-point sans serif font.
- /// </summary>
- public BitmapFontOptions()
- : this("Sans Serif", 14.0f)
- {
- }
- /// <summary>
- /// Constructs a BitmapFontOptions object.
- /// </summary>
- /// <param name="fontFamily"></param>
- /// <param name="sizeInPoints"></param>
- public BitmapFontOptions(string fontFamily, float sizeInPoints)
- {
- mFamily = fontFamily;
- mSize = sizeInPoints;
- mEdgeOptions = BitmapFontEdgeOptions.IntensityAlphaColor;
+ /// <summary>
+ /// Constructs a BitmapFontOptions object using a 10-point sans serif font.
+ /// </summary>
+ public BitmapFontOptions()
+ : this("Sans Serif", 14.0f)
+ {
+ }
+ /// <summary>
+ /// Constructs a BitmapFontOptions object.
+ /// </summary>
+ /// <param name="fontFamily"></param>
+ /// <param name="sizeInPoints"></param>
+ public BitmapFontOptions(string fontFamily, float sizeInPoints)
+ {
+ mFamily = fontFamily;
+ mSize = sizeInPoints;
+ mEdgeOptions = BitmapFontEdgeOptions.IntensityAlphaColor;
- // Latin characters used by English.
- mRanges.Add(new CharacterRange(' ', '~'));
+ // Latin characters used by English.
+ mRanges.Add(new CharacterRange(' ', '~'));
- // Latin characters used by languages other than English.
- mRanges.Add(new CharacterRange((char)0xA1, (char)0xFF));
- }
+ // Latin characters used by languages other than English.
+ mRanges.Add(new CharacterRange((char)0xA1, (char)0xFF));
+ }
- /// <summary>
- /// Constructs a BitmapFontOptions object.
- /// </summary>
- /// <param name="fontFamily"></param>
- /// <param name="sizeInPoints"></param>
- /// <param name="style"></param>
- public BitmapFontOptions(string fontFamily, float sizeInPoints, FontStyle style)
- : this(fontFamily, sizeInPoints)
- {
- mStyle = style;
- }
+ /// <summary>
+ /// Constructs a BitmapFontOptions object.
+ /// </summary>
+ /// <param name="fontFamily"></param>
+ /// <param name="sizeInPoints"></param>
+ /// <param name="style"></param>
+ public BitmapFontOptions(string fontFamily, float sizeInPoints, FontStyle style)
+ : this(fontFamily, sizeInPoints)
+ {
+ mStyle = style;
+ }
- /// <summary>
- /// Adds a range of characters to be rendered.
- /// </summary>
- /// <param name="start"></param>
- /// <param name="end"></param>
- public void AddRange(char start, char end)
- {
- try
- {
- for (int i = 0; i < mRanges.Count; i++)
- {
- if (mRanges[i].StartChar < end)
- {
- mRanges[i].StartChar = start;
- return;
- }
- else if (mRanges[i].EndChar > start)
- {
- mRanges[i].EndChar = end;
- return;
- }
- }
+ /// <summary>
+ /// Adds a range of characters to be rendered.
+ /// </summary>
+ /// <param name="start"></param>
+ /// <param name="end"></param>
+ public void AddRange(char start, char end)
+ {
+ try
+ {
+ for (int i = 0; i < mRanges.Count; i++)
+ {
+ if (mRanges[i].StartChar < end)
+ {
+ mRanges[i].StartChar = start;
+ return;
+ }
+ else if (mRanges[i].EndChar > start)
+ {
+ mRanges[i].EndChar = end;
+ return;
+ }
+ }
- mRanges.Add(new CharacterRange(start, end));
- }
- finally
- {
- ConsolidateRanges();
- }
- }
+ mRanges.Add(new CharacterRange(start, end));
+ }
+ finally
+ {
+ ConsolidateRanges();
+ }
+ }
- private void ConsolidateRanges()
- {
- SortRanges();
+ private void ConsolidateRanges()
+ {
+ SortRanges();
- for (int i = 0; i < mRanges.Count - 1; i++)
- {
- while (mRanges[i].EndChar > mRanges[i + 1].StartChar)
- {
- mRanges[i].EndChar = mRanges[i + 1].EndChar;
+ for (int i = 0; i < mRanges.Count - 1; i++)
+ {
+ while (mRanges[i].EndChar > mRanges[i + 1].StartChar)
+ {
+ mRanges[i].EndChar = mRanges[i + 1].EndChar;
- mRanges.RemoveAt(i + 1);
- i--;
- }
- }
- }
- private void SortRanges()
- {
- mRanges.Sort(
- delegate(CharacterRange x, CharacterRange y)
- {
- return x.StartChar.CompareTo(y.StartChar);
- });
- }
+ mRanges.RemoveAt(i + 1);
+ i--;
+ }
+ }
+ }
+ private void SortRanges()
+ {
+ mRanges.Sort(
+ delegate(CharacterRange x, CharacterRange y)
+ {
+ return x.StartChar.CompareTo(y.StartChar);
+ });
+ }
- /// <summary>
- /// Enumerates the character ranges to be rendered.
- /// </summary>
- public IEnumerable<CharacterRange> CharacterRanges
- {
- get { return mRanges; }
- }
+ /// <summary>
+ /// Enumerates the character ranges to be rendered.
+ /// </summary>
+ public IEnumerable<CharacterRange> CharacterRanges
+ {
+ get { return mRanges; }
+ }
- /// <summary>
- /// Gets the total number of characters to be rendered to the bitmap.
- /// </summary>
- public int TotalChars
- {
- get
- {
- int retval = 0;
+ /// <summary>
+ /// Gets the total number of characters to be rendered to the bitmap.
+ /// </summary>
+ public int TotalChars
+ {
+ get
+ {
+ int retval = 0;
- for (int i = 0; i < mRanges.Count; i++)
- retval += (int)(mRanges[i].EndChar - mRanges[i].StartChar + 1);
+ for (int i = 0; i < mRanges.Count; i++)
+ retval += (int)(mRanges[i].EndChar - mRanges[i].StartChar + 1);
- return retval;
- }
- }
+ return retval;
+ }
+ }
- /// <summary>
- /// Indicates how to treat font edges.
- /// </summary>
- public BitmapFontEdgeOptions EdgeOptions
- {
- get { return mEdgeOptions; }
- set { mEdgeOptions = value; }
- }
- /// <summary>
- /// Indicates whether to use System.Windows.Forms.TextRenderer instead of
- /// System.Drawing.Graphics. TextRenderer on Windows will likely produce
- /// nicer-looking characters than Graphics, but it is much slower rendering
- /// the characters.
- /// </summary>
- public bool UseTextRenderer
- {
- get { return mUseTextRenderer; }
- set { mUseTextRenderer = value; }
- }
+ /// <summary>
+ /// Indicates how to treat font edges.
+ /// </summary>
+ public BitmapFontEdgeOptions EdgeOptions
+ {
+ get { return mEdgeOptions; }
+ set { mEdgeOptions = value; }
+ }
+ /// <summary>
+ /// Indicates whether to use System.Windows.Forms.TextRenderer instead of
+ /// System.Drawing.Graphics. TextRenderer on Windows will likely produce
+ /// nicer-looking characters than Graphics, but it is much slower rendering
+ /// the characters.
+ /// </summary>
+ public bool UseTextRenderer
+ {
+ get { return mUseTextRenderer; }
+ set { mUseTextRenderer = value; }
+ }
- /// <summary>
- /// Style of the font to be generated.
- /// </summary>
- public FontStyle FontStyle
- {
- get { return mStyle; }
- set { mStyle = value; }
- }
- /// <summary>
- /// Size of the font in points.
- /// </summary>
- public float SizeInPoints
- {
- get { return mSize; }
- set { mSize = value; }
- }
- /// <summary>
- /// Name of the font family.
- /// </summary>
- public string FontFamily
- {
- get { return mFamily; }
- set { mFamily = value; }
- }
- /// <summary>
- /// Color of the border on the glyphs. Colors
- /// other than black may show up correctly when drawing
- /// colored text.
- /// </summary>
- public Color BorderColor
- {
- get { return mBorderColor; }
- set { mBorderColor = value; }
- }
- /// <summary>
- /// Indicates whether to create a border around the glyphs.
- /// </summary>
- public bool CreateBorder
- {
- get { return mCreateBorder; }
- set { mCreateBorder = value; }
- }
+ /// <summary>
+ /// Style of the font to be generated.
+ /// </summary>
+ public FontStyle FontStyle
+ {
+ get { return mStyle; }
+ set { mStyle = value; }
+ }
+ /// <summary>
+ /// Size of the font in points.
+ /// </summary>
+ public float SizeInPoints
+ {
+ get { return mSize; }
+ set { mSize = value; }
+ }
+ /// <summary>
+ /// Name of the font family.
+ /// </summary>
+ public string FontFamily
+ {
+ get { return mFamily; }
+ set { mFamily = value; }
+ }
+ /// <summary>
+ /// Color of the border on the glyphs. Colors
+ /// other than black may show up correctly when drawing
+ /// colored text.
+ /// </summary>
+ public Color BorderColor
+ {
+ get { return mBorderColor; }
+ set { mBorderColor = value; }
+ }
+ /// <summary>
+ /// Indicates whether to create a border around the glyphs.
+ /// </summary>
+ public bool CreateBorder
+ {
+ get { return mCreateBorder; }
+ set { mCreateBorder = value; }
+ }
- }
+ }
}
Modified: branches/font/AgateLib/DisplayLib/ISprite.cs
===================================================================
--- branches/font/AgateLib/DisplayLib/ISprite.cs 2009-04-25 19:43:50 UTC (rev 915)
+++ branches/font/AgateLib/DisplayLib/ISprite.cs 2009-04-25 19:58:56 UTC (rev 916)
@@ -22,152 +22,152 @@
namespace AgateLib.DisplayLib
{
-
- /// <summary>
- /// Basic interface implemented by different sprite classes.
- /// </summary>
- public interface ISprite : ISurface, IDisposable
- {
- /// <summary>
- /// Shows the next frame in the sequence. This pays attention
- /// to whether the animation is playing forwards or reverse.
- /// </summary>
- void AdvanceFrame();
- /// <summary>
- /// Updates the animation of the sprite, using the DeltaTime given
- /// by the Display object.
- /// </summary>
- void Update();
- /// <summary>
- /// Updates the animation of the sprite, using the given frame time.
- /// </summary>
- /// <param name="time_ms">The amount of time to consider passed, in milliseconds.</param>
- void Update(double time_ms);
+ /// <summary>
+ /// Basic interface implemented by different sprite classes.
+ /// </summary>
+ public interface ISprite : ISurface, IDisposable
+ {
+ /// <summary>
+ /// Shows the next frame in the sequence. This pays attention
+ /// to whether the animation is playing forwards or reverse.
+ /// </summary>
+ void AdvanceFrame();
- /// <summary>
- /// Gets or sets an enum value indicating what type of animation is happening.
- /// Looping - The animation will play from beginning to end and then restart.
- /// PingPong - The animation will play from beginning to end and then from end to beginning (continuously).
- /// Once - The animation plays once, and then shows its first frame.
- /// OnceHoldLast - The animation plays once, and leaves the last frame on.
- /// </summary>
- SpriteAnimType AnimationType { get; set; }
- /// <summary>
- /// Gets the currently displaying frame.
- /// </summary>
- ISpriteFrame CurrentFrame { get; }
- /// <summary>
- /// The index of the current frame.
- /// </summary>
- int CurrentFrameIndex { get; set; }
- /// <summary>
- /// Gets or sets a flag which indicates:
- /// True if the animation is running.
- /// False if a single frame will be shown indefinitely.
- /// </summary>
- bool IsAnimating { get; set; }
- /// <summary>
- /// Gets or sets a flag which indicates whether or not this animation plays in
- /// reverse instead.
- /// </summary>
- bool PlayReverse { get; set; }
+ /// <summary>
+ /// Updates the animation of the sprite, using the DeltaTime given
+ /// by the Display object.
+ /// </summary>
+ void Update();
+ /// <summary>
+ /// Updates the animation of the sprite, using the given frame time.
+ /// </summary>
+ /// <param name="time_ms">The amount of time to consider passed, in milliseconds.</param>
+ void Update(double time_ms);
- /// <summary>
- /// Gets height of the sprite.
- /// </summary>
- int SpriteHeight { get; }
- /// <summary>
- /// Gets the size of the sprite.
- /// </summary>
- Size SpriteSize { get; }
- /// <summary>
- /// Gets width of the sprite.
- /// </summary>
- int SpriteWidth { get; }
- /// <summary>
- /// Restarts the animation.
- /// </summary>
- void StartAnimation();
+ /// <summary>
+ /// Gets or sets an enum value indicating what type of animation is happening.
+ /// Looping - The animation will play from beginning to end and then restart.
+ /// PingPong - The animation will play from beginning to end and then from end to beginning (continuously).
+ /// Once - The animation plays once, and then shows its first frame.
+ /// OnceHoldLast - The animation plays once, and leaves the last frame on.
+ /// </summary>
+ SpriteAnimType AnimationType { get; set; }
+ /// <summary>
+ /// Gets the currently displaying frame.
+ /// </summary>
+ ISpriteFrame CurrentFrame { get; }
+ /// <summary>
+ /// The index of the current frame.
+ /// </summary>
+ int CurrentFrameIndex { get; set; }
+ /// <summary>
+ /// Gets or sets a flag which indicates:
+ /// True if the animation is running.
+ /// False if a single frame will be shown indefinitely.
+ /// </summary>
+ bool IsAnimating { get; set; }
+ /// <summary>
+ /// Gets or sets a flag which indicates whether or not this animation plays in
+ /// reverse instead.
+ /// </summary>
+ bool PlayReverse { get; set; }
- /// <summary>
- /// Gets the list of SpriteFrame objects in this sprite.
- /// </summary>
- Sprites.IFrameList Frames { get; }
+ /// <summary>
+ /// Gets height of the sprite.
+ /// </summary>
+ int SpriteHeight { get; }
+ /// <summary>
+ /// Gets the size of the sprite.
+ /// </summary>
+ Size SpriteSize { get; }
+ /// <summary>
+ /// Gets width of the sprite.
+ /// </summary>
+ int SpriteWidth { get; }
+ /// <summary>
+ /// Restarts the animation.
+ /// </summary>
+ void StartAnimation();
- /// <summary>
- /// The amount of time each frame should display, in milliseconds.
- /// </summary>
- double TimePerFrame { get; set; }
- /// <summary>
- /// If Visible is set to false, all calls to Draw overloads are ignored.
- /// </summary>
- bool Visible { get; set; }
+ /// <summary>
+ /// Gets the list of SpriteFrame objects in this sprite.
+ /// </summary>
+ Sprites.IFrameList Frames { get; }
+ /// <summary>
+ /// The amount of time each frame should display, in milliseconds.
+ /// </summary>
+ double TimePerFrame { get; set; }
+ /// <summary>
+ /// If Visible is set to false, all calls to Draw overloads are ignored.
+ /// </summary>
+ bool Visible { get; set; }
- /// <summary>
- /// Event which is raised when the animation is started.
- /// </summary>
- event SpriteEventHandler AnimationStarted;
- /// <summary>
- /// Event which is raised when the animation is stopped.
- /// </summary>
- event SpriteEventHandler AnimationStopped;
- /// <summary>
- /// Event which is raised when the play direction is changed, as
- /// in the PingPong type.
- /// </summary>
- event SpriteEventHandler PlayDirectionChanged;
- }
+ /// <summary>
+ /// Event which is raised when the animation is started.
+ /// </summary>
+ event SpriteEventHandler AnimationStarted;
- /// <summary>
- /// Event handler type for sprite events.
- /// </summary>
- /// <param name="caller"></param>
- public delegate void SpriteEventHandler(ISprite caller);
+ /// <summary>
+ /// Event which is raised when the animation is stopped.
+ /// </summary>
+ event SpriteEventHandler AnimationStopped;
+ /// <summary>
+ /// Event which is raised when the play direction is changed, as
+ /// in the PingPong type.
+ /// </summary>
+ event SpriteEventHandler PlayDirectionChanged;
+ }
- /// <summary>
- /// Enum indicating the different types of automatic animation that
- /// take place.
- /// </summary>
- public enum SpriteAnimType
- {
- /// <summary>
- /// Specifies that the sprite animation should go from
- /// frame 0 to the end, and start back at frame 0 to repeat.
- /// </summary>
- Looping,
- /// <summary>
- /// Specifies that the sprite animation should go from
- /// frame 0 to the end, and then go back down to frame 0. This
- /// cycle repeats indefinitely.
- /// </summary>
- PingPong,
- /// <summary>
- /// Specifies that the sprite animation should go from
- /// frame 0 to the end and stop, but show frame 0 once the animation
- /// is finished.
- /// </summary>
- Once,
- /// <summary>
- /// Specifies that the sprite animation should go from
- /// frame 0 to the end and stop there, with the last frame
- /// shown.
- /// </summary>
- OnceHoldLast,
- /// <summary>
- /// Specifies that the sprite animation should go from
- /// frame 0 to the end, and then disappear. The Visible
- /// property of the Sprite object is set to false once
- /// the animation is complete.
- /// </summary>
- OnceDisappear,
+ /// <summary>
+ /// Event handler type for sprite events.
+ /// </summary>
+ /// <param name="caller"></param>
+ public delegate void SpriteEventHandler(ISprite caller);
- /// <summary>
- /// Specifies that the sprite animation should go twice.
- /// </summary>
- Twice,
- }
+ /// <summary>
+ /// Enum indicating the different types of automatic animation that
+ /// take place.
+ /// </summary>
+ public enum SpriteAnimType
+ {
+ /// <summary>
+ /// Specifies that the sprite animation should go from
+ /// frame 0 to the end, and start back at frame 0 to repeat.
+ /// </summary>
+ Looping,
+ /// <summary>
+ /// Specifies that the sprite animation should go from
+ /// frame 0 to the end, and then go back down to frame 0. This
+ /// cycle repeats indefinitely.
+ /// </summary>
+ PingPong,
+ /// <summary>
+ /// Specifies that the sprite animation should go from
+ /// frame 0 to the end and stop, but show frame 0 once the animation
+ /// is finished.
+ /// </summary>
+ Once,
+ /// <summary>
+ /// Specifies that the sprite animation should go from
+ /// frame 0 to the end and stop there, with the last frame
+ /// shown.
+ /// </summary>
+ OnceHoldLast,
+ /// <summary>
+ /// Specifies that the sprite animation should go from
+ /// frame 0 to the end, and then disappear. The Visible
+ /// property of the Sprite object is set to false once
+ /// the animation is complete.
+ /// </summary>
+ OnceDisappear,
+ /// <summary>
+ /// Specifies that the sprite animation should go twice.
+ /// </summary>
+ Twice,
+ }
+
}
Modified: branches/font/AgateLib/DisplayLib/ISurface.cs
===================================================================
--- branches/font/AgateLib/DisplayLib/ISurface.cs 2009-04-25 19:43:50 UTC (rev 915)
+++ branches/font/AgateLib/DisplayLib/ISurface.cs 2009-04-25 19:58:56 UTC (rev 916)
@@ -21,122 +21,122 @@
namespace AgateLib.DisplayLib
{
- /// <summary>
- /// Public Surface interface.
- /// </summary>
- public interface ISurface : IDisposable
- {
- /// <summary>
- /// Gets or sets the alpha value for the surface.
- /// 0.0 is completely transparent and 1.0 is completely opaque.
- /// </summary>
- double Alpha { get; set; }
- /// <summary>
- /// Gets or sets the color the surface is multiplied by when drawn.
- /// Setting this value overwrites the Alpha value.
- /// </summary>
- Color Color { get; set; }
- /// <summary>
- /// Gets or sets a color gradient used for this surface.
- /// </summary>
- Gradient ColorGradient { get; set; }
- /// <summary>
- /// Gets or sets how coordinate arguments to Draw overloads are interpreted.
- /// </summary>
- OriginAlignment DisplayAlignment { get; set; }
- /// <summary>
- /// Gets or sets the display height of the surface, in pixels.
- /// </summary>
- int DisplayHeight { get; set; }
- /// <summary>
- /// Gets or sets the display size of the surface, in pixels.
- /// </summary>
- Size DisplaySize { get; set; }
- /// <summary>
- /// Gets or sets the display width of the surface, in pixels.
- /// </summary>
- int DisplayWidth { get; set; }
- /// <summary>
- /// Draws the surface at the specified point.
- /// </summary>
- /// <param name="destPt"></param>
- void Draw(Point destPt);
- /// <summary>
- /// Draws the surface at the specified point.
- /// </summary>
- /// <param name="destPt"></param>
- void Draw(PointF destPt);
- /// <summary>
- /// Draws the surface at the specified point.
- /// </summary>
- /// <param name="destX"></param>
- /// <param name="destY"></param>
- void Draw(int destX, int destY);
- /// <summary>
- /// Draws the surface at the specified point.
- /// </summary>
- /// <param name="destX"></param>
- /// <param name="destY"></param>
- void Draw(float destX, float destY);
- /// <summary>
- /// Gets the current scale values.
- /// </summary>
- /// <param name="width"></param>
- /// <param name="height"></param>
- void GetScale(out double width, out double height);
- /// <summary>
- /// Increases the rotation angle.
- /// </summary>
- /// <param name="radians"></param>
- void IncrementRotationAngle(double radians);
- /// <summary>
- /// Increases the rotation angle.
- /// </summary>
- /// <param name="degrees"></param>
- void IncrementRotationAngleDegrees(double degrees);
- /// <summary>
- /// The amount the surface is rotated when drawn. The angle is measured
- /// up from the horizontal axis.
- /// </summary>
- double RotationAngle { get; set; }
- /// <summary>
- /// The amount the surface is rotated when drawn. The angle is measured
- /// up from the horizontal axis.
- /// </summary>
- double RotationAngleDegrees { get; set; }
- /// <summary>
- /// The point where the surface is rotated around when drawn.
- /// </summary>
- OriginAlignment RotationCenter { get; set; }
- /// <summary>
- /// The amount the height of the surface is scaled when drawn. 1.0 is no scaling.
- /// </summary>
- double ScaleHeight { get; set; }
- /// <summary>
- /// The amount the width of the surface is scaled when drawn. 1.0 is no scaling.
- /// </summary>
- double ScaleWidth { get; set; }
- /// <summary>
- /// Sets the width and height scale values simultaneously.
- /// </summary>
- /// <param name="width"></param>
- /// <param name="height"></param>
- void SetScale(double width, double height);
- /// <summary>
- /// Gets the height of the surface data in pixels.
- /// </summary>
- int SurfaceHeight { get; }
- /// <summary>
- /// Gets the size of the surface data in pixels.
- /// </summary>
- Size SurfaceSize { get; }
- /// <summary>
- /// Gets the width of the surface data in pixels.
- /// </summary>
- int SurfaceWidth { get; }
+ /// <summary>
+ /// Public Surface interface.
+ /// </summary>
+ public interface ISurface : IDisposable
+ {
+ /// <summary>
+ /// Gets or sets the alpha value for the surface.
+ /// 0.0 is completely transparent and 1.0 is completely opaque.
+ /// </summary>
+ double Alpha { get; set; }
+ /// <summary>
+ /// Gets or sets the color the surface is multiplied by when drawn.
+ /// Setting this value overwrites the Alpha value.
+ /// </summary>
+ Color Color { get; set; }
+ /// <summary>
+ /// Gets or sets a color gradient used for this surface.
+ /// </summary>
+ Gradient ColorGradient { get; set; }
+ /// <summary>
+ /// Gets or sets how coordinate arguments to Draw overloads are interpreted.
+ /// </summary>
+ OriginAlignment DisplayAlignment { get; set; }
+ /// <summary>
+ /// Gets or sets the display height of the surface, in pixels.
+ /// </summary>
+ int DisplayHeight { get; set; }
+ /// <summary>
+ /// Gets or sets the display size of the surface, in pixels.
+ /// </summary>
+ Size DisplaySize { get; set; }
+ /// <summary>
+ /// Gets or sets the display width of the surface, in pixels.
+ /// </summary>
+ int DisplayWidth { get; set; }
+ /// <summary>
+ /// Draws the surface at the specified point.
+ /// </summary>
+ /// <param name="destPt"></param>
+ void Draw(Point destPt);
+ /// <summary>
+ /// Draws the surface at the specified point.
+ /// </summary>
+ /// <param name="destPt"></param>
+ void Draw(PointF destPt);
+ /// <summary>
+ /// Draws the surface at the specified point.
+ /// </summary>
+ /// <param name="destX"></param>
+ /// <param name="destY"></param>
+ void Draw(int destX, int destY);
+ /// <summary>
+ /// Draws the surface at the specified point.
+ /// </summary>
+ /// <param name="destX"></param>
+ /// <param name="destY"></param>
+ void Draw(float destX, float destY);
+ /// <summary>
+ /// Gets the current scale values.
+ /// </summary>
+ /// <param name="width"></param>
+ /// <param name="height"></param>
+ void GetScale(out double width, out double height);
+ /// <summary>
+ /// Increases the rotation angle.
+ /// </summary>
+ /// <param name="radians"></param>
+ void IncrementRotationAngle(double radians);
+ /// <summary>
+ /// Increases the rotation angle.
+ /// </summary>
+ /// <param name="degrees"></param>
+ void IncrementRotationAngleDegrees(double degrees);
+ /// <summary>
+ /// The amount the surface is rotated when drawn. The angle is measured
+ /// up from the horizontal axis.
+ /// </summary>
+ double RotationAngle { get; set; }
+ /// <summary>
+ /// The amount the surface is rotated when drawn. The angle is measured
+ /// up from the horizontal axis.
+ /// </summary>
+ double RotationAngleDegrees { get; set; }
+ /// <summary>
+ /// The point where the surface is rotated around when drawn.
+ /// </summary>
+ OriginAlignment RotationCenter { get; set; }
+ /// <summary>
+ /// The amount the height of the surface is scaled when drawn. 1.0 is no scaling.
+ /// </summary>
+ double ScaleHeight { get; set; }
+ /// <summary>
+ /// The amount the width of the surface is scaled when drawn. 1.0 is no scaling.
+ /// </summary>
+ double ScaleWidth { get; set; }
+ /// <summary>
+ /// Sets the width and height scale values simultaneously.
+ /// </summary>
+ /// <param name="width"></param>
+ /// <param name="height"></param>
+ void SetScale(double width, double height);
+ /// <summary>
+ /// Gets the height of the surface data in pixels.
+ /// </summary>
+ int SurfaceHeight { get; }
+ /// <summary>
+ /// Gets the size of the surface data in pixels.
+ /// </summary>
+ Size SurfaceSize { get; }
+ /// <summary>
+ /// Gets the width of the surface data in pixels.
+ /// </summary>
+ int SurfaceWidth { get; }
- SurfaceState State { get; }
+ SurfaceState State { get; }
- void Draw(SurfaceState State);
- }
+ void Draw(SurfaceState State);
+ }
}
Modified: branches/font/AgateLib/DisplayLib/OriginAlignment.cs
===================================================================
--- branches/font/AgateLib/DisplayLib/OriginAlignment.cs 2009-04-25 19:43:50 UTC (rev 915)
+++ branches/font/AgateLib/DisplayLib/OriginAlignment.cs 2009-04-25 19:58:56 UTC (rev 916)
@@ -20,56 +20,56 @@
namespace AgateLib.DisplayLib
{
- /// <summary>
- /// OriginAlignment enum. Used to specify how
- /// points should be interpreted.
- /// </summary>
- public enum OriginAlignment
- {
- /// <summary>
- /// Point indicates top-left.
- /// </summary>
- TopLeft = 0x11,
- /// <summary>
- /// Point indicates top-center.
- /// </summary>
- TopCenter = 0x12,
- /// <summary>
- /// Point indicates top-right.
- /// </summary>
- TopRight = 0x13,
+ /// <summary>
+ /// OriginAlignment enum. Used to specify how
+ /// points should be interpreted.
+ /// </summary>
+ public enum OriginAlignment
+ {
+ /// <summary>
+ /// Point indicates top-left.
+ /// </summary>
+ TopLeft = 0x11,
+ /// <summary>
+ /// Point indicates top-center.
+ /// </summary>
+ TopCenter = 0x12,
+ /// <summary>
+ /// Point indicates top-right.
+ /// </summary>
+ TopRight = 0x13,
- /// <summary>
- /// Point indicates center-left.
- /// </summary>
- CenterLeft = 0x21,
- /// <summary>
- /// Point indicates center.
- /// </summary>
- Center = 0x22,
- /// <summary>
- /// Point indicates center-right.
- /// </summary>
- CenterRight = 0x23,
+ /// <summary>
+ /// Point indicates center-left.
+ /// </summary>
+ CenterLeft = 0x21,
+ /// <summary>
+ /// Point indicates center.
+ /// </summary>
+ Center = 0x22,
+ /// <summary>
+ /// Point indicates center-right.
+ /// </summary>
+ CenterRight = 0x23,
- /// <summary>
- /// Point indicates bottom-left.
- /// </summary>
- BottomLeft = 0x31,
- /// <summary>
- /// Point indicates bottom-center.
- /// </summary>
- BottomCenter = 0x32,
- /// <summary>
- /// Point indicates bottom-right.
- /// </summary>
- BottomRight = 0x33,
+ /// <summary>
+ /// Point indicates bottom-left.
+ /// </summary>
+ BottomLeft = 0x31,
+ /// <summary>
+ /// Point indicates bottom-center.
+ /// </summary>
+ BottomCenter = 0x32,
+ /// <summary>
+ /// Point indicates bottom-right.
+ /// </summary>
+ BottomRight = 0x33,
/// <summary>
/// Specified indicates that the value in question is specified through
/// some other means.
/// </summary>
Specified = 0xFF,
- }
+ }
}
Modified: branches/font/AgateLib/DisplayLib/Surface.cs
===================================================================
--- branches/font/AgateLib/DisplayLib/Surface.cs 2009-04-25 19:43:50 UTC (rev 915)
+++ branches/font/AgateLib/DisplayLib/Surface.cs 2009-04-25 19:58:56 UTC (rev 916)
@@ -27,258 +27,258 @@
namespace AgateLib.DisplayLib
{
- /// <summary>
- /// Enum which is used to indicate what format an image file is in.
- /// </summary>
- public enum ImageFileFormat
- {
- /// <summary>
- /// Portable Network Graphics (PNG) format.
- /// </summary>
- Png,
- /// <summary>
- /// Windows Bitmap (BMP) format.
- /// </summary>
- Bmp,
- /// <summary>
- /// Jpeg format.
- /// </summary>
- Jpg,
- /// <summary>
- /// Targa format.
- /// </summary>
- Tga,
- }
- /// <summary>
- /// Class which represents a pixel surface.
- /// There are several ways to create a Surface object. The most common
- /// is to pass the name of an image file.
- ///
- /// Using a surface to draw on the screen is very simple. There are
- /// several overloaded Draw methods which do that.
- ///
- /// You must have created a DisplayWindow object before creating any
- /// Surface objects.
- /// <example>
- /// C# Example to create a new surface from an image file:
- /// <code>
- /// Surface surface = new Surface("myimage.png");
- /// </code>
- /// VB Example to create a new surface from an image file:
- /// <code>
- /// Dim surf as New Surface("myimage.png")
- /// </code>
- ///
- /// C# Example to draw surface to screen.
- /// <code>
- /// surface.Draw(20, 20);
- /// </code>
- /// VB Example to draw surface to screen.
- /// <code>
- /// surf.Draw(20, 20)
- /// </code>
- /// </example>
- /// </summary>
- public sealed class Surface : IRenderTarget, IDisposable, ISurface
- {
- SurfaceImpl impl;
+ /// <summary>
+ /// Enum which is used to indicate what format an image file is in.
+ /// </summary>
+ public enum ImageFileFormat
+ {
+ /// <summary>
+ /// Portable Network Graphics (PNG) format.
+ /// </summary>
+ Png,
+ /// <summary>
+ /// Windows Bitmap (BMP) format.
+ /// </summary>
+ Bmp,
+ /// <summary>
+ /// Jpeg format.
+ /// </summary>
+ Jpg,
+ /// <summary>
+ /// Targa format.
+ /// </summary>
+ Tga,
+ }
+ /// <summary>
+ /// Class which represents a pixel surface.
+ /// There are several ways to create a Surface object. The most common
+ /// is to pass the name of an image file.
+ ///
+ /// Using a surface to draw on the screen is very simple. There are
+ /// several overloaded Draw methods which do that.
+ ///
+ /// You must have created a DisplayWindow object before creating any
+ /// Surface objects.
+ /// <example>
+ /// C# Example to create a new surface from an image file:
+ /// <code>
+ /// Surface surface = new Surface("myimage.png");
+ /// </code>
+ /// VB Example to create a new surface from an image file:
+ /// <code>
+ /// Dim surf as New Surface("myimage.png")
+ /// </code>
+ ///
+ /// C# Example to draw surface to screen.
+ /// <code>
+ /// surface.Draw(20, 20);
+ /// </code>
+ /// VB Example to draw surface to screen.
+ /// <code>
+ /// surf.Draw(20, 20)
+ /// </code>
+ /// </example>
+ /// </summary>
+ public sealed class Surface : IRenderTarget, IDisposable, ISurface
+ {
+ SurfaceImpl impl;
SurfaceState mState = new SurfaceState();
- /// <summary>
- /// Creates a surface object from a resource.
- /// </summary>
- /// <param name="resources"></param>
- /// <param name="name"></param>
- public Surface(Resources.AgateResourceCollection resources, string name)
- {
- if (Display.Impl == null)
- throw new AgateException("AgateLib's display system has not been initialized.");
+ /// <summary>
+ /// Creates a surface object from a resource.
+ /// </summary>
+ /// <param name="resources"></param>
+ /// <param name="name"></param>
+ public Surface(Resources.AgateResourceCollection resources, string name)
+ {
+ if (Display.Impl == null)
+ throw new AgateException("AgateLib's display system has not been initialized.");
- Resources.AgateResource res = resources[name];
- Resources.SurfaceResource surf = res as Resources.SurfaceResource;
+ Resources.AgateResource res = resources[name];
+ Resources.SurfaceResource surf = res as Resources.SurfaceResource;
- using (System.IO.Stream s = AgateFileProvider.Images.OpenRead(surf.Filename))
- {
- impl = Display.Impl.CreateSurface(s);
- }
+ using (System.IO.Stream s = AgateFileProvider.Images.OpenRead(surf.Filename))
+ {
+ impl = Display.Impl.CreateSurface(s);
+ }
- Display.DisposeDisplay += new Display.DisposeDisplayHandler(Dispose);
- Display.PackAllSurfacesEvent += new EventHandler(Display_PackAllSurfacesEvent);
- }
- /// <summary>
- /// Creates a surface object, from the specified image file.
- /// </summary>
- /// <param name="filename"></param>
- public Surface(string filename)
- : this(AgateFileProvider.Images, filename)
- {
- }
- /// <summary>
- /// Creates a surface object using the specified file provider to open the image file.
- /// </summary>
- /// <param name="filename"></param>
- /// <param name="fileProvider"></param>
- public Surface(IFileProvider fileProvider, string filename)
- {
- if (Display.Impl == null)
- throw new AgateException("AgateLib's display system has not been initialized.");
+ Display.DisposeDisplay += new Display.DisposeDisplayHandler(Dispose);
+ Display.PackAllSurfacesEvent += new EventHandler(Display_PackAllSurfacesEvent);
+ }
+ /// <summary>
+ /// Creates a surface object, from the specified image file.
+ /// </summary>
+ /// <param name="filename"></param>
+ public Surface(string filename)
+ : this(AgateFileProvider.Images, filename)
+ {
+ }
+ /// <summary>
+ /// Creates a surface object using the specified file provider to open the image file.
+ /// </summary>
+ /// <param name="filename"></param>
+ /// <param name="fileProvider"></param>
+ public Surface(IFileProvider fileProvider, string filename)
+ {
+ if (Display.Impl == null)
+ throw new AgateException("AgateLib's display system has not been initialized.");
- using (System.IO.Stream s = fileProvider.OpenRead(filename))
- {
- impl = Display.Impl.CreateSurface(s);
- }
+ using (System.IO.Stream s = fileProvider.OpenRead(filename))
+ {
+ impl = Display.Impl.CreateSurface(s);
+ }
- Display.DisposeDisplay += new Display.DisposeDisplayHandler(Dispose);
- Display.PackAllSurfacesEvent += new EventHandler(Display_PackAllSurfacesEvent);
- }
- /// <summary>
- /// Creates a surface object from the data in the specified stream.
- /// </summary>
- /// <param name="st"></param>
- public Surface(Stream st)
- {
- if (Display.Impl == null)
- throw new AgateException("AgateLib's display system has not been initialized.");
-
- impl = Display.Impl.CreateSurface(st);
+ Display.DisposeDisplay += new Display.DisposeDisplayHandler(Dispose);
+ Display.PackAllSurfacesEvent += new EventHandler(Display_PackAllSurfacesEvent);
+ }
+ /// <summary>
+ /// Creates a surface object from the data in the specified stream.
+ /// </summary>
+ /// <param name="st"></param>
+ public Surface(Stream st)
+ {
+ if (Display.Impl == null)
+ throw new AgateException("AgateLib's display system has not been initialized.");
- Display.DisposeDisplay += new Display.DisposeDisplayHandler(Dispose);
- Display.PackAllSurfacesEvent += new EventHandler(Display_PackAllSurfacesEvent);
- }
- /// <summary>
- /// Creates a surface object of the specified size.
- /// </summary>
- /// <param name="width"></param>
- /// <param name="height"></param>
- public Surface(int width, int height)
- : this(new Size(width, height))
- {
-
- }
- /// <summary>
- /// Creates a surface object of the specified size.
- /// </summary>
- /// <param name="size"></param>
- public Surface(Size size)
- {
- if (Display.Impl == null)
- throw new AgateException("AgateLib's display system has not been initialized.");
+ impl = Display.Impl.CreateSurface(st);
- impl = Display.Impl.CreateSurface(size);
+ Display.DisposeDisplay += new Display.DisposeDisplayHandler(Dispose);
+ Display.PackAllSurfacesEvent += new EventHandler(Display_PackAllSurfacesEvent);
+ }
+ /// <summary>
+ /// Creates a surface object of the specified size.
+ /// </summary>
+ /// <param name="width"></param>
+ /// <param name="height"></param>
+ public Surface(int width, int height)
+ : this(new Size(width, height))
+ {
- Display.DisposeDisplay += new Display.DisposeDisplayHandler(Dispose);
- Display.PackAllSurfacesEvent += new EventHandler(Display_PackAllSurfacesEvent);
- }
- /// <summary>
- /// Constructs a surface object from the specified PixelBuffer object.
- /// </summary>
- /// <param name="pixels"></param>
- public Surface(PixelBuffer pixels)
- : this(pixels.Size)
- {
- if (Display.Impl == null)
- throw new AgateException("AgateLib's display system has not been initialized.");
+ }
+ /// <summary>
+ /// Creates a surface object of the specified size.
+ /// </summary>
+ /// <param name="size"></param>
+ public Surface(Size size)
+ {
+ if (Display.Impl == null)
+ throw new AgateException("AgateLib's display system has not been initialized.");
- WritePixels(pixels);
- }
- /// <summary>
- /// Creates a surface object and to be ready to attach to an implemented object.
- /// Throws an Exception if there is a passed impl.
- /// (This is not intended for use by applications).
- /// </summary>
- /// <param name="fromImpl"></param>
- private Surface(SurfaceImpl fromImpl)
- {
- if (Display.Impl == null)
- throw new AgateException("AgateLib's display system has not been initialized.");
+ impl = Display.Impl.CreateSurface(size);
- if (fromImpl != null)
- throw new Exception("fromImpl already has an owned implementation!");
+ Display.DisposeDisplay += new Display.DisposeDisplayHandler(Dispose);
+ Display.PackAllSurfacesEvent += new EventHandler(Display_PackAllSurfacesEvent);
+ }
+ /// <summary>
+ /// Constructs a surface object from the specified PixelBuffer object.
+ /// </summary>
+ /// <param name="pixels"></param>
+ public Surface(PixelBuffer pixels)
+ : this(pixels.Size)
+ {
+ if (Display.Impl == null)
+ throw new AgateException("AgateLib's display system has not been initialized.");
- Display.DisposeDisplay += new Display.DisposeDisplayHandler(Dispose);
- Display.PackAllSurfacesEvent += new EventHandler(Display_PackAllSurfacesEvent);
- }
- /// <summary>
- /// Destroyes unmanaged resources associated with this surface.
- /// </summary>
- public void Dispose()
- {
- impl.Dispose();
+ WritePixels(pixels);
+ }
+ /// <summary>
+ /// Creates a surface object and to be ready to attach to an implemented object.
+ /// Throws an Exception if there is a passed impl.
+ /// (This is not intended for use by applications).
+ /// </summary>
+ /// <param name="fromImpl"></param>
+ private Surface(SurfaceImpl fromImpl)
+ {
+ if (Display.Impl == null)
+ throw new AgateException("AgateLib's display system has not been initialized.");
- //Display.DisposeDisplay -= Dispose;
- Display.PackAllSurfacesEvent -= Display_PackAllSurfacesEvent;
- }
- /// <summary>
- /// Returns true if Dispose() has been called on this surface.
- /// </summary>
- public bool IsDisposed
- {
- get { return impl.IsDisposed; }
- }
+ if (fromImpl != null)
+ throw new Exception("fromImpl already has an owned implementation!");
- void Display_PackAllSurfacesEvent(object sender, EventArgs e)
- {
- if (ShouldBePacked && !IsDisposed)
- Display.SurfacePacker.QueueSurface(this);
- }
+ Display.DisposeDisplay += new Display.DisposeDisplayHandler(Dispose);
+ Display.PackAllSurfacesEvent += new EventHandler(Display_PackAllSurfacesEvent);
+ }
+ /// <summary>
+ /// Destroyes unmanaged resources associated with this surface.
+ /// </summary>
+ public void Dispose()
+ {
+ impl.Dispose();
- #region --- Surface properties ---
+ //Display.DisposeDisplay -= Dispose;
+ Display.PackAllSurfacesEvent -= Display_PackAllSurfacesEvent;
+ }
+ /// <summary>
+ /// Returns true if Dispose() has been called on this surface.
+ /// </summary>
+ public bool IsDisposed
+ {
+ get { return impl.IsDisposed; }
+ }
- /// <summary>
- /// Gets or sets how many times this surface should be broken down
- /// when drawn. A TesselateFactor of 2 indicates that each time
- /// this surface is drawn, it's drawn in 4 (2x2) chunks.
- /// </summary>
- /// <remarks>
- /// This property is used to divide a surface drawn up into smaller
- /// surfaces which are drawn independently. The reason to do this is
- /// lighting calculations (without using shaders) are done on a per-vertex
- /// basis. When a light source is close to a large surface, this will create
- /// noticably bad lighting, because only the lighting properties at the
- /// corners are calculated, and then the lighting is interpolated between
- /// the end points.
- /// <para>
- /// Changing this value while using gradients can result in ugly transitions between
- /// different tesselation values. The reason is AgateLib will interpolate the gradient
- /// color to the vertices used, and then this is capped to integer values. So avoid
- /// doing this.</para>
- /// <para>
- /// Setting this value high may have a significant impact on performance.
- /// For each time a Surface.Draw() overload is called, the number of triangles
- /// which are calculated and sent to the rasterizer is 2 * TesselateFactor<sup>2</sup>.
- /// </para>
- /// </remarks>
- ///
- public int TesselateFactor
- {
- get { return impl.TesselateFactor; }
- set { impl.TesselateFactor = value; }
- }
- /// <summary>
- /// Gets or sets a bool value that indicates whether or not this surface
- /// should be included in a call to Display.PackAllSurfaces.
- /// </summary>
- public bool ShouldBePacked
- {
- get { return impl.ShouldBePacked; }
- set { impl.ShouldBePacked = value; }
- }
+ void Display_PackAllSurfacesEvent(object sender, EventArgs e)
+ {
+ if (ShouldBePacked && !IsDisposed)
+ Display.SurfacePacker.QueueSurface(this);
+ }
- /// <summary>
- /// Gets the width of the source surface in pixels.
- /// </summary>
- public int SurfaceWidth { get { return impl.SurfaceWidth; } }
- /// <summary>
- /// Gets the height of the source surface in pixels.
- /// </summary>
- public int SurfaceHeight { get { return impl.SurfaceHeight; } }
- /// <summary>
- /// Gets the Size of the source surface in pixels.
- /// </summary>
- public Size SurfaceSize { get { return impl.SurfaceSize; } }
+ #region --- Surface properties ---
+ /// <summary>
+ /// Gets or sets how many times this surface should be broken down
+ /// when drawn. A TesselateFactor of 2 indicates that each time
+ /// this surface is drawn, it's drawn in 4 (2x2) chunks.
+ /// </summary>
+ /// <remarks>
+ /// This property is used to divide a surface drawn up into smaller
+ /// surfaces which are drawn independently. The reason to do this is
+ /// lighting calculations (without using shaders) are done on a per-vertex
+ /// basis. When a light source is close to a large surface, this will create
+ /// noticably bad lighting, because only the lighting properties at the
+ /// corners are calculated, and then the lighting is interpolated between
+ /// the end points.
+ /// <para>
+ /// Changing this value while using gradients can result in ugly transitions between
+ /// different tesselation values. The reason is AgateLib will interpolate the gradient
+ /// color to the vertices used, and then this is capped to integer values. So avoid
+ /// doing this.</para>
+ /// <para>
+ /// Setting this value high may have a significant impact on performance.
+ /// For each time a Surface.Draw() overload is called, the number of triangles
+ /// which are calculated and sent to the rasterizer is 2 * TesselateFactor<sup>2</sup>.
+ /// </para>
+ /// </remarks>
+ ///
+ public int TesselateFactor
+ {
+ get { return impl.TesselateFactor; }
+ set { impl.TesselateFactor = value; }
+ }
+ /// <summary>
+ /// Gets or sets a bool value that indicates whether or not this surface
+ /// should be included in a call to Display.PackAllSurfaces.
+ /// </summary>
+ public bool ShouldBePacked
+ {
+ get { return impl.ShouldBePacked; }
+ set { impl.ShouldBePacked = value; }
+ }
/// <summary>
+ /// Gets the width of the source surface in pixels.
+ /// </summary>
+ public int SurfaceWidth { get { return impl.SurfaceWidth; } }
+ /// <summary>
+ /// Gets the height of the source surface in pixels.
+ /// </summary>
+ public int SurfaceHeight { get { return impl.SurfaceHeight; } }
+ /// <summary>
+ /// Gets the Size of the source surface in pixels.
+ /// </summary>
+ public Size SurfaceSize { get { return impl.SurfaceSize; } }
+
+
+ /// <summary>
/// Gets or sets the state of the surface.
/// </summary>
public SurfaceState State
@@ -464,101 +464,101 @@
mState.IncrementRotationAngleDegrees(degrees);
}
- #endregion
+ #endregion
- #region --- Drawing to the screen ---
+ #region --- Drawing to the screen ---
- /// <summary>
- /// Draws the surface to the top-left corner (0, 0) of the
- /// target.
- /// </summary>
- public void Draw()
- {
- Draw(Point.Empty);
- }
- /// <summary>
- /// Draws this surface to the screen at the specified point,
- /// using all the state information defined in the properties
- /// of this surface.
- /// </summary>
- /// <param name="destX"></param>
- /// <param name="destY"></param>
- public void Draw(int destX, int destY)
- {
+ /// <summary>
+ /// Draws the surface to the top-left corner (0, 0) of the
+ /// target.
+ /// </summary>
+ public void Draw()
+ {
+ Draw(Point.Empty);
+ }
+ /// <summary>
+ /// Draws this surface to the screen at the specified point,
+ /// using all the state information defined in the properties
+ /// of this surface.
+ /// </summary>
+ /// <param name="destX"></param>
+ /// <param name="destY"></param>
+ public void Draw(int destX, int destY)
+ {
mState.DrawInstances.SetCount(1);
mState.DrawInstances[0] = new SurfaceDrawInstance(new PointF(destX, destY));
impl.Draw(State);
- }
- /// <summary>
- /// Draws this surface to the screen at the specified point,
- /// using all the state information defined in the properties
- /// of this surface.
- /// </summary>
- /// <param name="destX"></param>
- /// <param name="destY"></param>
- public void Draw(float destX, float destY)
- {
+ }
+ /// <summary>
+ /// Draws this surface to the screen at the specified point,
+ /// using all the state information defined in the properties
+ /// of this surface.
+ /// </summary>
+ /// <param name="destX"></param>
+ /// <param name="destY"></param>
+ public void Draw(float destX, float destY)
+ {
mState.DrawInstances.SetCount(1);
mState.DrawInstances[0] = new SurfaceDrawInstance(new PointF(destX, destY));
impl.Draw(State);
}
- /// <summary>
- /// Draws this surface to the screen at the specified point,
- /// using all the state information defined in the properties
- /// of this surface.
- /// </summary>
- /// <param name="destPt"></param>
- public void Draw(Point destPt)
- {
+ /// <summary>
+ /// Draws this surface to the screen at the specified point,
+ /// using all the state information defined in the properties
+ /// of this surface.
+ /// </summary>
+ /// <param name="destPt"></param>
+ public void Draw(Point destPt)
+ {
Draw(destPt.X, destPt.Y);
- }
- /// <summary>
- /// Draws this surface to the screen at the specified point,
- /// using all the state information defined in the properties
- /// of this surface.
- /// </summary>
- /// <param name="destPt"></param>
- public void Draw(Vector2 destPt)
- {
+ }
+ /// <summary>
+ /// Draws this surface to the screen at the specified point,
+ /// using all the state information defined in the properties
+ /// of this surface.
+ /// </summary>
+ /// <param name="destPt"></param>
+ public void Draw(Vector2 destPt)
+ {
Draw(destPt.X, destPt.Y);
- }
- /// <summary>
- /// Draws this surface to the screen at the specified point,
- /// using all the state information defined in the properties
- /// of this surface.
- /// </summary>
- /// <param name="destPt"></param>
- public void Draw(PointF destPt)
- {
+ }
+ /// <summary>
+ /// Draws this surface to the screen at the specified point,
+ /// using all the state information defined in the properties
+ /// of this surface.
+ /// </summary>
+ /// <param name="destPt"></param>
+ public void Draw(PointF destPt)
+ {
Draw(destPt.X, destPt.Y);
- }
- /// <summary>
- /// Draws this surface to the screen at the specified point,
- /// using all the state information defined in the properties
- /// of this surface.
- /// Ignores the value of RotationCenter and uses the specified
- /// point to rotate around instead.
- /// </summary>
- /// <param name="destPt"></param>
- /// <param name="rotationCenter">Center of rotation to use, relative
- /// to the top-left of the surface.</para...
[truncated message content] |
|
From: <ka...@us...> - 2009-04-25 19:44:00
|
Revision: 915
http://agate.svn.sourceforge.net/agate/?rev=915&view=rev
Author: kanato
Date: 2009-04-25 19:43:50 +0000 (Sat, 25 Apr 2009)
Log Message:
-----------
Use tabs to format FontSurface.cs.
Modified Paths:
--------------
branches/font/AgateLib/DisplayLib/FontSurface.cs
Modified: branches/font/AgateLib/DisplayLib/FontSurface.cs
===================================================================
--- branches/font/AgateLib/DisplayLib/FontSurface.cs 2009-04-25 18:37:13 UTC (rev 914)
+++ branches/font/AgateLib/DisplayLib/FontSurface.cs 2009-04-25 19:43:50 UTC (rev 915)
@@ -201,7 +201,7 @@
if (value == null)
throw new ArgumentNullException("Cannot set state to a null value. If you wish to reset the state, set it to a new FontState object.");
- mState = value;
+ mState = value;
}
}
/// <summary>
@@ -272,7 +272,7 @@
/// </summary>
/// <param name="text"></param>
/// <returns></returns>
- public int StringDisplayWidth(string text)
+ public int StringDisplayWidth(string text)
{
return StringDisplaySize(text).Width;
}
@@ -281,7 +281,7 @@
/// </summary>
/// <param name="text"></param>
/// <returns></returns>
- public int StringDisplayHeight(string text)
+ public int StringDisplayHeight(string text)
{
return StringDisplaySize(text).Height;
}
@@ -290,7 +290,7 @@
/// </summary>
/// <param name="text"></param>
/// <returns></returns>
- public Size StringDisplaySize(string text)
+ public Size StringDisplaySize(string text)
{
return impl.StringDisplaySize(mState, text);
}
@@ -390,7 +390,7 @@
{
new LayoutText { Font =this, LineIndex = 0, Text = formatString}
};
-
+
}
int lastIndex = 0;
@@ -494,8 +494,8 @@
}
}
- private void PushLayoutImage(int lineIndex, TextLayout layout,
- ref PointF dest, ref int lineHeight,ref int spaceAboveLine,
+ private void PushLayoutImage(int lineIndex, TextLayout layout,
+ ref PointF dest, ref int lineHeight, ref int spaceAboveLine,
ISurface surface)
{
int newSpaceAbove;
@@ -529,20 +529,20 @@
layout.Add(t);
}
- private void PushLayoutText(int lineIndex, TextLayout layout,
+ private void PushLayoutText(int lineIndex, TextLayout layout,
ref PointF dest, ref int lineHeight, ref int spaceAboveLine,
string text, AlterFont alter)
{
if (string.IsNullOrEmpty(text))
return;
- LayoutText t = new LayoutText
+ LayoutText t = new LayoutText
{
- Font = this,
+ Font = this,
State = State.Clone(),
- Location = dest,
- Text = text,
- LineIndex = lineIndex
+ Location = dest,
+ Text = text,
+ LineIndex = lineIndex
};
if (alter != null)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ka...@us...> - 2009-04-25 18:37:17
|
Revision: 914
http://agate.svn.sourceforge.net/agate/?rev=914&view=rev
Author: kanato
Date: 2009-04-25 18:37:13 +0000 (Sat, 25 Apr 2009)
Log Message:
-----------
Fix interpretation of escaped braces in text layout.
Modified Paths:
--------------
branches/font/AgateLib/DisplayLib/FontSurface.cs
branches/font/Tests/Fonts/TextLayout/TextLayout.cs
Modified: branches/font/AgateLib/DisplayLib/FontSurface.cs
===================================================================
--- branches/font/AgateLib/DisplayLib/FontSurface.cs 2009-04-25 17:46:09 UTC (rev 913)
+++ branches/font/AgateLib/DisplayLib/FontSurface.cs 2009-04-25 18:37:13 UTC (rev 914)
@@ -321,19 +321,6 @@
/// <param name="destX"></param>
/// <param name="destY"></param>
/// <param name="text"></param>
- public void DrawText(int destX, int destY, string text)
- {
- mState.Location = new PointF(destX, destY);
- mState.Text = mTransformer.Transform(text);
-
- DrawText(mState);
- }
- /// <summary>
- /// Draws the specified string at the specified location.
- /// </summary>
- /// <param name="destX"></param>
- /// <param name="destY"></param>
- /// <param name="text"></param>
public void DrawText(double destX, double destY, string text)
{
mState.Location = new PointF((float)destX, (float)destY);
@@ -382,8 +369,8 @@
impl.DrawText(state);
}
- Regex substituteMatch = new Regex(@"\{[0-9]+(:.*)?\}|\r\n|\n");
- Regex indexMatch = new Regex(@"[0-9]+");
+ Regex substituteMatch = new Regex(@"\{.*?\}|\{\{\}|\{\}\}|\r\n|\n");
+ Regex indexMatch = new Regex(@"[0-9]+:?");
public void DrawText(int destX, int destY, string formatString, params object[] args)
{
@@ -424,6 +411,9 @@
result += formatString.Substring(lastIndex, matches[i].Index - lastIndex);
+ var argsIndexText = indexMatch.Match(format);
+ int argsIndex;
+
if (format == "\r\n" || format == "\n")
{
PushLayoutText(lineIndex, layout, ref dest, ref lineHeight, ref spaceAboveLine,
@@ -441,11 +431,13 @@
spaceAboveLine = 0;
}
- else
+ else if (int.TryParse(argsIndexText.ToString(), out argsIndex))
{
- var argsIndexText = indexMatch.Match(format);
- int argsIndex = int.Parse(argsIndexText.ToString());
-
+ if (argsIndex >= args.Length)
+ {
+ throw new IndexOutOfRangeException(string.Format(
+ "Argument number {0} was specified, but only {1} arguments were given.", argsIndex, args.Length));
+ }
object obj = args[argsIndex];
if (obj is ISurface)
@@ -453,7 +445,7 @@
PushLayoutText(lineIndex, layout, ref dest, ref lineHeight, ref spaceAboveLine,
result, currentAlterText);
- PushLayoutImage(lineIndex, layout, ref dest, ref lineHeight, ref spaceAboveLine,
+ PushLayoutImage(lineIndex, layout, ref dest, ref lineHeight, ref spaceAboveLine,
(ISurface)obj);
result = string.Empty;
@@ -468,11 +460,19 @@
currentAlterText = (AlterFont)obj;
result = string.Empty;
}
- else
+ else
{
result += ConvertToString(obj, format);
}
}
+ else if (format.StartsWith("{"))
+ {
+ if (format == "{{}")
+ result += "{";
+ else if (format == "{}}")
+ result += "}";
+ }
+
lastIndex = matches[i].Index + matches[i].Length;
}
Modified: branches/font/Tests/Fonts/TextLayout/TextLayout.cs
===================================================================
--- branches/font/Tests/Fonts/TextLayout/TextLayout.cs 2009-04-25 17:46:09 UTC (rev 913)
+++ branches/font/Tests/Fonts/TextLayout/TextLayout.cs 2009-04-25 18:37:13 UTC (rev 914)
@@ -51,6 +51,8 @@
"The last word here should appear really {2}Large{3}.",
AlterFont.Color(Color.Green), AlterFont.Color(Color.Black),
AlterFont.Scale(3.0, 3.0), AlterFont.Scale(1.0, 1.0));
+
+ font.DrawText(0, 530, "Test of escape sequences: {{}Escaped{}}");
}
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ka...@us...> - 2009-04-25 17:46:22
|
Revision: 913
http://agate.svn.sourceforge.net/agate/?rev=913&view=rev
Author: kanato
Date: 2009-04-25 17:46:09 +0000 (Sat, 25 Apr 2009)
Log Message:
-----------
Add in AlterFont classes.
Modified Paths:
--------------
branches/font/AgateLib/BitmapFont/BitmapFontImpl.cs
branches/font/AgateLib/DisplayLib/FontSurface.cs
branches/font/AgateLib/DisplayLib/TextLayout.cs
branches/font/Tests/Fonts/TextLayout/TextLayout.cs
Modified: branches/font/AgateLib/BitmapFont/BitmapFontImpl.cs
===================================================================
--- branches/font/AgateLib/BitmapFont/BitmapFontImpl.cs 2009-04-25 07:39:00 UTC (rev 912)
+++ branches/font/AgateLib/BitmapFont/BitmapFontImpl.cs 2009-04-25 17:46:09 UTC (rev 913)
@@ -205,6 +205,7 @@
}
// measure height
+ i = 0;
do
{
i = text.IndexOf('\n', i + 1);
Modified: branches/font/AgateLib/DisplayLib/FontSurface.cs
===================================================================
--- branches/font/AgateLib/DisplayLib/FontSurface.cs 2009-04-25 07:39:00 UTC (rev 912)
+++ branches/font/AgateLib/DisplayLib/FontSurface.cs 2009-04-25 17:46:09 UTC (rev 913)
@@ -292,8 +292,18 @@
/// <returns></returns>
public Size StringDisplaySize(string text)
{
- return impl.StringDisplaySize(mState, text);
+ return impl.StringDisplaySize(mState, text);
}
+ /// <summary>
+ /// Measures the display size of the specified string, using the specified state information.
+ /// </summary>
+ /// <param name="state"></param>
+ /// <param name="text"></param>
+ /// <returns></returns>
+ public Size StringDisplaySize(FontState state, string text)
+ {
+ return impl.StringDisplaySize(state, text);
+ }
/// <summary>
/// Gets the height in pixels of a single line of text.
@@ -377,12 +387,23 @@
public void DrawText(int destX, int destY, string formatString, params object[] args)
{
+ TextLayout layout = CreateLayout(formatString, args);
+
+ layout.Translate(new Point(destX, destY));
+ layout.DrawAll();
+ }
+
+ public TextLayout CreateLayout(string formatString, object[] args)
+ {
var matches = substituteMatch.Matches(formatString);
if (matches.Count == 0)
{
- DrawText(destX, destY, formatString);
- return;
+ return new TextLayout
+ {
+ new LayoutText { Font =this, LineIndex = 0, Text = formatString}
+ };
+
}
int lastIndex = 0;
@@ -395,6 +416,7 @@
int lineHeight = FontHeight;
int spaceAboveLine = 0;
int lineIndex = 0;
+ AlterFont currentAlterText = null;
for (int i = 0; i < matches.Count; i++)
{
@@ -404,7 +426,9 @@
if (format == "\r\n" || format == "\n")
{
- PushLayoutText(lineIndex, layout, ref dest, result);
+ PushLayoutText(lineIndex, layout, ref dest, ref lineHeight, ref spaceAboveLine,
+ result, currentAlterText);
+
result = string.Empty;
ShiftLine(layout, spaceAboveLine, lineIndex);
@@ -426,12 +450,26 @@
if (obj is ISurface)
{
- PushLayoutText(lineIndex, layout, ref dest, result);
- PushLayoutImage(lineIndex, layout, ref dest, ref lineHeight, ref spaceAboveLine, (ISurface)obj);
+ PushLayoutText(lineIndex, layout, ref dest, ref lineHeight, ref spaceAboveLine,
+ result, currentAlterText);
+
+ PushLayoutImage(lineIndex, layout, ref dest, ref lineHeight, ref spaceAboveLine,
+ (ISurface)obj);
+
result = string.Empty;
}
- else
+ else if (obj is AlterFont)
{
+ // push text with the old state
+ PushLayoutText(lineIndex, layout, ref dest, ref lineHeight, ref spaceAboveLine,
+ result, currentAlterText);
+
+ // store the new alter object to affect the state of the next block.
+ currentAlterText = (AlterFont)obj;
+ result = string.Empty;
+ }
+ else
+ {
result += ConvertToString(obj, format);
}
}
@@ -439,11 +477,12 @@
}
result += formatString.Substring(lastIndex);
- PushLayoutText(lineIndex, layout, ref dest, result);
+ PushLayoutText(lineIndex, layout, ref dest, ref lineHeight, ref spaceAboveLine,
+ result, currentAlterText);
+
ShiftLine(layout, spaceAboveLine, lineIndex);
- layout.Translate(new Point(destX, destY));
- layout.DrawAll();
+ return layout;
}
private static void ShiftLine(TextLayout layout, int lineShift, int lineIndex)
@@ -455,8 +494,9 @@
}
}
- private void PushLayoutImage(int lineIndex, TextLayout layout, ref PointF dest, ref int lineHeight,
- ref int spaceAboveLine, ISurface surface)
+ private void PushLayoutImage(int lineIndex, TextLayout layout,
+ ref PointF dest, ref int lineHeight,ref int spaceAboveLine,
+ ISurface surface)
{
int newSpaceAbove;
LayoutSurface t = new LayoutSurface { Location = dest, Surface = surface, LineIndex = lineIndex };
@@ -489,7 +529,9 @@
layout.Add(t);
}
- private void PushLayoutText(int lineIndex, TextLayout layout, ref PointF dest, string text)
+ private void PushLayoutText(int lineIndex, TextLayout layout,
+ ref PointF dest, ref int lineHeight, ref int spaceAboveLine,
+ string text, AlterFont alter)
{
if (string.IsNullOrEmpty(text))
return;
@@ -503,15 +545,23 @@
LineIndex = lineIndex
};
- layout.Add(t);
+ if (alter != null)
+ {
+ alter.ModifyState(t.State);
+ }
- var size = StringDisplaySize(text);
+ var size = StringDisplaySize(t.State, text);
var update = Origin.Calc(DisplayAlignment, size);
+ int newSpaceAbove = size.Height - FontHeight;
+ t.Y -= newSpaceAbove;
+ spaceAboveLine = Math.Max(spaceAboveLine, newSpaceAbove);
+
dest.X += size.Width;
+
+ layout.Add(t);
}
-
private string ConvertToString(object obj, string format)
{
return obj.ToString();
Modified: branches/font/AgateLib/DisplayLib/TextLayout.cs
===================================================================
--- branches/font/AgateLib/DisplayLib/TextLayout.cs 2009-04-25 07:39:00 UTC (rev 912)
+++ branches/font/AgateLib/DisplayLib/TextLayout.cs 2009-04-25 17:46:09 UTC (rev 913)
@@ -29,23 +29,17 @@
public abstract class LayoutItem
{
- PointF mLocation;
-
public abstract void Draw();
- public virtual PointF Location
- {
- get { return mLocation; }
- set { mLocation = value; }
- }
+ public abstract PointF Location { get; set; }
public float X
{
- get { return mLocation.X; }
- set { mLocation.X = value; }
+ get { return Location.X; }
+ set { Location = new PointF(value, Location.Y); }
}
public float Y
{
- get { return mLocation.Y; }
- set { mLocation.Y = value; }
+ get { return Location.Y; }
+ set { Location = new PointF(Location.X, value); }
}
public int LineIndex { get; set; }
}
@@ -68,12 +62,19 @@
{
Font.DrawText(State);
}
+
+ public override string ToString()
+ {
+ return string.Format(
+ "LayoutText: {0}; {1}", Location, Text);
+ }
}
public class LayoutSurface : LayoutItem
{
public ISurface Surface { get; set; }
public SurfaceState State { get; set; }
-
+ public override PointF Location { get; set; }
+
public static bool DebugRects;
public override void Draw()
@@ -90,4 +91,48 @@
Display.DrawRect(new Rectangle(Point.Round(Location), Surface.DisplaySize), Color.Blue);
}
}
+
+ public abstract class AlterFont
+ {
+ protected internal abstract void ModifyState(FontState state);
+
+ class AlterTextColor : AlterFont
+ {
+ Color clr;
+ public AlterTextColor(Color newColor)
+ {
+ clr = newColor;
+ }
+
+ protected internal override void ModifyState(FontState state)
+ {
+ state.Color = clr;
+ }
+ }
+ class AlterTextScale : AlterFont
+ {
+ double width, height;
+
+ public AlterTextScale(double width, double height)
+ {
+ this.width = width;
+ this.height = height;
+ }
+ protected internal override void ModifyState(FontState state)
+ {
+ state.ScaleWidth = width;
+ state.ScaleHeight = height;
+ }
+ }
+
+ public static AlterFont Color(Color newColor)
+ {
+ return new AlterTextColor(newColor);
+ }
+ public static AlterFont Scale(double scaleWidth, double scaleHeight)
+ {
+ return new AlterTextScale(scaleWidth, scaleHeight);
+ }
+ }
+
}
Modified: branches/font/Tests/Fonts/TextLayout/TextLayout.cs
===================================================================
--- branches/font/Tests/Fonts/TextLayout/TextLayout.cs 2009-04-25 07:39:00 UTC (rev 912)
+++ branches/font/Tests/Fonts/TextLayout/TextLayout.cs 2009-04-25 17:46:09 UTC (rev 913)
@@ -47,7 +47,10 @@
font.DrawText(0, 300, "Test InlineBottom:\n{0}Test Layout {0} Text\nTest second line.",
AgateLib.InternalResources.Data.PoweredBy);
-
+ font.DrawText(0, 450, "This is a test of the {0}AlterText{1} stuff." +
+ "The last word here should appear really {2}Large{3}.",
+ AlterFont.Color(Color.Green), AlterFont.Color(Color.Black),
+ AlterFont.Scale(3.0, 3.0), AlterFont.Scale(1.0, 1.0));
}
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|