PDA

View Full Version : Pascal and XNA...



savage
23-01-2007, 12:44 PM
I was just discussing with cairnswm about creating stuff with Pascal and XNA. Since Chrome 1.5 supports .NET 2.0 I thought I would quickly try and get a Hello world progam workin. This is the result...

http://upload5.postimage.org/329322/XNAandPascal.jpg (http://upload5.postimage.org/329322/photo_hosting.html)

0. Install .NET 2.0 and XNA Game Studio Express

1. Download the Free Chrome 1.5 command line compiler and install it

2. Create a file named XNADemo.pas and copy code as follows...



namespace XNADemo;

interface

uses
Microsoft.Xna.Framework,
Microsoft.Xna.Framework.Content,
Microsoft.Xna.Framework.Audio,
Microsoft.Xna.Framework.Graphics,
Microsoft.Xna.Framework.Input,
Microsoft.Xna.Framework.Storage;

type
TXNAGame = class(Microsoft.Xna.Framework.Game)
private
// these are the size of the output window, ignored on Xbox 360
preferredWindowWidth : integer;
preferredWindowHeight : integer;

graphics : GraphicsDeviceManager;

class content : ContentManager;
protected
method Initialize; override;
method BeginRun; override;
method Update( gameTime : Gametime ); override;
method BeginDraw : boolean; override;
method Draw( gameTime : Gametime ); override;
method EndDraw; override;
method LoadGraphicsContent( loadAllContent : boolean ); override;
method UnloadGraphicsContent( unloadAllContent : boolean ); override;
public
constructor;

// Entry point into this object.
class method Main;
end;

implementation

constructor TXNAGame;
begin
inherited;
preferredWindowWidth := 320;//1280;
preferredWindowHeight := 240;//720;

Self.graphics := new Microsoft.Xna.Framework.GraphicsDeviceManager(Self );
Self.graphics.PreferredBackBufferWidth := preferredWindowWidth;
Self.graphics.PreferredBackBufferHeight := preferredWindowHeight;
end;

class method TXNAGame.Main;
begin
try
// probably should not be instantiating an object within itself :).
with lGame := new TXNAGame do
lGame.Run;
except
on E: Exception do
begin
// MessageBox.Show(E.Message);
end;
end;
end;

method TXNAGame.Initialize;
begin
// Your Initialize Code here
Window.Title := 'Pascal and XNA';

inherited;
end;

method TXNAGame.BeginRun;
begin
// Your BeginRun Code here
inherited;
end;

method TXNAGame.Update( gameTime : Gametime );
begin
// Allows the default game to exit on Xbox 360 and Windows
if (GamePad.GetState(PlayerIndex.One).Buttons.Back = ButtonState.Pressed) then
Self.Exit();

// Your Update Code here

inherited Update( gameTime );
end;

method TXNAGame.BeginDraw : boolean;
begin
if not ( inherited BeginDraw ) then
begin
result := false;
exit;
end;

// Your BeginDraw Code here

result := true;
end;

method TXNAGame.Draw( gameTime : Gametime );
begin
graphics.GraphicsDevice.Clear( Color.CornflowerBlue );

inherited Draw( gameTime );

// Your Draw Code here

end;

method TXNAGame.EndDraw;
begin
// Your EndDraw Code here

inherited;
end;

method TXNAGame.LoadGraphicsContent( loadAllContent : boolean );
begin
if (loadAllContent) then
begin
// TODO: Load any ResourceManagementMode.Automatic content
end;

// TODO: Load any ResourceManagementMode.Manual content

end;

method TXNAGame.UnloadGraphicsContent( unloadAllContent : boolean );
begin
if (unloadAllContent) then
begin
content.Unload;
end;
end;

end.


3. At the command line type


Chrome XNADemo.pas /frameworkversion:v2.0.50727 /ref:"C:\Program Files\Microsoft XNA\XNA Game Studio Express\v1.0\References\Windows\x86\Microsoft.Xna. Framework.dll" /ref:"C:\Program Files\Microsoft XNA\XNA Game Studio Express\v1.0\References\Windows\x86\Microsoft.Xna. Framework.Game.dll"


If all goes well you should have an XNADemo.exe file ready to run. This will display a blank screen with the Window title "Pascal and XNA"!

Remember this is Chrome Object Pascal, which is slightly different to CodeGear Object Pascal

tanffn
23-01-2007, 12:50 PM
An impressive black window :wink:

savage
23-01-2007, 12:58 PM
An impressive black window :wink:

I've been told I create the best black windows in the business.

Traveler
23-01-2007, 01:03 PM
Perhaps a silly question but does this mean we can develop for Xbox 360?

Luuk van Venrooij
23-01-2007, 01:14 PM
.net 2.0 executables should be able to run on the XBOX 360. THis is a pretty sweet find savage :).

savage
23-01-2007, 01:38 PM
Perhaps a silly question but does this mean we can develop for Xbox 360?

In theory, that is the case.

Taken from a google ]
The cash cow is XNA Creators Club, an Xbox Live-hosted service that Microsoft hopes budding developers will turn to for help, white papers, game assets offered not only by Microsoft but also by third-parties, forums and the like. More to the point, coders won't be able to deliver games to Xbox 360 owners without coughing up to Microsoft.

In addition to the $99 annual subscription, purchased through Xbox Live Marketplace, Microsoft is also offering a $49 four-month sub. Membership will allow developers to offer finished games through Xbox Live Arcade.

Downloaders will require a console fitted with a hard drive and likewise be an XNA Creators Club member, Microsoft's XNA FAQ reveals. That's because creators don't share the game but the assets and source code, which the recipient must then compile into an Xbox 360-friendly format. Xbox 360 games must be offered on non-commercial terms, Microsoft added, though XNA can be used to develop commercial titles for Windows.

