• Create Account

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

# Sammie22

Member Since 14 Oct 2009
Offline Last Active Jul 19 2011 03:26 PM

### Since we have an extra week

02 February 2011 - 12:32 AM

I thought I'd play around with some shader effects, which I am really enjoying. In addition to gaining a better understanding of the XNA framework, it's one of the reasons I am really looking forward to this workshop. I have been messing around with some water effects, and have a nice wavy look to an underwater scene. So I thought it would be cool to have an effect where the user can click on the screen, and set off a ripple effect, like what happens when a small object falls into a body of water. I did a lot of googling around for some examples, but nothing is really setting in with me. Right now I have this, which is from the Microsoft example on applying shader effects to 2D textures:

```uniform extern texture ScreenTexture;

sampler ScreenS = sampler_state
{
Texture = <ScreenTexture>;
};

float wave;                // pi/.75 is a good default
float distortion;        // 1 is a good default
float2 centerCoord;        // 0.5,0.5 is the screen center

float4 PS(float2 texCoord: TEXCOORD0) : COLOR0
{
float2 distance = abs(texCoord - centerCoord);
float scalar = length(distance);

// invert the scale so 1 is centerpoint
scalar = abs(1 - scalar);

// calculate how far to distort for this pixel
float sinoffset = sin(wave / scalar);
sinoffset = clamp(sinoffset, 0, 1);

// calculate which direction to distort
float sinsign = cos(wave / scalar);

// reduce the distortion effect
sinoffset = sinoffset * distortion/32;

// pick a pixel on the screen for this pixel, based on
// the calculated offset and direction
float4 color = tex2D(ScreenS, texCoord+(sinoffset*sinsign));

return color;
}

technique
{
pass P0
{
}
}
```

This does produce a ripple effect, but not the desired result. The ripple begins a bit away from center position, and has an ugly trailing effect. I think this is down to the timing as well as some missing variables needed to make the desired effect. For an example, I am going for something like: http://www.youtube.c...h?v=Nr42AG1aPAY

I would like to be able to adjust the initial radius, number of ripples, length of the ripples before they dampen out, and the time it takes for them to reach their dampened state. If anyone has any experience with this, I'd love some help.

Thanks

Edit: I should also add that I am applying this effect to a Texture2D, and would like to make it a pixel shader only.

### Ch 3 oddity

21 January 2011 - 08:40 PM

I found this a little strange.. Maybe I'm having a brain fart here but in Managing Memory section, the author states:

"When you pass in a reference type, we are actually passing a copy of the reference to the data."

He then states, in regards to the 'ref' keyword:

"We should not use this keyword on reference types because it will actually slow things down..."

Then, in Program.cs for the PerformanceChecker, he has this static method signature:

static void PrintPerformance(string label, ref Stopwatch sw) { ... }

At first I was thinking Stopwatch was a struct, but it is a class. So am I missing something here, or did he just say one thing and do another? There is no reason I see to pass as a reference, as it does not redefine the memory pointer for that reference. It only access the member variables of that object.

### Raw Input and Key Combinations

04 March 2010 - 02:35 PM

Trying to handle key combinations with Raw Input API and having some trouble. For example, in a typical FPS, you can press 'W' and 'D' and move forward and to the right. Releasing 'D' would still leave you moving forward... etc. What I have done is this:
```                // keyboard
{
// get key value from the keyboard member
USHORT key_code = raw->data.keyboard.VKey;

// key down
if( raw->data.keyboard.Flags == RI_KEY_MAKE )
{
if( key_code == 'W' )
{
g_Camera->MoveForward( g_Camera_Movement_Speed );
}
if( key_code == 'S' )
{
g_Camera->MoveForward( -g_Camera_Movement_Speed );
}
if( key_code == 'A' )
{
g_Camera->MoveRight( -g_Camera_Movement_Speed );
}
if( key_code == 'D' )
{
g_Camera->MoveRight( g_Camera_Movement_Speed );
}
}
```
This only captures the last key pressed. Does anyone know of any samples which handle key combinations? Or can anyone help on getting this to work? Thanks, Brad

### Implementing MVC Questions

11 February 2010 - 04:41 PM

I have done quite a bit of searching here, and other places in the web, looking for actual implementation examples of MVC game design. I found this article very useful for visualizing for a high level design: http://www.gamasutra.com/features/20050414/rouwe_01.shtml .. But, while I have learned a lot conceptually, I am struggling turning it into an actual program. I want to learn MVC to decouple the rendering, model, input, logic, etc to ease the rafactoring pain in my projects. I came up with a simple game project to practice MVC (I am sure MVC is overkill for it and not necessary, but I wanted to learn in a simple manner). The project contains simple 3d primitives for graphics, and no animation. Using the above link as my template, I have built my Model out as I typically do: EntityBase <- Non-MovingGameObjects EntityBase <- MovingEntityBase <- MovingEntityGameObjects I created a EntityManager to contain the EntityObjects, and provided Add(), Remove(), and Update() interfaces. I am comfortable with this setup and feel it will work fine for this project. But now I have reached a bit of a hurdle in my understanding of the implementation. I am trying to build out the representation piece, and am not quite sure how to proceed. I was thinking of something like: RepresentationBase <- Non-EntityGameObjects (i.e. background) RepresentationBase <- EntityRepresentationBase <- EntityRepresentationGameObjects In this setup, I am unclear as to what to pass to the EntityRepresentationGameObjects, nor how exactly to structure it. Do I provide a pointer to the EntityGameObject in the representation class to get position information? Or do I use a messaging system? How do I implement the actual shapes of the objects into the representation class? Use another class to represent the shape and have a pointer to that in the representation class? Any help / advice, or actual implementation examples, would be greatly appreciated. Thanks, Brad Edit: If this question seems to vague or unclear and you need more info, please let me know and I will provide it as best I can. [Edited by - Sammie22 on February 12, 2010 1:41:02 AM]

### DirectX Matrix Transformations

16 October 2009 - 10:52 AM

I would like to rotate a cube primitive around a single axis. To be more specific, I would like to rotate the vertex points (8) of the cube, which uses an index buffer to create the triangles. In GDI and other projects, I have written my own functions to handle matrix transformations. However, I would like to use methods provided by dx if possible (since I am trying to learn it). I have done some searching and found this:
```    D3DXMATRIX mSunScale;
D3DXMATRIX mSunSpinRotation;
D3DXMATRIX mSunMatrix;

D3DXMatrixRotationY( &mSunSpinRotation, D3DXToRadian( fSunSpin ) );
D3DXMatrixScaling( &mSunScale, 5.0f, 5.0f, 5.0f );

// Now, concatenate them together...

mSunMatrix = mSunScale *       // 1. Uniformly scale the Sun up in size
mSunSpinRotation; // 2. and then spin it on its axis.

g_pd3dDevice->SetTransform( D3DTS_WORLD, &mSunMatrix );
g_pSunMesh->DrawSubset(0);
```
This example applies to a mesh, not a primitive. I also do not see where the matrix transformation is actually applied to the mesh?? Is that in the DrawSubset(0) call? Further down the rendering process, a similar approach is repeated mutliple times for different meshes, and DrawSubset(0) is called each time. So I am guessing that this is part of applying the transformation to the mesh, but my searches on the DrawSubset() function didn't turn up much info. Can anyone point me in the right direction for example(s) of transformations on primitives? Or provide a sample here? Thanks for any help, Brad

PARTNERS