Code:

`String func (void)`

{

return "A String";

}

/* Constructor to initialise a const char* called for typecasting "A String" to my String data type and then

Copy Constructor invoked for returning "A String" */

or

Code:

`String& func (void)`

{

String* string = new String("Another String");

return string;

}

/* If I do it this way, only the Constructor to initialise const char* is called and the function returns a

reference to that block of memory on the heap but then I run into the problem of de-allocating the

memory. However, for the sake of argument let's say that the memory does get de-allocated at the end of

the program. Then, which of the two functions will be a more optimised way of returning the string? */

Also, I just want to share a mistake I learnt from while playing with my String class.

Code:

`String& func (void)`

{

String s = "Don't do this";

return s;

// RIP

}

Thanks, any help will be appreciated :) ]]>

I have a function similar to this for character construction (types omitted).

The switch statement does not work. I though it is an issue of score, but setting curly brackets inside each case does not help. The actual switch statement is quite long, because there are many admissible combinations of weapons (and more than two weapons are allowed).

Can you please help with an advice? Thanks!

Code:

`CowboyPtr ConstructCowboy(std::string name, const int loadoutcode)`

{

CowboyPtr cowboy = CowboyPtr(new Cowboy(name));

switch (loadoutcode) {

default:

WeaponPtr leftweapon = WeaponPtr(new Colt());

WeaponPtr rightweapon = WeaponPtr(new Whip());

break;

case 1:

WeaponPtr leftweapon = WeaponPtr(new Colt());

WeaponPtr rightweapon = WeaponPtr(new Rifle());

break;

}

cowboy->Loadout.insert(WeaponPair(leftweapon->Range, leftweapon));

cowboy->Loadout.insert(WeaponPair(rightweapon->Range, rightweapon));

return cowboy;

}

Code:

`Hi, I have this one assignment I am working on and I am a bit stuck here`

Code:

I have to make a rectangle do this with user input:

Side size = 1

+-+

| |

| |

| |

| |

| |

| |

+-+

----------------------------------------------------------------------------

Here's what I have so far

//Draw a single line of fiver uppercase Xs using two kinds of count-controlled loops

#include <iostream>

using namespace std;

int main()

{

//Variables declared

int count1 = 1, limit = 5, count2 = 1;

char doAgain;

cout << "Enter the width for a line of Xs to be drawn on the screen: ";

cin >> limit;

count1 = 1;

cout<< '+';

while(count1 <= limit-2)

{

cout << "-";

count1++; //Loop update condition

}

cout<< '+';

cout << endl << endl;

while(count1 <= limit-2)

{

cout << " ";

count1++; //Loop update condition

}

cout<< '|';

cout << endl << endl;

while(count2 <= limit-2)

{

cout << " ";

count2++; //Loop update condition

}

cout<< '|';

cout << endl << endl;

return 0;

}

Any guidance would be useful thank you in advance :)

Where should I put typedef that is used in several header files? Putting it in each file causes multiple declaration error, and yet each header file requires a declaration. Should I play around with name spaces?

Thx ]]>

Code:

typedef struct Node {

value_t valueof;

} Node;

typedef struct BranchNode {

struct BranchNode *left_node;

struct BranchNode *mid_node;

struct BranchNode *right_node;

struct Node *left_val;

struct Node *right_val;

} BranchNode;

While I try to access data member in the below NodeAll function, it gives error

error: error: request for member 'Node' in 'newBranchNode->TreeNode::left_val', which is of non-class type 'DataNode*'

Can someone tell me how to access this nested pointer to member structure for non class type?

BranchNode* NodeAll(BranchNode *root, int val)

{

BranchNode* newBranchNode;

BranchNode *BranchNodeptr;

newBranchNode = newBranchNode;

newBranchNode->left_node = NULL;

newBranchNode->right_node = NULL;

newBranchNode->mid_node = NULL;

newBranchNode->left_val.Node->valueof; // error here

newBranchNode->right_val.Node->valueof;

return newBranchNode;

}

i am trying to basically just make a button in my little console application which can be pressed. There will be three buttons,

so if I press first button, hello 1 should be display screen

if I press seconds button, hello 2 should be display on screen

if I press third button, hello 3 should be display on screen

I'm having trouble figuring out how to get it to work mingw ]]>

I just wanted to check on this. I have the statement below inside a function (method of Player) that checks that all weapons in the Loadout vector has the same scale as the Player who carries them:

Code:

`int playerscale = PlayerScale;`

bool IncorrectScale = any_of(Loadout.begin(), Loadout.end(), [&playerscale](auto& weapon) { return weapon->WeaponScale != playerscale; });

So, the question is to count the number of all possible rectangles that are formed on the x-y plane given the coordinates of a variable number of points. It is also given that no two coordinates of a point will be the same as the coordinates of any other point.

Here's my try:

Code:

`#include <iostream>`

struct Point

{

int x;

int y;

};

int main (void)

{

int TotalPoints , Ctr1 , Ctr2 , Ctr3 , Ctr4;

std::cout << std::endl

<< "Enter Number of Points: ";

std::cin >> TotalPoints;

Point* Coordinates = new Point[TotalPoints];

for (Ctr1 = 0; Ctr1 < TotalPoints; Ctr1++)

{

std::cout << "Point " << Ctr1 + 1 << " x: "; std::cin >> Coordinates[Ctr1].x;

std::cout << "Point " << Ctr1 + 1 << " y: "; std::cin >> Coordinates[Ctr1].y;

}

int TotalPossibleLines = ((TotalPoints)*(TotalPoints - 1)) / 2 , Line = 0;

float* SlopeOfLine = new float[TotalPossibleLines] { 0.0f };

//float* SlopeOfPerpendicularLine = new float[TotalPossibleLines] { 0.0f };

for (Ctr1 = 0; Ctr1 < TotalPoints - 1; Ctr1++)

{

for (Ctr2 = Ctr1 + 1; Ctr2 < TotalPoints; Ctr2++)

{

SlopeOfLine[Line] = (float)((float)(Coordinates[Ctr2].y - Coordinates[Ctr1].y) / (float)(Coordinates[Ctr2].x - Coordinates[Ctr1].x));

//SlopeOfPerpendicularLine[Line] = -(1.0f / SlopeOfLine[Line]);

Line++;

}

}

/*for (Ctr1 = 0; Ctr1 < TotalPossibleLines; Ctr1++)

{

std::cout << std::endl << SlopeOfLine[Ctr1]; // " " << SlopeOfPerpendicularLine[Ctr1] << std::endl;

}*/

int TotalRectangles = 0;

for (Ctr1 = 0; Ctr1 < TotalPossibleLines; Ctr1++)

{

for (Ctr2 = Ctr1 + 1; Ctr2 < TotalPossibleLines; Ctr2++)

{

if (SlopeOfLine[Ctr1] == SlopeOfLine[Ctr2])

{

for (Ctr3 = 0; Ctr3 < TotalPossibleLines; Ctr3++)

{

if (SlopeOfLine[Ctr3] * SlopeOfLine[Ctr1 /*or Ctr2*/ ] == -1)

{

for (Ctr4 = Ctr3 + 1; Ctr4 < TotalPossibleLines; Ctr4++)

{

if (SlopeOfLine[Ctr3] == SlopeOfLine[Ctr4])

TotalRectangles++;

}

}

}

}

}

}

std::cout << std::endl << "Total Possible Rectangles: " << TotalRectangles;

delete[] SlopeOfLine;

//delete[] SlopeOfPerpendicularLine;

delete[] Coordinates;

return 0;

}

So, what I'm trying to do is this:

- Take in a set of points and their coordinates

- Find all possible slope of lines through each pair of points

(If there are 4 points, then total possible lines are 6 which can be easily found out by using the formula (n*(n-1))/2 )