"Games developed using XNA Game Studio Express cannot be shared through a memory card or CD/DVD at this time," the software giant warned.
[/quote]

Someone would need to investigate this further. I would if I had an XB360 but I don't and only plan on getting a PS3 when that is released in the UK.

jdarling
23-01-2007, 02:19 PM
http://blogs.msdn.com/coding4fun/archive/2007/01/18/1491742.aspx

I'll also ask around and see what I can find out about doing this outside of VisualStudios. The link above at least explains how to do it within VisualStudios (witch can be used with Chrome).

cairnswm
23-01-2007, 03:04 PM
If I can get a Pascal Program running on an XBox360 I might actually buy one!

I've already converted my S2DL framework over to C# and XNA Game Studio Express. If I can use Pascal instead I will also convert to Chrome and XNA.

I use ConTEXT as my editor of choice for command line compilers - I will try set it up tonight to compile and run the program with F9. If I can I pretty much have enough to start writing XBox games :)

Well done Savage!

savage
23-01-2007, 03:09 PM
using /ref: switch in Chrome you should be able to link to the XBox versions of the Xna.* Assemblies which are installed when XNA Game Studio Express is installed. So I think it should theoretically be possible to use Chrome to create an XB360 exe.

There are some tutorial videos that show how to load 3D objects etc over @ http://blogs.msdn.com/xna/archive/2006/12/13/xna-game-studio-express-video-tutorials-available.aspx
but you should be able to keep up to date by checking
http://blogs.msdn.com/xna/
regularly

WILL
23-01-2007, 04:37 PM
Am I going to have to put XBox360 in the description for the 'Console Development' forum? :)

NecroDOME
23-01-2007, 07:16 PM
(Very offtopic:)
@savage - Oh great master of black windows! Could you make a yellow window for me?

cairnswm
23-01-2007, 08:21 PM
Actually I dont think the screen was being cleared at all - I had a black screen with some very retro looking blocks all over it :)

Change the GraphicsDevice.Clear statement to

graphics.GraphicsDevice.Clear( Color.CornflowerBlue );

and you'll have the correct CornFlower blue of the empty XNA GSE base project.

:)

savage
23-01-2007, 09:39 PM
Actually I dont think the screen was being cleared at all - I had a black screen with some very retro looking blocks all over it :)

Change the GraphicsDevice.Clear statement to

graphics.GraphicsDevice.Clear( Color.CornflowerBlue );

and you'll have the correct CornFlower blue of the empty XNA GSE base project.

:)

I've changed the above base code as mentioned, though it would be nice to know why the other Clear code does not work.

savage
23-01-2007, 09:40 PM
(Very offtopic:)
@savage - Oh great master of black windows! Could you make a yellow window for me?

I'm sorry NecroDOME I only specialise in black windows. Yellow windows are just so 80s.

savage
29-01-2007, 09:44 AM
OK I finally worked out what I was doing wrong with the 3D stuff. Basically XNA expects XNA specific compatible 3D resources and audio file to load correctly. Once that was established it works like a charm ( as seen below )


http://upload5.postimage.org/407061/XNAandPascalTut1.jpg (http://upload5.postimage.org/407061/photo_hosting.html)

This rotating 3D model is very, and I mean very, easy to get working.

I've spoken to the people at RemObjects and they are keen to have these demos, and a few more, showing off Chrome's XNA and .NET 2.0 compatibility. They would like a game project template for XNA and they are speaking to Microsoft about what is required to get these Chrome created Exes working on an XBox 360.

cairnswm
29-01-2007, 09:51 AM
I'll get my S2DL for Chrome and XNA done by the end of the week including a 2D game template :) Can you speak to them about using this as a base 2D game system for Chrome?

savage
29-01-2007, 01:42 PM
William, I'll ask them and will see what they say. I might make a vanilla version as well so that developers know what is going on under the hood for starters.

Btw, here is the latest Pascal and XNA files -
http://www.pascalgamedevelopment.com/files/XNA.zip ( Updated and working ).

This contains the 3 3D tutorials ported to Chrome with relevant executable and data files necessary. Proper Keyboard handling has been added because by default it assumes an Xbox 360 GamePad is attached to your computer.
Therefore now in the 3rd Tutorial you can use the Up arrow to accelerate and hear the thrusters firing. Left and Right arrow will roate you in those directions and Space bar will warp you back to the centre of the screen ( with sound ).
As these now have a .chrome project file you can just compile the code at the command line as follows :


Chrome /frameworkversion:v2.0.50727

Assuming you have a .chrome file in that directory, it will find it and compile it using the .NET 2.0.

Note1 : The command line compiler compiles .chrome projects into the /Release subdirectory by default.

