my solutions

The Partridge Family were neither partridges nor a family. Discuss.
albinopapa
Posts: 4373
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: my solutions

Post by albinopapa » August 4th, 2018, 7:18 pm

It kind of depends. When you return an object by value, it can either be copy elided or it becomes an rvalue which is automatically moved either through construction or assignment.

Code: Select all

Thing make_thing()
{
    // Creates a temporary 
    return Thing();
}

// Assigns the temporary object from make_thing to thing
auto thing = make_thing(); 

// Ends up being the same as 
auto thing = Thing();
I'm guessing in the past, compilers would create the temporary, then make a copy in the return register, then assign the copy in the return register to the lvalue. With C++17, copy elision is suppose to be guaranteed, so the compiler just takes into account which temporary is being returned and creates it in the return register so it doesn't have to make the copy.

Otherwise, yes, the whole reason std::move was brought about was to avoid these copies since temporaries are going to die anyway at the end of the function, why not just move their resources out. So instead of forcing the programmer to type: return std::move( temporary ); the compiler usually will do this for you.
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com

randomGuy
Posts: 32
Joined: May 31st, 2018, 11:45 am

Re: my solutions

Post by randomGuy » August 14th, 2018, 8:13 am

https://youtu.be/8_U_pake6J0?t=1031

I don't understand why would the object on the screen change it's shape and why does a floating point error occur.
So I made the function TranslateBy directly affect std::vector<Vec2> model to see how will the shape change when I moved it a lot on the screen but it just remains the same.

Code: Select all

	void TranslateBy( const Vec2& offset )
	{
		//pos += offset;
		for (auto& v : model)
		{
			v += offset;
		}

	}
	std::vector<Vec2> GetPolyline() const
	{
		//auto poly = model;
		//for( auto& v : poly )
		//{
		//	v *= scale;
		//	v += pos;
		//}
		return model;
	}

User avatar
chili
Site Admin
Posts: 3948
Joined: December 31st, 2011, 4:53 pm
Location: Japan
Contact:

Re: my solutions

Post by chili » August 14th, 2018, 12:16 pm

Not so much simple translation, I was talking more like rotation. With that you have rounding from the precise actual values. But depending on the scale of your model, you would have to do *a lot* of transformations to start to see some error build up. It was more of a theoretical observation than a huge and immediately apparent issue.

If you wanted to do a slightly better test you could have it do a lot of rotations (like millions maybe) to a star and see if you can get any deformation.
Chili

albinopapa
Posts: 4373
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: my solutions

Post by albinopapa » August 14th, 2018, 8:20 pm

For floating point numbers, you have 32 bits divided into three sections.

A sign bit ( positive or negative )
8 bit exponent ( 1 to 126 are negative exponents and 128 to 254 are positive )
23 mantissa bits ( integral numbers ) a range from 0 to 8,388,607

Code: Select all

struct FloatingPoint
{
	FloatingPoint( const float val )
	{
		int ival = *reinterpret_cast< const int* >( &val );
		signbit = ( ival & expMask ) >> 31;
		exponentbits = ( ival & expMask ) >> 23;
		precisionbits = ival & manMask;
	}
	operator float()const
	{
		int ival = ( signbit << 31 ) | ( exponentbits << 23 ) | ( precisionbits & 0x007FFFFF );
		return *( reinterpret_cast< float* >( &ival ) );
	}
	static constexpr auto sgnMask = 0x80000000u;
	static constexpr auto expMask = 0x7F800000u;
	static constexpr auto manMask = 0x007FFFFFu;

	unsigned int signbit : 1;
	unsigned int exponentbits : 8;
	unsigned int precisionbits : 23;
};

#include <iostream>
int main()
{
	constexpr size_t szfp = sizeof( FloatingPoint );
	auto fp = FloatingPoint( 0.f );
	float fval = 0.f;
	for( int counter = 0; counter < 1'000'000; ++counter )
	{
		std::cout << "Sign bit: " << fp.signbit << "\n";
		std::cout << "Exponent: " << fp.exponentbits << "\n";
		std::cout << "Mantissa: " << fp.precisionbits << "\n";

		fval += .000001f;
		fp = FloatingPoint( fval );

	}

	return 0;
}
Ran the loop from 0 to 1,000,000 incrementing the float value by .000001f each step. This should have ended on 0.999999, but the end result was 1.00903893f. This is the accumulation error you get by adding floats together over time. It's usually best to multiply, but even then you can still get rounding errors.
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com

randomGuy
Posts: 32
Joined: May 31st, 2018, 11:45 am

Re: my solutions

Post by randomGuy » August 15th, 2018, 7:44 am

I want to post a solution to show you guys something but the whole thing is around 500 mb.
I tried running the bat file from Chilli_Clean&deletmyself.zip but nothing happens. I assume it's because it was made for older version on visual studio and Im using 2017.
When I delete debug and release folders there is still a file in \advmath\.vs\Chili Framework 2016\v15 called Browse.VC which is 50 mb, should I remove it also?

albinopapa
Posts: 4373
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: my solutions

Post by albinopapa » August 15th, 2018, 9:27 am

You can delete the whole .vs folder, VS will recreate it next time you open that project. An alternative to your dilemma is to upload your project to GitHub ( provided you are lucky enough to have all the right files and folders ignored ) and we can check it out that way. This way you won't have the space limit that the forums require, you won't be bombarding chili's servers with bandwidth and if someone finds a bug or something, they can file a pull request.

If the biggest issue is assets like sounds and images, you could probably upload them to a dropbox account and post a Share link that we can download them separately from the project.
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com

randomGuy
Posts: 32
Joined: May 31st, 2018, 11:45 am

Re: my solutions

Post by randomGuy » August 15th, 2018, 11:10 am

I've tried to make the camera rotate on advanced tutorial 2 without knowing how rotation works yet but I did spend some time to figure out how Star::Make works.

https://uploadfiles.io/jrrvw
use 'D' and 'A' to rotate

User avatar
chili
Site Admin
Posts: 3948
Joined: December 31st, 2011, 4:53 pm
Location: Japan
Contact:

Re: my solutions

Post by chili » August 15th, 2018, 12:11 pm

Looks like you got it.

It's gonna make the homework for A4 a bit easier ;)
Chili

randomGuy
Posts: 32
Joined: May 31st, 2018, 11:45 am

Re: my solutions

Post by randomGuy » August 29th, 2018, 1:20 pm

I tried implementing collision before watching advanced 3.2 but it's not how it should be and Im stuck.
I want to make it like it's in the right side of the picture.

We have this plank which has length, slope and left point coordinates.
We figure out the offset of the slope.
To get the y position of the plank at the ball position we multiple the slope with how far away the ball is from the left side of the plank and add offset.
We have a ball and its 4 sides by adding/subtracting it's radius on ball's position, so we treat it as rectangle.

This collision detection doesn't work well if the slope is high because it's basically retarded.
The ball is already a little bit in the plank when its top side collides with the bottom side of the plank.
Well Im about to watch the video and find out how its properly made.
Attachments
collision.jpg
(21.85 KiB) Not downloaded yet

albinopapa
Posts: 4373
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: my solutions

Post by albinopapa » August 30th, 2018, 3:09 am

Sounds like you're pretty close actually.
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com

Post Reply