- Loop through all possible slopes and search for any two same slope values. These indicate parallel lines (Note: They may indicate the same line but that wouldn't happen as it is given that no two coordinates of a point will be the same as that of any other point)

- Once I find a set of parallel lines, I start looping through the slopes of all possible lines again and search for a slope such that the value of the slope found in the above point times the value of slopes currently being looped is equal to -1.

(Why? Because the product of slopes of two lines = -1 (m1 * m2 = -1 ) )

- Once I find any such line/slope such that it is indeed perpendicular, I start looking for another slope with the same slope value (as that of the perpendicular) because I'll need two perpendicular lines to form the rectangle.

- If all conditions are met, I get one rectangle. Similarly, once all possible conditions are exhausted, I'll get my total number of rectangles.

Now, obviously I'm going to be criticised for this approach because it makes for a very dirty code and there might be better approaches on the internet for solving the same problem but this was my own logic that I came up with, so, I wanna stick with this and get to the bottom of the inherent issues before looking at other approaches.

There might be a situation where the slope of a line is positive infinity (or negative infinity) i.e. (1/0) (or (-1/0) ) and the slope of another line is 0. It is obvious that the two lines are perpendicular but going by what I implemented, we can never have the condition of the product of slopes being equal to -1 because,

Logically, (and Mathematically) ((-1/0)*0 = -1 ) (Not saying that 0 and 0 cancel each other out but that's how we know the two will be perpendicular. But this is not the result that the computer will give. I'm writing my program in C::B and compiling with GNU GCC so I can use negative infinity and positive infinity and as a matter of fact, if I choose to display the slopes, it gives me the correct results like so "-inf" for negative infinity and "inf" for positive infinity.

Is there a way I can get through this without having to do error checking (i.e. divide by zero)? I think that I can add more check conditions and based upon it modify the product of slopes result.

So, if I have two slopes which are actually perpendicular, I'm getting a result -0.999... which is -1, but doing the comparison -0.999... == -1 results in a false statement. Is there a way I can doing floating point comparisons for numbers that are very close to each other? Is there a way I can round my number to the nearest decimal point? This way, a rounded up -0.999... will give -1.

---------------------

Again, I know the code is very flawed for the inherent issues that are there but speaking from a mathematical viewpoint, I think the logic makes sense but having to implement it in code is something rather difficult as taking care of these pesky and minute bugs is a difficult.

Please redirect me to reading material on the problem, if any.

Thanks for your help, time, and patience! :) ]]>

I have a very basic question. What is the appropriate data type for what essentially is a collection of bools, taking the value true if a certain property exists? For example, assume there are 9 properties in total,

Code:

`{Red, Yellow, Green, Thick, Thin, Young, Old, Bad, Good}`

Code:

`MyClass Example({Red, Green, Young})`

I was thinking of using an enum, but verifying whether a property exists in an enum not straight forward. In principle, vector of bools would do. Even bits of an integer. But then I don't see the labels, just the indices, which impairs readability. ]]>

Code:

` cmake_minimum_required(VERSION 2.4)`

project(aproject)

include_directories(${PROJECT_SOURCE_DIR})

include_directories(${CMAKE_SOURCE_DIR})

target_include_directories(atarget ${CMAKE_SOURCE_DIR})

add_executable(app asrc.cpp)

Write a program to display all possible permutations of additions that lead to the Input number so long as they contain the digit "1"

Input: 5

Output:

1 1 1 2

1 1 2 1

1 2 1 1

2 1 1 1

1 1 3

1 3 1

3 1 1

1 4

4 1

Code:

`#include <iostream>`

#include <iomanip>

int main (void)

{

int Input , Ctr1 , Ctr2 , Ctr3;

std::cin >> Input;

int* Sum = new int[Input - 1];

int Num = 1;

for ( Ctr1 = 0 ; Ctr1 < Input - 1 ; Ctr1++ ) Sum[Ctr1] = 1;

for ( Ctr1 = 0 ; Ctr1 < Input - 2 ; Ctr1++ )

{

std::cout << std::endl;

for ( Ctr2 = Ctr1 + 1 ; Ctr2 < Input ; Ctr2++ )

{

Sum[Input - (Ctr2 + 1)] += Num;

for ( Ctr3 = 0 ; Ctr3 < Input - (Ctr1 + 1) ; Ctr3++ )

std::cout << std::setw(3) << Sum[Ctr3];

std::cout << std::endl;

Sum[Input - (Ctr2 + 1)] -= Num;

}

Num++;

}

std::cin.get();

delete[] Sum;

return 0;

}

Could someone suggest an alternate/better approach?

Thanks! ]]>

I have been trying to read from a file(which includes some Turkish characters too) into a wstring,string or vector, then write the contents into another file, then read the new file's contents into a wstring,string or vector and write them into a file,then read the new file's contents...

And also I want to be able to use functions like "find()"of wstring/string/vector.

I tried so many things in the last about 10 days, playing with string,wstring,vectors but I wasn't able to do what I want.I had thought I was able to do that yesterday using vectors and copy() function(I actually read it online and did some additions to suit what I want to accomplish) but unfortunately it didn't copy whitespace characters so it was not useful for my purpose.

I have tried so many things so I am not sure which one I should write here, but one of them was:

************************

Code:

`#include <iostream>`

#include <vector>

#include <fstream>