Note2 : XNA demos/games will only work if your graphics card supports shader model 1.1 or above. The reference rasterizer does not appear to work, without jumping through a few hoops :(.

WILL
29-01-2007, 03:16 PM
http://upload5.postimage.org/407061/XNAandPascalTut1.jpg (http://upload5.postimage.org/407061/photo_hosting.html)

This rotating 3D model is very, and I mean very, easy to get working.

I've spoken to the people at RemObjects and they are keen to have these demos, and a few more, showing off Chrome's XNA and .NET 2.0 compatibility. They would like a game project template for XNA and they are speaking to Microsoft about what is required to get these Chrome created Exes working on an XBox 360.

This is very cool. Looks like Chrome has just found a means to be a top contender for the Object Pascal coding market. XBox360 would be a welcomed addition to the platforms you can make game in Pascal with.

Might I ask if either of you guys know what the max. capabilities of XNA on a 360 would be?

cairnswm
29-01-2007, 07:03 PM
As far as I know XNA makes use of the .Net compact framework as available on the XBox 360. Also remember that XNA replaces DirectX - so should give an indication of its capabilities.

Try this: http://www.gamasutra.com/features/20061215/sheffield_01.shtml

jdarling
29-01-2007, 07:27 PM
As far as I know XNA makes use of the .Net compact framework as available on the XBox 360. Also remember that XNA replaces DirectX - so should give an indication of its capabilities.

Try this: http://www.gamasutra.com/features/20061215/sheffield_01.shtml

XNA doesn't replace DirectX, it simply wraps up the features of DirectX and hides them from view. DirectX 10 still exists, and 11 is in the planning stages already.

BTW: Using SDL inside of an XNA game would make the game invalid on the XBOX 360. You have to use the built in XNA graphical methods in order to cross compile for the XBOX :(. Good news is, if you use XNA then your game will run on Windows, Windows CE, Windows Mobile, and XBOX. Bad news is, if you use XNA, then your game won't compile for WII, PS3, MAC, Linux, and other platforms not supported by MS. Of course, this may change as people start to adopt XNA and build out their own environments for the platforms. Just look at Mono.

savage
29-01-2007, 07:37 PM
Might I ask if either of you guys know what the max. capabilities of XNA on a 360 would be?

Benjamin Nitschke is pretty much at the forefront of XNA development from an indie point of view. Check out his blog at http://exdream.no-ip.info/blog/
In particular have look at Top down shooter video and also the XNA Racer screen shots that are all supposed to run on an XNA 360 at 1080p resolution. Another one of his game called XNA Rocket Commander come with full source code and the shooter and Racer game will also come with full source when his book is released.

Here is the top down shooter :
<object width="320" height="240"><param name="movie" value="http://www.youtube.com/v/3dlBRX6BHdU"></param><embed src="http://www.youtube.com/v/3dlBRX6BHdU" type="application/x-shockwave-flash" width="320" height="240"></embed></object>

All seem to run at a fairly decent pace on the XBox 360. The main caveat he mentions is that don't create things dynamically on the XBox and don't use For Each loops as this really slows things down. He lists other tips and gripes he has about XNA compared to MDX.

Clootie
29-01-2007, 08:41 PM
Little offtopic:
Some marketing managers @ Microsoft decided to make our life more complicated. Remember ".NET"? Probably the same person got his hands on graphics division of MS.
Seems in this year everything game/graphics related will be called XNA! So, even MS DirectX is now [probarbly will be] XNA DirectX.

So, it's better to start describing things more extensively (not just XNA) to avoid further confusion:
* XNA Game Studio Express
* XNA Framework
* XNA Build

PS.

Q: Does the XNA Framework support Windows and Pocket PC devices?
A: The XNA Framework currently does not support Windows Mobile or Pocket PC devices, but based on customer feedback this may be a direction we expand the XNA Framework in the future. We know that developing mobile games is a hot area of growth and one we would like to support in the future.

Sly
29-01-2007, 10:33 PM
PS.

Q: Does the XNA Framework support Windows and Pocket PC devices?
A: The XNA Framework currently does not support Windows Mobile or Pocket PC devices, but based on customer feedback this may be a direction we expand the XNA Framework in the future. We know that developing mobile games is a hot area of growth and one we would like to support in the future.
With handheld devices you generally don't want a lot of baggage in your code. Based on what Benjamin Nitschke wrote in his blog, creating objects at run-time and using the for-each loop sound like a lot of baggage if they slow down the Xbox 360.

bigsofty
30-01-2007, 03:38 AM
Very impressive piece of work.

jdarling
30-01-2007, 02:46 PM
PS.

Q: Does the XNA Framework support Windows and Pocket PC devices?
A: The XNA Framework currently does not support Windows Mobile or Pocket PC devices, but based on customer feedback this may be a direction we expand the XNA Framework in the future. We know that developing mobile games is a hot area of growth and one we would like to support in the future.

All I can say is watch for Crossbow. Full support for XNA, probably not, but there will be support. The key statement is "Currrently does not".

savage
30-01-2007, 04:12 PM
All I can say is watch for Crossbow.

Can you clarify what "Crossbow" is, apart from the obvious.

jdarling
30-01-2007, 05:07 PM
Can you clarify what "Crossbow" is, apart from the obvious.

Next generation of Windows Mobile (WM6). More support for .NET applications coming with it then exists with WM5 currently. Embedded has a similar project, overall MS is trying to bridge the gap in development across their platforms within the next few releases of all platforms.

savage
31-01-2007, 02:56 PM
Here's another XNA arcade style game which I thought looked ok...

<object height="300" width="320"><param name="movie" value="http://www.youtube.com/v/BRQW960EgwE"><embed src="http://www.youtube.com/v/BRQW960EgwE" type="application/x-shockwave-flash" width="320" height="300"></embed></object>

The developer ( http://shmup.blogspot.com/ ) says it took him 5 months to put together.

cairnswm
31-01-2007, 07:31 PM
I'd like to see more of his engine and its functionalities.

savage
05-02-2007, 12:12 PM
OK guys, this is probably the last update to the XNA demos until RemObjects sort out the Visual Studio IDE issues.

Here are the latest Pascal and XNA files -
http://www.pascalgamedevelopment.com/files/XNA.zip

This version of the demos is based on the Chrome Project templates that I have created. Each tutorial contains a Build.bat file in an attempt to simplify the compilation of .chrome files via the command line.

NOTE : the .chrome files will compile from within VS 2005, but it will not convert any attached resource correctly. This works correctly when using MSBuild via the command line however.

The key to getting resources compiling correctly, until RemObject provide and automated way of doing it is to amend the .chrome. Follow the following steps...

1. Add your resource to the project as per normal with VS2005 ( if you don't have VS 2005 and only have the command line compiler skip to step 2 ). If the resource is added correctly, save the project.

2. Open up the project's .chrome file in a text editor. A .chrome file is just a XML file that MSbuild understands. In it you should have a line that looks something like this...


<Content Include="Content\Models\p1_wedge.fbx" />

or whatever the resource name path and extention are.

For MSBuild to correctly convert this resource into an XNA resource, you need to change this to...



<Content Include="Content\Models\p1_wedge.fbx">
<XNAUseContentPipeline>true</XNAUseContentPipeline>
<Importer>FbxImporter</Importer>
<Processor>ModelProcessor</Processor>
<Name>p1_wedge</Name>
</Content>


for a .fbx model file. Notice the Importer and Processor tags.

If you have added an XACT file then it should look something like this...



<Content Include="Content\Audio\MyGameAudio.xap">
<XNAUseContentPipeline>true</XNAUseContentPipeline>
<Importer>XactImporter</Importer>
<Processor>XactProcessor</Processor>
<Name>MyGameAudio</Name>
</Content>


and for Textures, something like...



<Content Include="Content\Textures\wedge_p1_diff_v1.tga">
<XNAUseContentPipeline>true</XNAUseContentPipeline>
<Importer>TextureImporter</Importer>
<Processor>SpriteTextureProcessor</Processor>
<Name>wedge_p1_diff_v1</Name>
</Content>


The Name property is what you will be accessing within your code after the resource has been converted.

Once done save the .chrome file. If you have any doubts use Tutorial3.chrome as a base project file and work from there.

3. Build the .chrome project via the command line. You will need to find the path to MSBuild.exe. Mine looks like this...


%windir%\Microsoft.NET\Framework\v2.0.50727\MSBuil d.exe MyProject.chrome

This should build your project in the bin\x86\Release directory.

That's it, run the exe and enjoy.

If anyone has any questions, let me know.

savage
07-02-2007, 04:36 PM
One thing that Nitschke wrote was that you shouldn't use foreach contruct when developing in C# as it is really slow due to an error in the XBox 360 Garbage Collector. Instead of the Draw routine that was previously posted, should probably use something like this...


method TTutorial3.Draw( gameTime : Gametime );
var
transforms : array of Matrix;
mesh : ModelMesh;
effect : BasicEffect;
i, x : integer;
begin
graphics.GraphicsDevice.Clear( Color.CornflowerBlue );

//Copy any parent transforms
transforms := new Matrix[ myModel.Bones.Count ];
myModel.CopyAbsoluteBoneTransformsTo( transforms );

//Draw the model, a model can have multiple meshes, so loop
// use normal for loop rather than for each as it is faster.
for i := 0 to myModel.Meshes.Count - 1 do
begin
mesh := myModel.Meshes[ i ];
//This is where the mesh orientation is set, as well as our camera and projection
for x := 0 to mesh.Effects.Count - 1 do
begin
effect := BasicEffect( mesh.Effects[ x ] );
effect.EnableDefaultLighting;
effect.World := transforms[ mesh.ParentBone.Index ] * Matrix.CreateRotationY( modelRotation ) * Matrix.CreateTranslation( modelPosition );
effect.View := Matrix.CreateLookAt( cameraPosition, Vector3.Zero, Vector3.Up );
effect.Projection := Matrix.CreatePerspectiveFieldOfView( MathHelper.ToRadians( 45.0 ), aspectRatio, 1.0, 10000.0 );
end;

//Draw the mesh, will use the effects set above.
mesh.Draw( );
end;

inherited Draw( gameTime );
end;

savage
07-03-2007, 04:13 PM
http://upload7.postimage.org/86590/3DTank.jpg (http://upload7.postimage.org/86590/photo_hosting.html)

Hi Guys, I've uploaded another example of Chrome with XNA, this time it's a 3D WWI ( I think ) animated tank. It is based on a sample from http://creators.xna.com.

You can download the current demo from
http://www.pascalgamedevelopment.com/files/SimpleAnimation.zip ( about 23MB due to large textures and the crappy content pipeline format ), and if you have XNA runtimes installed it includes an exe for you to see it in action.

I have taken the aforementioned sample and enhanced it slightly with the following capabilities :
* Left and Right arrows turn the steering left and right.
* Up and Down arrows give the tank velocity and move it ( not working correctly ).
* Moving the mouse Left and Right rotates the turret 360 degrees
* Moving the mouse Forward and Backwards raises and lowers the Turret.

It is while working with this sort of 3D stuff that make me feel inadequate. I really need to sort out my lack of knowledge of 3D maths with regard to rotations and transformations.

For example I would like allow the user to drive the tank around, but I don't know how to work out the correct model rotation and position based on the steering angle and the velocity of the model.

If anyone can point out how I can do this in simple child like maths terms, that would be great.

NecroDOME
08-03-2007, 09:38 AM
Use a physics engine?

savage
08-03-2007, 09:47 AM
Could do, but I want to understand it first. I did that sort of thing with ODE, but didn't really understand what was going on in the back ground.

Huehnerschaender
08-03-2007, 01:07 PM
I don't know if I understand everything right...

But basically in TANX I did those kind of calculations by just having some values for speed, angle, turretangle, position etc. Nearly all calculations are done in 2D in Tanx, because I had a plain terrain there. Only when things exploded, the Z-value came into calculation for position (things flying to camera).

So, when pressing left/right keys you should alter angle. When moving the mouse left/right you should alter turretangle. Pressing up/down would alter speed (velocity).

Thats all you need in the first place.

Calculation of new position would be something like this:

Pos.x := Pos.x + sin(angle) * speed;
Pos.y := Pos.y + cos(angle) * speed;

Thats all to move the tank.

rotation of you model is given by angle, too.
rotation of your turret is given by angle+turretangle, because you want the turret to move too when you turn the tank, don't you?

Then when rendering the model its just something like this:

ClearWorldMatrix;
RotateWorldY(tank.angle);
TranslateWorld(tank.x,tank.y,tank.z);
DrawTankCorpse;

ClearWorldMatrix;
RotateWorldY(tank.angle+tank.turretangle);
TranslateWorld(tank.x,tank.y,tank.z);
DrawTankTurret;

All this is written out of my head in PseudoCode. I did not test anything, but basically this should enable you to turn and move your tank.

Hope that helps. If there are further questions... you know where to find me :)

savage
08-03-2007, 02:20 PM
Hi Dirk,
Thanks for the explanation. That makes sense a tank on tracks, but would that work for a tank that steers more like a car? Could I not need something like a turning circle in this case?

Huehnerschaender
08-03-2007, 02:27 PM
yes, this should work, because you multiply with the speed. so is the tank is not moving, its position will not change. only thing you should multiply with speed too is the angle you add when rotating. so no movement no rotation.

Huehnerschaender
08-03-2007, 03:41 PM
Great!! ;)

Is the "animation" already controlled by your manual input?

WILL
08-03-2007, 05:20 PM
<object width="640" height="480"><param name="movie" value="http://www.youtube.com/v/CG-n0alspek"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/CG-n0alspek" type="application/x-shockwave-flash" wmode="transparent" width="640" height="480"></embed></object>

savage
08-03-2007, 07:22 PM
Thanks WILL! Pity the Pascal code is not very visible. I'm going to post a link on the MSDN forums and see what they say.

@Huehnerschaender : Turret and Cannon movement is mouse controlled, steering is keyboard controlled. Wheels are rotating arbitrarily.
I still need to add the steering code you mentioned earlier. This video was taken before you answered by question.

savage
09-03-2007, 09:02 AM
Here's an article that shows one way that could be used to get a Chrome game onto an XBox 360.
http://grammerjack.spaces.live.com/blog/cns!F2629C772A178A7C!158.entry

It basically involves make your game an assembly, then writing a C# dummy project in GSE that just calls your Chrome Game.main function and it should just work assuming everything else is setup correctly.

Also if you want to know what people who know what they are doing can do with XNA in 4 days, check out Ben's entry into the GDC XNA Challenge. He tried to write a 3rd person RPG in 4 days. You can check out what he managed to do by visiting http://abi.exdream.com

savage
09-03-2007, 03:05 PM
Ok I've tried a few things, but it's just not working correctly :(.

This is the current state of the UpdateInput method.
Currently when I press left or right without moving the model just rotates on the spot, it's a bit more realistic when it's moving, but still not perfect.

Any ideas?


method TTank.UpdateInput( aGameTime : Gametime; aGamePadState : GamePadState; aKeyboardState : KeyboardState; aMouseState : MouseState ) : boolean;
var
tankVelocityAdd : Vector3;
lTimeSeconds : single;
lTimeMilliSeconds : single;
begin
result := true;
lTimeMilliSeconds := aGameTime.ElapsedGameTime.TotalMilliseconds;
lTimeSeconds := aGameTime.TotalGameTime.TotalSeconds;

{$REGION GamePad}
if ( aGamePadState.IsConnected ) then
begin
// Allows the default game to exit on Xbox 360 and Windows using a Gamepad
if ( aGamePadState.Buttons.Back = ButtonState.Pressed ) then
begin
result := false;
Exit;
end;

//rotate the model using the left thumbstick, scale it down
tankRotation := tankRotation - aGamePadState.ThumbSticks.Left.X * 0.10;

//create some velocity if the right trigger is down
tankVelocityAdd := Vector3.Zero;

//find out what direction we should be thrusting, using rotation
tankVelocityAdd.X := -Math.Sin( tankRotation );
tankVelocityAdd.Z := -Math.Cos( tankRotation );

//now scale our direction by how hard the trigger is down
tankVelocityAdd := tankVelocityAdd * aGamePadState.Triggers.Right;

//finally, add this vector to our velocity.
tankVelocity := tankVelocity + tankVelocityAdd;

GamePad.SetVibration( PlayerIndex.One, aGamePadState.Triggers.Right, aGamePadState.Triggers.Right );

//in case you get lost, press A to warp back to the center
if ( aGamePadState.Buttons.A = ButtonState.Pressed ) then
begin
tankPosition := Vector3.Zero;
tankVelocity := Vector3.Zero;
tankRotation := 0.0;
end;
end;
{$ENDREGION}

{$REGION Keyboard}
if Assigned( aKeyboardState ) then
begin
// Allows the default game to exit on Xbox 360 and Windows using a Keyboard
if ( aKeyboardState.IsKeyDown( Keys.Escape ) ) then
begin
result := false;
Exit;
end;

//in case you get lost, press Spacebar to warp back to the center
if ( aKeyboardState.IsKeyDown( Keys.Space ) ) then
begin
//Key has just been pressed
tankPosition := Vector3.Zero;
tankVelocity := Vector3.Zero;
tankRotation := 0.0;
end;
// otherwise, check to see we are moving left, right forward backward
// (and therefore just released)
if ( aKeyboardState.IsKeyDown( Keys.Left ) ) then
begin
// Rotate Left
steerRotationValue := steerRotationValue + ( lTimeMilliSeconds * MathHelper.ToRadians( 0.1 ) );
end
else if ( aKeyboardState.IsKeyDown( Keys.Right ) ) then
begin
// Rotate Right
steerRotationValue := steerRotationValue - ( lTimeMilliSeconds * MathHelper.ToRadians( 0.1 ) );
end;

// Restrict how much we can steer the wheels
steerRotationValue := MathHelper.Clamp( steerRotationValue, -0.8, 0.8 );

// Change our TankRotation
tankRotation := tankRotation - steerRotationValue * 0.10;

if ( aKeyboardState.IsKeyDown( Keys.Up ) ) then
begin
//create some velocity if the up key is pressed
tankVelocityAdd := Vector3.Zero;

//find out what direction we should be thrusting, using rotation
tankVelocityAdd.X := -Math.Sin( tankRotation );
tankVelocityAdd.Z := -Math.Cos( tankRotation );

// scale velocity
tankVelocityAdd := tankVelocityAdd / ( lTimeMilliSeconds * MathHelper.ToRadians( 0.5 ) );

// Move Forward
tankVelocity := tankVelocity + tankVelocityAdd;
end
else if ( aKeyboardState.IsKeyDown( Keys.Down ) ) then
begin
//reduce our velocity if the down key is pressed
tankVelocityAdd := Vector3.Zero;

//find out what direction we should be thrusting, using rotation
tankVelocityAdd.X := -Math.Sin( tankRotation );
tankVelocityAdd.Z := -Math.Cos( tankRotation );

// scale velocity
tankVelocityAdd := tankVelocityAdd / ( lTimeMilliSeconds * MathHelper.ToRadians( 0.5 ) );

// Move Forward
tankVelocity := tankVelocity - tankVelocityAdd;
end;

if ( aKeyboardState.IsKeyDown( Keys.H ) ) then
begin
openHatch := not openHatch;
end;
end;
{$ENDREGION}

{$REGION Mouse}
if Assigned( aMouseState ) then
begin
currentMouseX := aMouseState.X;
currentMouseY := aMouseState.Y;
if ( previousMouseX <currentMouseX> previousMouseX ) then
turretRotationValue := turretRotationValue + ( lTimeMilliSeconds * MathHelper.ToRadians( 0.1 ) )
else
turretRotationValue := turretRotationValue - ( lTimeMilliSeconds * MathHelper.ToRadians( 0.1 ) );
previousMouseX := currentMouseX;
end;

if ( previousMouseY <currentMouseY> previousMouseY ) then
cannonElevationValue := cannonElevationValue + ( lTimeMilliSeconds * MathHelper.ToRadians( 0.1 ) )
else
cannonElevationValue := cannonElevationValue - ( lTimeMilliSeconds * MathHelper.ToRadians( 0.1 ) );

// Restrict how much we can raise and lower the cannon
cannonElevationValue := MathHelper.Clamp( cannonElevationValue, -1.4, 0.2 );
previousMouseY := currentMouseY;
end;
end;
{$ENDREGION}

wheelRotationValue := tankVelocity.Z;

if openHatch then
hatchRotationValue := hatchRotationValue - ( lTimeMilliSeconds * MathHelper.ToRadians( 0.1 ) )
else
hatchRotationValue := hatchRotationValue + ( lTimeMilliSeconds * MathHelper.ToRadians( 0.1 ) );

// Limit how wide we open
hatchRotationValue := MathHelper.Clamp( hatchRotationValue, -1, 0 );

//add velocity to current position
tankPosition := tankPosition + tankVelocity;

//bleed off velocity over time
tankVelocity := tankVelocity * 0.95;
end;

JSoftware
09-03-2007, 03:54 PM
method TTank.UpdateInput( aGameTime : Gametime; aGamePadState : GamePadState; aKeyboardState : KeyboardState; aMouseState : MouseState ) : boolean;
var
tankVelocityAdd : Vector3;
lTimeSeconds : single;
lTimeMilliSeconds : single;
lVelocity: single;
begin
result := true;
lTimeMilliSeconds := aGameTime.ElapsedGameTime.TotalMilliseconds;
lTimeSeconds := aGameTime.TotalGameTime.TotalSeconds;

{$REGION GamePad}
if ( aGamePadState.IsConnected ) then
begin
// Allows the default game to exit on Xbox 360 and Windows using a Gamepad
if ( aGamePadState.Buttons.Back = ButtonState.Pressed ) then
begin
result := false;
Exit;
end;

//rotate the model using the left thumbstick, scale it down
tankRotation := tankRotation - aGamePadState.ThumbSticks.Left.X * 0.10;

//create some velocity if the right trigger is down
tankVelocityAdd := Vector3.Zero;

//find out what direction we should be thrusting, using rotation
tankVelocityAdd.X := -Math.Sin( tankRotation );
tankVelocityAdd.Z := -Math.Cos( tankRotation );

//now scale our direction by how hard the trigger is down
tankVelocityAdd := tankVelocityAdd * aGamePadState.Triggers.Right;

//finally, add this vector to our velocity.
tankVelocity := tankVelocity + tankVelocityAdd;

GamePad.SetVibration( PlayerIndex.One, aGamePadState.Triggers.Right, aGamePadState.Triggers.Right );

//in case you get lost, press A to warp back to the center
if ( aGamePadState.Buttons.A = ButtonState.Pressed ) then
begin
tankPosition := Vector3.Zero;
tankVelocity := Vector3.Zero;
tankRotation := 0.0;
end;
end;
{$ENDREGION}

{$REGION Keyboard}
if Assigned( aKeyboardState ) then
begin
// Allows the default game to exit on Xbox 360 and Windows using a Keyboard
if ( aKeyboardState.IsKeyDown( Keys.Escape ) ) then
begin
result := false;
Exit;
end;

//in case you get lost, press Spacebar to warp back to the center
if ( aKeyboardState.IsKeyDown( Keys.Space ) ) then
begin
//Key has just been pressed
tankPosition := Vector3.Zero;
tankVelocity := Vector3.Zero;
tankRotation := 0.0;
end;
// otherwise, check to see we are moving left, right forward backward
// (and therefore just released)
if ( aKeyboardState.IsKeyDown( Keys.Left ) ) then
begin
// Rotate Left
steerRotationValue := steerRotationValue + ( lTimeMilliSeconds * MathHelper.ToRadians( 0.1 ) );
end
else if ( aKeyboardState.IsKeyDown( Keys.Right ) ) then
begin
// Rotate Right
steerRotationValue := steerRotationValue - ( lTimeMilliSeconds * MathHelper.ToRadians( 0.1 ) );
end;

// Restrict how much we can steer the wheels
steerRotationValue := MathHelper.Clamp( steerRotationValue, -0.8, 0.8 );

if ( aKeyboardState.IsKeyDown( Keys.Up ) ) then
begin
lVelocity := 1;
end
else if ( aKeyboardState.IsKeyDown( Keys.Down ) ) then
begin
lVelocity := -1;
end;

tankVelocityAdd := Vector3.Zero;
tankVelocityAdd.X := Math.Sin(steerRotationValue+tankRotation)*lVelocit y;
tankVelocityAdd.Z := Math.Cos(steerRotationValue+tankRotation)*lVelocit y;

tankVelocity := Vector3.Dot(Vector3.Normalize(tankVelocity), Vector3.Normalize(tankVelocityAdd))*tankVelocity;

tankVelocity := (tankVelocity+tankVelocityAdd) / ( lTimeMilliSeconds * MathHelper.ToRadians( 0.5 ) );

// Change our TankRotation
tankRotation := tankRotation - sin(steerRotationValue) * Vector3.Length(tankVelocity) / ( lTimeMilliSeconds * MathHelper.ToRadians( 0.5 ) );

if ( aKeyboardState.IsKeyDown( Keys.H ) ) then
begin
openHatch := not openHatch;
end;
end;
{$ENDREGION}

{$REGION Mouse}
if Assigned( aMouseState ) then
begin
currentMouseX := aMouseState.X;
currentMouseY := aMouseState.Y;
if ( previousMouseX <currentMouseX> previousMouseX ) then
turretRotationValue := turretRotationValue + ( lTimeMilliSeconds * MathHelper.ToRadians( 0.1 ) )
else
turretRotationValue := turretRotationValue - ( lTimeMilliSeconds * MathHelper.ToRadians( 0.1 ) );
previousMouseX := currentMouseX;
end;

if ( previousMouseY <currentMouseY> previousMouseY ) then
cannonElevationValue := cannonElevationValue + ( lTimeMilliSeconds * MathHelper.ToRadians( 0.1 ) )
else
cannonElevationValue := cannonElevationValue - ( lTimeMilliSeconds * MathHelper.ToRadians( 0.1 ) );

// Restrict how much we can raise and lower the cannon
cannonElevationValue := MathHelper.Clamp( cannonElevationValue, -1.4, 0.2 );
previousMouseY := currentMouseY;
end;
end;
{$ENDREGION}

wheelRotationValue := tankVelocity.Z;

if openHatch then
hatchRotationValue := hatchRotationValue - ( lTimeMilliSeconds * MathHelper.ToRadians( 0.1 ) )
else
hatchRotationValue := hatchRotationValue + ( lTimeMilliSeconds * MathHelper.ToRadians( 0.1 ) );

// Limit how wide we open
hatchRotationValue := MathHelper.Clamp( hatchRotationValue, -1, 0 );

//add velocity to current position
tankPosition := tankPosition + tankVelocity;

//bleed off velocity over time
tankVelocity := tankVelocity * 0.95;
end;


I just altered it quite a bit. This may work or it may not. I was only awake while I rewrote half of it :P

savage
10-03-2007, 05:15 PM
Thanks JSoftware, I'll try it on my work machine on Monday.

My book should arrive this week, so hopefully I won't bother you guys so much with this 3D stuff.

savage
28-04-2007, 11:17 AM
More XNA Samples have been posted on the creators site - http://creators.xna.com/Education/Samples.aspx as well as a full 3D Racing Car game available as a Starter Kit from http://creators.xna.com/Education/StarterKits.aspx
The racing game looks quite professional and comes with full source code.

There's less and less excuse not to use XNA now with Chrome.

WILL
28-04-2007, 04:33 PM
I'm thinking XNA Starters Kit Translation project. ;)

savage
29-04-2007, 09:11 PM
Here's a screen shot of the racing game in action...
http://arenawars.net/XnaRacingGame/Images/RacingGameScreenshotBig03_small.jpg ('http://arenawars.net/XnaRacingGame/Images/RacingGameScreenshotBig03.jpg')
[ Click to see a bigger picture ]

It runs at 90 FPS on my machine at 1024 * 768 with all the effects on. I've read it runs equally well on the XBox 360.

WILL
30-04-2007, 02:26 PM
Wow thats pretty cool. What are your system specs so we can compare?

As I alluded to before, someone should really consider a translation of this game's source to Object Pascal for Chrome. Or if not that create a game of their own that would look as or almost as good as this. :)

How compatible is Chrome with XNA right now?

savage
30-04-2007, 02:47 PM
Chrome as a compiler is 100% compatible with XNA. It you don't mind waiting for full XNA support in Visual 2005 ( NOT Express ), then you can start writing XNA code yesterday. The only issue is getting it only the XBox 360, but even that has a small work around until the support is built into VS2005.

I also think it would be nice to port this demo to Chrome, but I don't have the time right now to start another port project.

My system specs are the ones I posted when I bought the new motherboard, CPU and graphics card. The main thing is having Shader 2.0 or 3.0 support for most XNA stuff.

WILL
30-04-2007, 06:33 PM
Oh ok. I'd be a bit left behind with my 1.2 Shader I think. :)

What about the Command Line Edition ('http://www.chromesville.com/page.asp?id={537132C6-5B3A-4CF9-B3EB-087E7CEC25DB}#cmdline') of Chrome though? (It's FREE btw everyone! ;))

Are there things about XNA that would prevent someone from creating stuff made using that? I think in the worst case scenario one could make an IDE that took advantage of the command line compiler, much like how Lazarus does, but with whatever is required to get XNA games on the go. And who knows eventually XBox360 games too.

savage
30-04-2007, 08:07 PM
I am talking about both the Chrome command line compiler and the version that works within VS2005. The demos work with both. The thing that is a bit fiddly right now is adding resources to the project file. That needs to be done manually for now.

technomage
30-04-2007, 08:30 PM
What is the possibilty of having pascal code that can compile in both Delphi (win32) and Chrome?

I know Indy has ifdefs to handle .Net compalation, is something simalar possible with Chrome? I'm just wanders code it would be nice to have XNA support in the engine I am building...

savage
30-04-2007, 10:22 PM
The main IFDEF would look something like
{$IFDEF DELPHI}procedure{$ELSE}method{$ENDIF} MyfunctionOrProcedure();

Chrome does NOT have the concept of function/procedure only method.

Keep in mind that Chrome is working at .NET 2.0 so supports most of the features from that version and as such makes use of generics in XNA. Not to say that you couldn't work around this, but it would be a bit of a pain until Codgear add it to their Win32 and .NET compilers.

technomage
30-04-2007, 10:32 PM
Thanks for the hint Dom :D

I just got the following to compile and run under Chrome, Delphi and FPC.

ChromeDelphi.dpr

{$IFDEF CHROME}
namespace ChromeDelphi;
{$ELSE}
program ChromeDelphi;
{$APPTYPE CONSOLE}
{$ENDIF}

{$IFDEF CHROME}
interface

uses System.*;
{$ELSE}
uses Test;
{$ENDIF}

{$IFDEF CHROME}
type
ConsoleApp = class
private
public
class method Main(args: array of string);
end;
{$ENDIF}

{$IFDEF CHROME}
implementation
{$ENDIF}

var a: TTest;

{$IFDEF CHROME}
class method ConsoleApp.Main(args: array of string);
{$ENDIF}
begin

WriteLine('InfinitEngine Test');
a := TTest.Create;
a.doStuff;
ReadLine();
{$IFDEF CHROME}
end;
{$ENDIF}

end.



Test.pas

{$IFDEF CHROME}
namespace ChromeDelphi;
{$ELSE}
unit Test;
{$ENDIF}

interface

{$IFDEF CHROME}
uses System.*;
{$ELSE}
{$ENDIF}

type

TTestRecord = record
a: Integer;
end;

TTest = class
private
r: TTestRecord;
public
constructor Create;

procedure DoStuff; virtual;
end;

procedure WriteLine(s: string);
procedure ReadLine;

implementation

procedure WriteLine(s: string);
begin
{$IFDEF CHROME}
Console.WriteLine(s);
{$ELSE}
Writeln(s);
{$ENDIF}
end;

procedure ReadLine;
begin
{$IFDEF CHROME}
Console.ReadLine();
{$ELSE}
Readln;
{$ENDIF}
end;


constructor TTest.Create;
begin
inherited Create;
WriteLine('TTest.Create');
end;

procedure TTest.DoStuff;
begin
WriteLine('TTest.DoStuff');
end;


end.


Well impressed :D

savage
15-05-2007, 12:46 PM
Excellent Stuff Dean!

I just received my copy of Professional XNA Game Programming: For Xbox 360 and Windows (http://www.amazon.com/Professional-XNA-Game-Programming-Windows/dp/0470126779?tag=delphigamer02&camp=14573&creative=327641&linkCode=as1&creativeASIN=0470126779&adid=1BXP1XXS8NSD5MTP9N6D) so will start pouring over that this evening.

yassersoft
07-04-2008, 03:03 PM
Pascal you say. But .Net is from Microsoft. And that look like C# for me or I should say PAscal#??? :-)

WILL
07-04-2008, 03:54 PM
You should check out Chrome: www.remobjects.com

or of course, Delphi for .NET: www.codegear.com

Both will allow you to work with .NET in Object Pascal. However only Chrome will allow you to work with XNA as it's the only Object Pascal compiler to support the nessissary versions of .NET to do so.

savage
07-04-2008, 07:19 PM
Forget Delphi for .NET it really is not worth the time to use it as it is way way way behind Chrome's support.

WILL
07-04-2008, 08:32 PM
Well I agree, but I figured that I'd at least give them a fighting chance to be seen or heard of. lol

paul_nicholls
31-07-2008, 03:36 AM
Hi Savage, I wanted to download 1 or more of your XNA demo projects you wrote using Chrome hosted on pascalgamedevelopment, but they don't seem to be there anymore (too old I guess).

Is there anyway I can get hold of them someplace?

cheers,
Paul

cronodragon
31-07-2008, 01:42 PM
paul, here: http://chrome.pascalgamedevelopment.com/

paul_nicholls
31-07-2008, 10:56 PM
Thanks for that cronodragon :)

I'll take a look.
cheers,
Paul

pstudio
03-08-2008, 12:16 PM
I thought I might as well as my question in this topic instead of making a new one.

Do any of you have some good recomendations for books about XNA? I'm looking for something like, from intermediate to expert, kind of books. Not books trying to teach you programming, but books only focusing on game development using XNA.

paul_nicholls
03-08-2008, 11:11 PM
Hi pstudio,
I don't know about any books, but you could try the links below . They are C#, but still could be helpful :-)

http://creators.xna.com/
http://forums.xna.com/forums/
http://www.xnaresources.com/pages.asp?pageid=8

cheers,
Paul

yassersoft
17-11-2009, 04:04 PM
Where I get Free Chrome 1.5. I can¬Ąt Find It On Google.
Could you send me the link to yass3000gs@gmail.com?

pjpdev
17-11-2009, 04:48 PM
Where I get Free Chrome 1.5. I can¬Ąt Find It On Google.
Could you send me the link to yass3000gs@gmail.com?


I speak under correction here, but I don't think you can get chrome for free anymore. It's bundled with Delphi Prism.

noeska
17-11-2009, 05:57 PM
The commandline editions of delphi prism can be downloade for free here:
https://downloads.embarcadero.com/free/delphi_prism