• Create Account

# greenzone

Member Since 24 Jun 2011
Offline Last Active Feb 23 2014 02:00 PM

### Qestion about passing incremented values

06 December 2013 - 08:49 AM

Ok, so I completely understand the recursive portion of the Merge Sort algorithm but what I am having problems with is this example of the actual merge portion of the algorithm. In the first conditional statement were one is comparing the first element of the two input vectors I understand, but its the next line were p1 or p2 are being incremented up 1, while specifying which element is to be moved on to the empty vector, I am not understanding. Is it adding element 0 and then ++ to element 1 for the next comparison or is it passing element 1?

I guess my main question is, does the value of a variable get read first and then incremented or is the variables' value incremented and then read?

int newVariable = 0, oldVariableX = 0;

newVariable = oldVariableX++

Does  ( newVariable = 0   or   newVarivable = 1  ) ?

```void Merge(Vector<int> & vec, Vector<int> & v1, Vector<int> & v2)
{
int n1 = v1.size();
int n2 = v2.size();
int p1 = 0;
int p2 = 0;
while (p1 < n1 && p2 < n2) {
if (v1[p1] < v2[p2]) {
} else {
}
}
}
```

### placing constructor in private

24 November 2013 - 02:06 PM

I am currently studying the design patterns described by the Gang of Four. The Composite Pattern, is what I am currently trying to concertize mentally. While doing this I was looking at an example of its implementation shown here. If you notice in the portion were they are implementing the leaf classes of this pattern they place a generic version of the classes" constructor in private and they place an overloaded version of the constructor in public. Trying to figure this out on my own I came across a forum post that describes the various reasons one might place the constructor in private here by Kerido. Of those 5 examples I am certain its not B or E. But out of A,C, and D I am not sure. I place portions of the code I am talking about to reduce having to hunt through the posted link above. Also the explanations of  A, C, and D (reasons to have a constructor in private) I'll past below the class in question.

```/*
* Capacitor is a LEAF class which is directly inherited from the -
* ElectronicComponet class.
*/
class Capacitor:public ElectronicComponent
{
float capacitance_muF; //Capacitance value in micro fared.

Capacitor(){} // Point in question. Why are they doing this, in this context?
public:
/*
* Constructor - initialize the capacitance value.
*/
Capacitor(float muF)
:capacitance_muF(muF)
{

}
/*
* Prints the Capacitor's specification.
*/
void PrintSpec(ostream& ostr, string prefix = "")
{
ostr<<prefix<<"Capacitor ("<< capacitance_muF <<" muF )"<<endl;
}
/*
* Performs the Capacitor's real function of modifying  input Voltage & Current.
* Now I just put a printing of Voltage and current as place holder.
*/
void DoFunction(float& voltage, float& current)
{
cout<<endl<<"Capacitor Input ("<<voltage<<" V ,"<<current<<" Amp)
Capacitance ="<< capacitance_muF<<endl;
}
};
```

A. Your class instances are created in a static method. The static method is then declared as public.

```class MyClass()
{
private:
MyClass() { }

public:
static MyClass * CreateInstance() { return new MyClass(); }
};
```

C. (Only applies to the upcoming C++0x standard) You have several constructors. Some of them are declared public, others private. For reducing code size, public constructors 'call' private constructors which in turn do all the work. Your public constructors are thus called delegating constructors:

```class MyClass
{
public:
MyClass() : MyClass(2010, 1, 1) { }

private:
MyClass(int theYear, int theMonth, int theDay) { /* do real work */ }
};```

D. You want to limit object copying (for example, because of using a shared resource):

```class MyClass
{
SharedResource * myResource;

private:
MyClass(const MyClass & theOriginal) { }
};
```

Any thoughts on the matter would be nice thanks

### Most efficient Picking Method

08 November 2013 - 08:54 AM

I am curious as to what is the most efficient picking method. Currently I render all the objects of the screen assigning each a different color and then what ever color is under the mouse during picking is the object that is then selected. I have also heard if i change the size of the screen during picking to be just a little larger then the mouse and then drawing the screen right under the mouse during the picking pass helps with the efficiency as well. Also is casting a ray more efficient then doing a render pass for handling picking?  Any thoughts on this would be pure awesomeness thanks

### glutTimerFunc question

15 October 2013 - 10:05 AM

Does the glutTimerFunction work on a thread separate from the main thread when it is executed? Used to call the function that encapsulates it, when it calls that parent function it does not immediately get placed in a stack. I mean the line proceeding glutTimerFunc is then executed before the next call to the parent function is executed. I thought in a recursive function the line proceeding the call to the function is not executed until the base case is satisfied. Why is this or how is this working in the background? What is the voodoo behind the glutTimerFunction?

### Programming interview FAIL

01 August 2013 - 05:04 PM

So I have read many of the FAQ and how to break into the business of games on this forum which are very informative. After much reading I went and looked at questions that interviewers ask to find out if programmers know how to program and OH MY GOD. I have to admit I am kind of speechless lol. I thought I knew something, wow WAS I WRONG.

I have recently, completely written my own game engine using C++, Opengl. It can import any type of geometry file type. I have a fully operational scene graph to manage my game objects and animations.  I have written a math library that include Vectors, matrices, quaternions, and the combination of all these into my own Rigid Body Transformation class which i thought was totally awesome lol. I have created glsl shader programs to implement effects such as bump mapped textures, specular, Cube map shadows, Ambient occlusion, super sampling, and even vertex displacement for like cool distorted lens affects. I am also using physX for all my collision detection, character controllers, projectiles and what not. All while trying to keep the cleanest and commented code calligraphy.

I am so passionate about learning how to be a better programmer and the whole game development process but after reading this article I feel like a complete failure.

Five-Essential-Phone-Screen-Questions

I do how ever feel like I could probably accomplish many of the exercises form this article

Programming-Interview-Questions