#include <iterator>

#include <algorithm>

using namespace std;

int main()

{

vector<char>cv ;

ifstream if1 ("hello.txt",ios::binary);

if (!(if1))

{

cout << "hello.txt can't be opened!";

return 0;

}

while (!(if1.eof()))

{

cv.push_back(if1.get());

}

cv.push_back('\0');

ofstream of("file1.txt",ios::binary);

if (!(of))

{

cout << "file1.txt can't be opened!";

return 0;

}

cout << "\n\ncv: " << cv.data() << endl;

int counter=0,i=0;

vector<char>::iterator oic = cv.begin();

while (oic!=cv.end()-2 && counter<39)

{

oic++;

counter++;

of.put(cv[i]);

i++;

}

ptrdiff_t position = find(cv.begin(),cv.end(),'c') - cv.begin();

cout << "\n\nposition of h: " << position << endl;

if1.close();

of.close();

vector<char>cy ;

ifstream if2 ("file1.txt",ios::binary);

if (!(if2))

{

cout << "file1.txt can't be opened!";

return 0;

}

while (!(if2.eof()))

{

cy.push_back(if2.get());

}

cy.push_back('\0');

ofstream of2("file2.txt",ios::binary);

if (!(of2))

{

cout << "file2.txt can't be opened!";

return 0;

}

cout << "cy: " << cy.data();

counter=0;

i=0;

vector<char>::iterator oic2 = cy.begin();

while (oic2!=cy.end()-2 && counter<39)

{

oic2++;

counter++;

of2.put(cy[i]);

i++;

}

if2.close();

of2.close();

ptrdiff_t pos = find(cy.begin(),cy.end(),'c')- cy.begin();

cout << "\nposition of h " << pos;

return 0;

}

*****************

Although this code seems like reads/writes from/to files well, also when I try to find a character like 'c' ,'o' in the vector it finds it's position but unfortunately when I try to find a Turkish letter like 'ç' instead of 'c' using:

Code:

`ptrdiff_t position = find(cv.begin(),cv.end(),'ç') - cv.begin();`

How can I solve this problem? ]]>

1) ++*p means incrementing the value of de-referenced p

2) *p++ means incrementing p to the next address and de-referencing it

Code:

`#include <iostream>`

int main (void)

{

int My_arr[] = { 1 , 4 };

int* ptr = My_arr;

std::cout << ++*ptr;

std::cout << " " << *ptr++;

return 0;

}

Am I invoking undefined behaviour by writing the incremental statements with cout?

[EDIT]

I feel like an idiot for starting this thread... I figured out what's happening. Doing a "cout << *ptr++" means display "*ptr" first and then increment it. Sorry for wasting the time of anyone who looked through this post...

[/EDIT] ]]>

I have my camera class, from Camera.cpp and camera.h.

They all have three functions that work perfectly(actually two of them work)

when I go

Code:

`m_camera.Yaw(DeltaY);`

m_camera.Pitch(DeltaX);

Code:

`m_camera.Roll(DeltaZ);`

Code:

`m_camera.Roll(10.00f); //or any over float value`

Here is Camera.cpp:

Code:

`#include <d3d9.h> // directx header files`

#include <d3dx9.h>

#include "camera.h"

#include "common.h"

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

Summary: Default constructor

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

CCamera::CCamera()

{

m_maxPitch = D3DXToRadian(89.0f);

m_maxVelocity = 1.0f;

m_invertY = FALSE;

m_enableYMovement = TRUE;

m_position = D3DXVECTOR3(0.0f, 0.0f, 0.0f);

m_velocity = D3DXVECTOR3(0.0f, 0.0f, 0.0f);

m_look = D3DXVECTOR3(0.0f, 0.0f, 1.0f);

CreateProjectionMatrix(D3DX_PI / 3.0f, 1.3f, 0.1f, 1000.0f);

Update();

}

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

Summary: Creates the projection matrix.

Parameters:

[in] fov - Field of view

[in] aspect - Aspect ratio

[in] near - Near plane

[in] far - Far plane

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

void CCamera::CreateProjectionMatrix(float fov, float aspect, float nearPlane, float farPlane)

{

m_fov = fov;

m_aspect = aspect;

m_nearPlane = nearPlane;

m_farPlane = farPlane;

D3DXMatrixPerspectiveFovLH(&m_projection, m_fov, m_aspect, m_nearPlane, m_farPlane);

}

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

