[QUOTE=Jimmylaw;26210368]Here is the code I have for the model handling class.
[code]
#include "Object.h"
Object::Object(LPDIRECT3DDEVICE9 device, const std::string &modelname, D3DXVECTOR3 newposition)
{
d3ddev = device;
LPD3DXBUFFER bufMaterial;
position = newposition;
D3DXLoadMeshFromX(modelname.c_str(), // file to load
D3DXMESH_SYSTEMMEM, // load mesh into system memory
d3ddev, // D3D device
NULL, // adjacency setting
&bufMaterial, // put materials here
NULL, // effects
&numMaterials, // number of materials in the model
&mesh); // the mesh
// pointer to buffer containing material info
D3DXMATERIAL* tempMaterials = (D3DXMATERIAL*)bufMaterial->GetBufferPointer();
// create a material buffer for each material in the mesh
Material = new D3DMATERIAL9[numMaterials];
Texture = new LPDIRECT3DTEXTURE9[numMaterials];
for(DWORD i = 0; i < numMaterials; i++)
{
Material[i] = tempMaterials[i].MatD3D; // material info
Material[i].Ambient = Material[i].Diffuse; // set the ambient
if(FAILED(D3DXCreateTextureFromFileA(d3ddev, tempMaterials[i].pTextureFilename, &Texture[i])))
Texture[i] = NULL;
}
}
void Object::Update(void)
{
// static float index = 0.0f; index+=0.03f; // an ever-increasing float value
D3DXMatrixTranslation(&meshTranslate, 0, 0, 0);
D3DXMatrixRotationY(&meshRotateY, 0);
D3DXMatrixScaling(&meshScale, scale, scale, scale);
D3DXMatrixTranslation(&meshPosition,position.x,position.y,position.z);
meshMatrix = meshPosition *
meshRotateY;
}
void Object::Render()
{
// Meshes0 are divided into subsets, one for each material. Render them in
// a loop
for( DWORD i = 0; i < numMaterials; i++ )
{
// Set the material and texture for this subset
d3ddev->SetMaterial( &Material[i] );
d3ddev->SetTexture( 0, Texture[i] );
// Draw the mesh subset
mesh->DrawSubset( i );
}
}
LPD3DXMESH Object::GetMesh(void) { return mesh; }
D3DMATERIAL9 *Object::GetMaterial(void) { return Material; }
LPDIRECT3DTEXTURE9 *Object::GetTexture(void) { return Texture; }
DWORD Object::GetMaterialCount(void) { return numMaterials; }
D3DXMATRIX Object::GetTranslation(void) { return meshTranslate; }
D3DXMATRIX Object::GetYRotation(void) { return meshRotateY; }
D3DXMATRIX Object::GetScale(void) { return meshScale; }
D3DXMATRIX Object::GetMatrix(void) { return meshMatrix; }
void Object::setPosition(D3DXVECTOR3 newPosition)
{
position = newPosition;
}
Object::~Object(void)
{
}
[/code]
Now for example, if I created a class called vehicle. Would I be able to call methods to the class its inheriting by just doing;
Vehicle tank;
tank.Render();
Would that be possible? Or am I completely wrong.[/QUOTE]
Yeah, that's possible.
Make sure you declare the destructor virtual. This is important, because you probably want to store the Vehicle as a pointer to Object. That means, when the Object (actually a Vehicle) is destroyed, ~Object will be called, instead of ~Vehicle, so the new variables introduced in Vehicle would not get destroyed.
Declaring a function as virtual makes it possible to call the Vehicle-destructor, although you have it stored as a pointer to Object.
Virtual function calls are a bit more expensive that normal function calls, so you should be selective on what should be overridden and what not.
[QUOTE=flyboy463;26217295]Hi guys, I'm pretty new to the whole programming deal but I need help with something in C#. What I have now is a very basic maze game, and when you touch one of the borders, the game will reset you to the beginning and will play a sound. Now what I need help with is playing other sounds when I touch the walls, I've looked on google but it was useless. Is there anyway to trigger other sounds to play while I touch the walls?
Code:
[code]using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Maze
{
public partial class Form1 : Form
{
// This SoundPlayer plays a sound whenever the player hits a wall.
System.Media.SoundPlayer startSoundPlayer = new System.Media.SoundPlayer(@"C:\Users\Owner\Desktop\Oops.wav");
// This SoundPlayer plays a sound when the player finishes the game.
System.Media.SoundPlayer finishSoundPlayer = new System.Media.SoundPlayer(@"C:\Windows\Media\tada.wav");
public Form1()
{
InitializeComponent();
MoveToStart();
}
private void label1_Click(object sender, EventArgs e)
{
}
private void finishLabel_MouseEnter(object sender, EventArgs e)
{
}
private void finishLabel_MouseMove(object sender, MouseEventArgs e)
{
{
// Show a congratulatory MessageBox, then close the form.
finishSoundPlayer.Play();
MessageBox.Show("Congratulations!");
Close();
}
}
/// <summary>
/// Play a sound, then move the mouse pointer to a point 10 pixels down and to
/// the right of the starting point in the upper-left corner of the maze.
/// </summary>
private void MoveToStart()
{
Point startingPoint = panel1.Location;
startingPoint.Offset(10, 10);
Cursor.Position = PointToScreen(startingPoint);
}
private void wall_MouseEnter(object sender, EventArgs e)
{
// When the mouse pointer hits a wall or enters the panel,
// call the MoveToStart() method.
MoveToStart();
startSoundPlayer.Play();
}
private void panel1_MouseEnter(object sender, EventArgs e)
{
MoveToStart();
}
}
}
[/code][/QUOTE]
Have an array of Sounds and use Random.Next(0, SoundArray.Length) to determine a random index.
Right I've been messing around with inheritance in a test project and I thought I had it figured out till I tired using the same method on my main project and an annoying error appeared.
The super class "Object" as the constructor
[code]
Object::Object(LPDIRECT3DDEVICE9 device, const std::string &modelname, D3DXVECTOR3 newposition)
[/code]
So for the sub class "Vehicle" I did this, which worked perfectly fine for my test project.
[code]
Vehicle::Vehicle(LPDIRECT3DDEVICE9 d3ddev, const std::string &modelname, D3DXVECTOR3 newposition) : Object(d3ddev, &modelname, newposition)
{
}
[/code]
but for some strange reason the ( just before the d3ddev errors with the message "Error: no instance of constructor "Object::Object" matches the argument list. There the same! I don't understand how they can differ.
*FIXED - needed to take the & before modelname *
[QUOTE=Jimmylaw;26210368]Here is the code I have for the model handling class.
<Snip>
Now for example, if I created a class called vehicle. Would I be able to call methods to the class its inheriting by just doing;
Vehicle tank;
tank.Render();
Would that be possible? Or am I completely wrong.[/QUOTE]
Suggestion: Separate the mesh from the instance. (E.g. Mesh and Model.)
This means that if you have two instances which use the same mesh, you only need to load it once into one set of buffers.
Each instance would have it's own world-matrix and possibly textures. (Or is able to override the textures in the mesh.) Each mesh can be responsible for the instances of itself and it also sets you up for hardware instancing.
Anyone know why the C++0x <random> distributions have their operator() non-const?
I have a const discrete_distribution and I can't use it, unless I don't mark it const.. which I actually do want to do.
I secretly added a const-qualifier for the operator() in the standard-header and it worked fine.. but messing with the headers is obviously something I want to avoid, too.
I looked at the standard proposal N2079 and it does indeed not declare it const.
Soo.. anyone know the rationale for this? A distribution surely should not change after it is applied to a random number?
I'm curious, how are you guys using see plus plus oh ex? Probably a really dumb question, but I haven't seen anything on it.
The proposal-documents that are linked on the gcc C++0x status page ([url=http://gcc.gnu.org/projects/cxx0x.html]linky[/url]) :v:
Aw. So there isn't any way to get support for VS2010 right now?
[QUOTE=ZeekyHBomb;26224709]A distribution surely should not change after it is applied to a random number?[/QUOTE]
I'm pretty sure it does... the seed is updated, thus you get a different value the next time you call the function. This causes problems if you silently pop a random number from the stream while using a deterministic seed.
No, the distribution, not the generator. I'm fine with the generator-argument being a non-const reference.
The distribution simply adapts the output of a (pseudo) random number.
[editline]22nd November 2010[/editline]
Like I also said, I can simply add the const qualifier to the operator overload and it works fine, with no suppressed errors.
[editline]22nd November 2010[/editline]
Like I also said, I can simply add the const qualifier to the operator overload and it works fine, with no suppressed errors.
[QUOTE=ZeekyHBomb;26227178]No, the distribution, not the generator. I'm fine with the generator-argument being a non-const reference.
The distribution simply adapts the output of a (pseudo) random number.[/QUOTE]
Since there's a reset() function too, I think it's intended that distributions may be stateful. Not all of them necessarily [i]are[/i], but they're designed to act as if they might be.
It may seem strange for a stateless distribution to have an interface that pretends it's stateful, but all these distributions are models of the same "concept" (in the STL sense, like Forward Iterator or Random Access Container), and they're meant to present a uniform interface to generic functions which take distribution classes as template parameters. The statefulness or non-statefulness of a particular distribution is a private implementation detail from that standpoint.
Reposting: How the hell do I build JSONCPP for Visual Studio 2010?
[QUOTE=ZeekyHBomb;26218280]
Have an array of Sounds and use Random.Next(0, SoundArray.Length) to determine a random index.[/QUOTE]
Thanks for the answer but I don't know how to do this yet, looking on google for tutorials of arrays.
EDIT:
Scratch above, I got it working using a different method. I just clicked on a wall and replaced wall_MouseEnter with wall(# of wall)_MouseEnter, which created a separate sub dictionary which I then used NAME.Play(); and that worked out ok.
Any good tutorials for programming a game server in C#? I'm having a few difficulties.
[QUOTE=Agent766;26235270]Any good tutorials for programming a game server in C#? I'm having a few difficulties.[/QUOTE]
Read Beej's networking guide and just learn to use sockets and stuff in C#. Game servers are just normal servers, there's no such thing as a generic 'game server', and you'll only (maybe) find tutorials on how to program servers for specific games.
[QUOTE=Wyzard;26235171]Since there's a reset() function too, I think it's intended that distributions may be stateful. Not all of them necessarily [i]are[/i], but they're designed to act as if they might be.
It may seem strange for a stateless distribution to have an interface that pretends it's stateful, but all these distributions are models of the same "concept" (in the STL sense, like Forward Iterator or Random Access Container), and they're meant to present a uniform interface to generic functions which take distribution classes as template parameters. The statefulness or non-statefulness of a particular distribution is a private implementation detail from that standpoint.[/QUOTE]
Damn, you're right.
std::normal_distribution calculates two numbers upon adapting, storing one for a subsequent call :|
Anyone here skilled with directx and C++?
I'm writing a turtle graphics interpreter for LOVE, but am having trouble with turning.
The direction is a number from 0 to 359.
How would I draw a line from one vector, say (30, 30), to forward 100 units at 45 degrees?
fucking c++, what do
[img]http://ahb.me/_Zp[/img]
That is why I fucking hate building stuff
[QUOTE=pro ruby dev;26263035]fucking c++, what do
[img_thumb]http://ahb.me/_Zp[/img_thumb][/QUOTE]
One webpage I found suggested that you may have forgotten to run bootstrap.bat.
If that's not the case, maybe try a different version.
[QUOTE=ZeekyHBomb;26263317]One webpage I found suggested that you may have forgotten to run bootstrap.bat.[/QUOTE]
D'oh :downs:
(code)
int tala = 0, teljari1 = 0 ,teljari2=0;
do
{
Console.WriteLine("Sláðu inn tölu");
tala = Convert.ToInt32(Console.ReadLine());
if (tala >= 5 && tala <= 65)
{
tala = tala - tala;
teljari1 = teljari1 + 1;
}
else
{
teljari2 = teljari2 + 1;
tala = tala + tala;
}
} while (tala!=112);
why does this crash when i type in 112 ????
If you type in 112 it skips that piece of code
man sorry about the edits but how do you make someone put in a string and he puts in something like
my name is john and the program takes the 1st letter and makes its likes this mm mmmm mm mmmm = my name is john
Is this possible?
[code]
template<class T>
class Base
{
public:
typename T::Type type;
};
class Child : public Base<Child>
{
public:
enum Type
{
TEST
};
};
[/code]I'm getting "Type is not a member of Child"
PS: What happened to the [noparse][cpp][/noparse] tags?
Base<Child> is instanced before Child. As such, Child::Type does not yet exist when Base<Child> is created.
[editline]24th November 2010[/editline]
Well, instanced is the wrong word, but you know what I mean.
At the point where Base<Child> is created, Child only exists as a forward declaration.
[editline]24th November 2010[/editline]
Well, instanced is the wrong word, but you know what I mean.
At the point where Base<Child> is created, Child only exists as a forward declaration.
Sorry, you need to Log In to post a reply to this thread.