When BillG ran Microsoft, he was a total asshole. Now he's trying to be remembered in a positive light, but he's still thin skinned when it comes to competition.
I really doubt that he's doing that to create a better legacy. It's just that people at his level can do whatever they like, absolutely anything. So some are buying Hawaii islands and others try and help other people. Gates is one of the latter.
His family sort of has a history of doing this kind of thing.
Is Google really his competition?
It is probably not a competition to the foundation which gets a lot of his time but I'd imagine he probably sees Google as his competition.
Google, along with Apple, will always be the company that beat him.