Summary: Moves the camera forward and backward

Parameters:

[in] units - Amount to move

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

void CCamera::MoveForward(float units)

{

if (m_enableYMovement)

{

m_velocity += m_look * units;

}

else

{

D3DXVECTOR3 moveVector(m_look.x, 0.0f, m_look.z);

D3DXVec3Normalize(&moveVector, &moveVector);

moveVector *= units;

m_velocity += moveVector;

}

}

void CCamera::MoveBackward(float units)

{

if (m_enableYMovement)

{

m_velocity -= m_look * units;

}

else

{

D3DXVECTOR3 moveVector(m_look.x, 0.0f, m_look.z);

D3DXVec3Normalize(&moveVector, &moveVector);

moveVector *= units;

m_velocity += moveVector;

}

}

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

Summary: Moves the camera left and right

Parameters:

[in] units - Amount to move

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

void CCamera::Strafe(float units)

{

m_velocity += m_right * units;

}

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

Summary: Moves the camera up and down

Parameters:

[in] units - Amount to move

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

void CCamera::MoveUp(float units)

{

if (m_enableYMovement)

{

m_velocity.y += units;

}

}

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

Summary: Yaw the camera around its Y-axis.

Parameters:

[in] radians - Radians to yaw.

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

void CCamera::Yaw(float radians)

{

if (radians == 0.0f)

{

return;

}

D3DXMATRIX rotation;

D3DXMatrixRotationAxis(&rotation, &m_up, radians);

D3DXVec3TransformNormal(&m_right, &m_right, &rotation);

D3DXVec3TransformNormal(&m_look, &m_look, &rotation);

}

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

Summary: Pitch the camera around its X-axis.

Parameters:

[in] radians - Radians to pitch.

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

void CCamera::Pitch(float radians)

{

if (radians == 0.0f)

{

return;

}

radians = (m_invertY) ? -radians : radians;

m_pitch -= radians;

if (m_pitch > m_maxPitch)

{

radians += m_pitch - m_maxPitch;

}

else if (m_pitch < -m_maxPitch)

{

radians += m_pitch + m_maxPitch;

}

D3DXMATRIX rotation;

D3DXMatrixRotationAxis(&rotation, &m_right, radians);

D3DXVec3TransformNormal(&m_up, &m_up, &rotation);

D3DXVec3TransformNormal(&m_look, &m_look, &rotation);

}

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

Summary: Roll the camera around its Z-axis.

Parameters:

[in] radians - Radians to roll.

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

void CCamera::Roll(float radians)

{

if (radians == 0.0f)

{

return;

}

D3DXMATRIX rotation;

D3DXMatrixRotationAxis(&rotation, &m_look, radians);

D3DXVec3TransformNormal(&m_right, &m_right, &rotation);

D3DXVec3TransformNormal(&m_up, &m_up, &rotation);

}

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

Summary: Updates the camera and creates a new view matrix.

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

void CCamera::Update()

{

// Cap velocity to max velocity

if (D3DXVec3Length(&m_velocity) > m_maxVelocity)

{

m_velocity = *(D3DXVec3Normalize(&m_velocity, &m_velocity)) * m_maxVelocity;

}

// Move the camera

m_position += m_velocity;

// Could decelerate here. I'll just stop completely.

m_velocity = D3DXVECTOR3(0.0f, 0.0f, 0.0f);

m_lookAt = m_position + m_look;

// Calculate the new view matrix

D3DXVECTOR3 up = D3DXVECTOR3(0.0f, 1.0f, 0.0f);

D3DXMatrixLookAtLH(&m_view, &m_position, &m_lookAt, &up);

// Set the camera axes from the view matrix

m_right.x = m_view._11;

m_right.y = m_view._21;

m_right.z = m_view._31;

m_up.x = m_view._12;

m_up.y = m_view._22;

m_up.z = m_view._32;

m_look.x = m_view._13;

m_look.y = m_view._23;

m_look.z = m_view._33;

// Calculate yaw and pitch

float lookLengthOnXZ = sqrtf(m_look.z * m_look.z + m_look.x * m_look.x);

m_pitch = atan2f(m_look.y, lookLengthOnXZ);

m_yaw = atan2f(m_look.x, m_look.z);

}

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

Summary: Updates the camera and creates a new view matrix.

Parameters:

[in] pPosition - New position

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

void CCamera::SetPosition(D3DXVECTOR3* pPosition)

