Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!

1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


Member Since 19 Aug 2002
Offline Last Active Yesterday, 11:55 PM

#5226402 Need Some Assistance with XNA

Posted by Nypyren on 29 April 2015 - 07:26 PM

OK. The SpriteBatch class is only for sprites (sprites are 2D rectangles).

To draw a 3D model, you need to use something specific for that:


*** IMPORTANT NOTE: This is from XNA 3.1. If you're using a different version, google search for "XNA 3D model example", because things often change slightly between different versions, so the code might not even compile on a different version! ***

Quote taken from that example:
protected override void Draw(GameTime gameTime)

    // Copy any parent transforms.
    Matrix[] transforms = new Matrix[myModel.Bones.Count];

    // Draw the model. A model can have multiple meshes, so loop.
    foreach (ModelMesh mesh in myModel.Meshes)
        // This is where the mesh orientation is set, as well 
        // as our camera and projection.
        foreach (BasicEffect effect in mesh.Effects)
            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.0f), aspectRatio, 1.0f, 10000.0f);
        // Draw the mesh, using the effects set above.
As you can see, 3D models require more setup steps to draw!

World matrix: Used to control how the model is translated (moved), oriented (rotated), and scaled (made larger/smaller).

View matrix: Used to control the "camera" (your viewpoint in space).
Projection matrix: Used to control the camera's field of view.

Effects: Are used to control how the pixels of the model are colored - they can take into account things like light sources, shiny spots on the surface, and MUCH more. These are also known as "Shaders".

Hopefully that helps some. 3D rendering takes a lot of getting used to!

#5226331 C# class library and external functions

Posted by Nypyren on 29 April 2015 - 01:43 PM

I concur with ferrous - If you've ported it to C#, why do you have 'unsafe' and 'float *' exposed in the public interface at all?

Even if your port is just a lightweight P/Invoke layer, you should try to make the public interface use .NET class library design guidelines. This may mean adding some marshalling functions, but that's usually pretty simple.


#5226160 Spot the bug quiz.

Posted by Nypyren on 28 April 2015 - 04:09 PM

Interesting quiz, but it's too picky about what you're supposed to click on. In some cases, I wanted to select the entire code snippet.

#5225375 Direction Booleans into single Integer

Posted by Nypyren on 24 April 2015 - 08:56 PM

Well, since we are in the coding horrors forum...

Well, we sure are NOW anyway smile.png

#5225356 Direction Booleans into single Integer

Posted by Nypyren on 24 April 2015 - 06:00 PM

In that case, you can do the bitfield as a temporary, then use that in a lookup table (this is C-like pseudocode so it won't necessarily actually compile):
int lookups[] = { 0, 1, 5, 0, 7, 8, 6, 7, 3, 2, 4, 3, 0, 1, 5, 0 };

int index = (up ? 1 : 0) + (down ? 2 : 0) + (left ? 4 : 0) + (right ? 8 : 0);

ReportByte[0] = lookups[index];
Should be damn efficient, and the code is compact.

(edit) My lookup table had zeroes for all of the 3-bit combinations instead of only cancelling out the opposing directions. Fixed.

#5225347 Direction Booleans into single Integer

Posted by Nypyren on 24 April 2015 - 05:11 PM

Use a bit field. Also, why is this in Coding Horrors?

Following code is C# but the bitfield concept holds elsewhere:
public enum Direction
  None  = 0,
  Up    = 1,
  Down  = 2,
  Left  = 4,
  Right = 8,

  UpLeft = Up | Left,
  UpRight = Up | Right,
  DownLeft = Down | Left,
  DownRight = Down | Right,
Use | and & to perform bitwise manipulation.

This breaks your existing values, but will be much easier to deal with in the long run.

If the 0-8 range cannot be changed, then just go with your current code; it's not that bad.

#5224741 Confused. Can I use PHP to make a game?

Posted by Nypyren on 21 April 2015 - 01:44 PM

Yeah, you can make a game where the only client-side stuff is plain old HTML. Game actions can be made using form posts. The downside is that this typically results in a game where taking a turn completely reloads the whole page on the browser.

An incremental improvement from that is use javascript to communicate with the server and update only a portion of the HTML instead of reloading the whole page.

And then the extreme form is to do as much as possible in javascript and only communicate with the server when necessary (passing just game data back and forth).

You can choose to implement your game anywhere along that spectrum.

#5224738 Confused. Can I use PHP to make a game?

Posted by Nypyren on 21 April 2015 - 01:28 PM

PHP runs server-side only, not client-side. So you use it for the server-side half of the game, and something else for the client-side half.
{ PHP on server machine } <-> { data (json, html, etc) over internet } <-> { HTML/JS/AS3/Unity/etc on client machine }

#5224593 software contract (good or bad)

Posted by Nypyren on 20 April 2015 - 07:28 PM

I recommend avoiding % split at all times unless you're publishing a game on a storefront. Negotiate $ values and deadlines (milestones), provisions for scope changes, etc.

#5223803 FastCall Is Alll

Posted by Nypyren on 16 April 2015 - 04:39 PM

The true horror though is that a lot of these already *have* alternative tokens:


#5223297 Write ToLower As Efficient, Portable As Possible

Posted by Nypyren on 14 April 2015 - 07:43 PM

"Portable" and "Efficient" is almost a polar opposite of each other.

Nah, you can have both. Most of your lines-of-code become #ifdef directives, though. sad.png

#5223294 Template or Macro

Posted by Nypyren on 14 April 2015 - 07:37 PM

This thread makes me want a third option: An alcoholic beverage.

#5223291 inline virtual is a nonsense ?

Posted by Nypyren on 14 April 2015 - 07:29 PM

Some compilers know how to "de-virtualize" specific calls; i.e. if one particular spot in your code always uses one specific function, it could optimize that (at the very least, replace the virtual call with a normal call, but I see no reason why it couldn't inline it).

(also, your topic title is "inline template", but your post is about virtual functions...)

#5222977 Seemed easy, is really hard, How do you program bullets?

Posted by Nypyren on 13 April 2015 - 12:03 PM

And then for detecting collision usually a raycast (swept point) or capsule (swept sphere) is used for representing the space that the bullet travels in one game frame.

Randy is correct - for very fast travelling objects, the simple circle-circle test that I've got in my example can allow very fast projectiles to "jump" through other objects. To prevent that, you should check the entire path that the bullet travels each frame to see if it hits anything.

Use a line segment check if your bullet's size is not important for purposes of collision. Use a capsule if it is.

#5222975 Seemed easy, is really hard, How do you program bullets?

Posted by Nypyren on 13 April 2015 - 12:01 PM

Should I really be allocating and deallocating memory like that?

That's what the bulletPool.NewBullet() is for: