Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 16 Oct 2013
Online Last Active Today, 04:04 PM

#5243281 Old-School 3D Wireframe Modelling Tool

Posted by Lactose! on 28 July 2015 - 04:51 PM

why can't you simply set draw mode to wireframe?
(OpenGL: glPolygonMode, DX11: rastdescriptor.fillmode)

Create/model, not draw.

#5243094 Resolution scaling and World / Screen Coords

Posted by Lactose! on 27 July 2015 - 07:28 PM

Do logic in whatever size you feel like. Then draw it at whatever size you (or the user, depending on what you allow) feel like.

Scale input to your logic, instead of trying to scale your logic based on screen size.


If your logical window is 640 x 360, and the render resolution is at 1280 x 720, just treat input at coordinate 500 x 250 as if it were at 250x 125.

The exact process will depend a bit on what kind of stuff you're using -- some frameworks operate in normalized values from -1 to 1 across the entire screen, others might only give you access to the pixels and the window size. Regardless, you don't really care what size the window is, you care what size your world and logic is.

#5242996 SFML + Box2D Camera (Or just "Camera" Concept in general)

Posted by Lactose! on 27 July 2015 - 10:34 AM

Or does anyone know if there is a way to track specific variables and act like a breakpoint when their value changes?


If you're using Visual Studio, you can set a breakpoint, and then set a Data Breakpoint (Debug --> New Breakpoint --> New Data Breakpoint...).

Set your address and it should notify you when the memory is written to.


That said, it sounds like maybe your not actually using the same camera as you're constructing.I would guess that your camera instance goes out of scope, and you're using a different (not correctly initialized) camera instance later on, or something like that...

#5242626 Calculating points of rectangle after rotation (Trig) help!

Posted by Lactose! on 25 July 2015 - 11:21 AM

It seems like maybe it's rotating around (0,0) instead of the players pos

I don't have time to read through in more depth right now, but if that's the case...


When rotating around a point, you want to subtract the rotation point, do the sin/cos stuff, and then add the rotation point back in.

You might, as you say, also need to verify if your functions expect radians or degrees.

#5242415 Vector cast

Posted by Lactose! on 24 July 2015 - 09:11 AM

You mean sample code that compiles only if you have Microsoft language extensions enabled (i.e. no /Za).
Else you're gonna have to change that to a const reference, like Brother Bob already mentioned.

Good catch. Thanks for the correction :)

#5242404 Vector cast

Posted by Lactose! on 24 July 2015 - 08:31 AM

EDIT: See other responses in thread for more information.


Assuming C++...

Ensure that your Vector class has a constructor that fits. In your example, it seems like it would Vector::Vector(int x, int y, int z). Doing that should make it work.


Sample code that compiles (in Visual Studio, your mileage may vary -- see Mona2000's reply):

class Vector
	Vector(int a, int b, int c) { x = a; y = b; z = c; }
	int x, y, z;

void Add(Vector &data)
	//Stuff here

void test()
	Add(Vector(1, 2, 3));

#5241997 Custom environment macro

Posted by Lactose! on 22 July 2015 - 01:46 PM

You can create a new solution configuration, and add the define to the preprocessor for that configuration:

1. From the Solution Configurations drop-down (by default containing Release, Debug and Configuration Manager...), select Configuration Manager....

2. In the Active Solution Configuration drop-down, select <New...>.

3. Name your solution configuration something appropriate, e.g. MemLeak Debug or MemLeak Release.

4. Copy settings from an existing solution configuration if appropriate.

5. Close the Configuration Manager.

6. Go to Properties on your project (e.g. right click your project in the Solution Explorer and select Properties).

7. Ensure your new solution configuration is selected as the configuration to be edited.

8. Go to Configuration properties --> C/C++ --> Preprocessor.

9. Under Preprocessor Definitions, add the wanted preprocessor definition -- in your case KHATBOX.

10. Select OK, and you should be good to go.


#ifdef KHATBOX will now be true for your newly created solution configuration, and false for the other ones.

#5241133 New Game Programmer!

Posted by Lactose! on 17 July 2015 - 06:59 PM

I have a for loop.

Yes, but in that for loop, you have a piece of code that will essentially restart the current iteration of the for loop if the randomly chosen card has already been randomly chosen.

As you keep choosing unused cards, the chance of choosing an already chosen card will increase, which means constantly trying to select a new card, taking more and more time.


Other than the issue mentioned above, there's also an issue with how you randomly select a card. You currently choose a card between 1 and 52.

However, your arrays are only initialized to [51], so if card 52 is chosen (which will try to index into your arrays at [52]), you'll be comparing against uninitialized values, which might be what's causing your code to never finish.

Arrays are zero-indexed -- meaning that the first item in an array is at [0], not [1].


The fix for this issue is to simply remove the + 1 part of the random number generation.

Math.Rand() returns a number from 0 (0 is included) up to 1 (1 is not included).

Math.Floor(Math.Rand() * 52) -- this includeds the fix I mentioned -- yields a minimum of 0 and a maximum of 51. This is exactly what we want for indexing into our arrays.

#5240839 How do you write this down?

Posted by Lactose! on 16 July 2015 - 11:07 AM

My attempt at shortening it... Not really pretty, but should be equivalent. This is starting to feel like a coding horror post.

while (true)
	if !((v > 0) && (x < 0))
		if !((v <= 0) && x > 0))
	int n = (x < 0) ? 1 : -1;

	y += x;
	z += y + n;
	x += n;
	if ((x - n) < 0)
		if (doA())
		if (doB())