{

m_position.x = pPosition->x;

m_position.y = pPosition->y;

m_position.z = pPosition->z;

}

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

Summary: Updates the camera and creates a new view matrix.

Parameters:

[in] pPosition - New target

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

void CCamera::SetLookAt(D3DXVECTOR3* pLookAt)

{

m_lookAt.x = pLookAt->x;

m_lookAt.y = pLookAt->y;

m_lookAt.z = pLookAt->z;

D3DXVec3Normalize(&m_look, &(m_lookAt - m_position));

}

Code:

#ifndef CCAMERA_H

#define CCAMERA_H

class CCamera

{

public:

CCamera();

void CreateProjectionMatrix(float fov, float aspect, float nearPlane, float farPlane);

void MoveForward(float units);

void MoveBackward(float units);

void Strafe(float units);

void MoveUp(float units);

void Yaw(float radians);

void Pitch(float radians);

void Roll(float radians);

void Update();

void SetPosition(D3DXVECTOR3* pPosition);

void SetLookAt(D3DXVECTOR3* pLookAt);

void SetFOV(float fov) { CreateProjectionMatrix(fov, m_aspect, m_nearPlane, m_farPlane); }

void SetAspectRatio(float aspect) { CreateProjectionMatrix(m_fov, aspect, m_nearPlane, m_farPlane); }

void SetNearPlane(float plane) { CreateProjectionMatrix(m_fov, m_aspect, plane, m_farPlane); }

void SetFarPlane(float plane) { CreateProjectionMatrix(m_fov, m_aspect, m_nearPlane, plane); }

void SetMaxVelocity(float maxVelocity) { m_maxVelocity = maxVelocity; }

void SetInvertY(BOOL invert) { m_invertY = invert; }

void SetMaxPitch(float maxPitch) { m_maxPitch = maxPitch; }

D3DXMATRIX* GetViewMatrix() { return &m_view; }

D3DXMATRIX* GetProjectionMatrix() { return &m_projection; }

D3DXVECTOR3* GetPosition() { return &m_position; }

D3DXVECTOR3 GetPos() { return m_position; }

D3DXVECTOR3* GetLookAt() { return &m_lookAt; }

float GetFOV() { return m_fov; }

float GetAspectRatio() { return m_aspect; }

float GetNearPlane() { return m_nearPlane; }

float GetFarPlane() { return m_farPlane; }

float GetMaxVelocity() { return m_maxVelocity; }

BOOL GetInvertY() { return m_invertY; }

float GetPitch() { return m_pitch; }

float GetYaw() { return m_yaw; }

float GetMaxPitch() { return m_maxPitch; }

private:

D3DXMATRIX m_view;

D3DXMATRIX m_projection;

D3DXVECTOR3 m_right;

D3DXVECTOR3 m_up;

D3DXVECTOR3 m_look;

D3DXVECTOR3 m_position;

D3DXVECTOR3 m_lookAt;

D3DXVECTOR3 m_velocity;

float m_yaw;

float m_pitch;

float m_roll;

float m_maxPitch;

float m_maxVelocity;

float m_fov;

float m_aspect;

float m_nearPlane;

float m_farPlane;

BOOL m_invertY;

BOOL m_enableYMovement;

};

#endif

Thank you so much for your time and consideration. And mods, please don't move this another subforum that nobody reads. This is mostly a C++ issue, after all, not a graphics API issue.

Thank you!

~Xterria ]]>

So, a the simulation runs, different body parts represented by classes declared in the Player Class (e.g. Head, Body, Legs and Weapons) take damage. When this happens, I am storing a pointer to the damaged part in a map belonging to the player class, with the key value representing the priority in the subsequent repair queue:

In the player class:

Code:

`map<int, shared_ptr<PartBase>, greater<int>> DamageLog;`

Code:

`auto HeadPtr = std::make_shared<Part>(Head);`

if (Head.Critical > 0) DamageLog.insert(make_pair(200, HeadPtr));

Each part is derived from PartBase and each overrides the Repair() method. At the end parts get repaired by calling:

Code:

`for (auto const& item : player.DamageLog) item.second->Repair();`

Code:

`vector<shared_ptr<Weapon>> Loadout;`

Code:

`for (auto weapon : Loadout) {`

if (weapon->Disabled) {

auto WeaponPtr = std::make_shared<Weapon>(weapon);

DamageLog.insert(make_pair(10, WeaponPtr));

}

}