If the second clause only happens if v is negative (instead of not negative AND zero, as is currently the case), it could be condensed further:

while ((x * v) < 0)
	int n = (x < 0) ? 1 : -1;

	y += x;
	z += y + n;
	x += n;
	if ((x - n) < 0)
		if (doA())
		if (doB())

#5240833 How do you write this down?

Posted by Lactose! on 16 July 2015 - 10:54 AM

I may be wrong, but isn't this equivalent?

	int n = (v > 0 ? 1 : -1);

	x += n;
	y += (x - n);
	z += (y - n);

	if(doA()) doB();
Very hard to be sure without understanding what this does.


Doesn't seem equivalent to me. Firstly, x is never stated to have to reach 0. E.g. if v is positive and x is positive, nothing should happen (in the original code).

Additionally, the x, y and z things also seem wrong. I got this for the stuff inside the while loops:

int n = (x < 0) ? 1 : -1;
y += x;
z += y + n;
x += n;

I rejigged the order the variables are adjusted, so if the order is important in the actual code (it isn't in the posted snippet), then this wouldn't work.

#5240830 How do you write this down?

Posted by Lactose! on 16 July 2015 - 10:40 AM


[…] how do you solve the while clause?

if( v > 0 )

    while( x < 0 );


    whle( x > 0 );

while( abs(x + v) > 0) {
    // blah

What on earth are you doing?


That seems wrong to me.

v might be positive/negative 10000, while x might be positive/negative 5 -- the actual value of v doesn't matter, just whether it's positive or not.

In the posted code, v is never adjusted, while x is. In my example, the while loop should execute 5 times (given valid signs for x and v), which your abs version would not.

#5240650 Broken code

Posted by Lactose! on 15 July 2015 - 07:18 PM


If you have errors with your code, post the actual code that gives the error. Posting "cleaned up" code which doesn't contain the errors or show the full picture just makes everything harder when trying to help.

What you've posted omits too much to point to specific code other than guessing a lot.


That said, my guess is that "final" isn't a valid index for your deck_array. Why it isn't is a whole different question, which requires more information.

#5239708 Visual Studio Not Recognizing #include for SDL?

Posted by Lactose! on 11 July 2015 - 04:35 AM

Hey guys, issue was resolved. 


Posting your solution might help others :)

#5239156 Bugs in code?

Posted by Lactose! on 09 July 2015 - 02:27 AM

but it's not working again..

Define "not working".

Helping someone is a lot harder when you don't know what the problem is.



That said, you're currently clearing the screen right before presenting it, which will essentially discard all rendering you've done before the clear.


You should also separate updating and rendering better than you do. Currently, you render the snake, then update it, then render other stuff -- I'd suggest updating everything that needs to be updated first, and then rendering everything that needs to be rendered after.

Additionally, your snake seems to have a lot of responsibilities -- updating time and input, spawning food, etc. For future projects, I would suggest splitting these responsibilities up further into additional classes. (See also: Single Responsibility Principle).

#5239076 Circular Header-Include Problem

Posted by Lactose! on 08 July 2015 - 04:23 PM

(Didn't want to post it because it's not the cleanest code).

If you have errors in your code, post your actual code. Sometimes posting a "cleaned up" version will remove the source of the error.

Also post the exact error messages you get, don't paraphrase them, etc. Simply saying "then the errors started appearing" doesn't give us enough information.


Don't be too worried about the quality level of your code. We all have code we can look back on and shudder at :)