The account by Darren Fresco, who has been identified as being with Pistorius on two occasions when a gun was fired in public, corroborated much of the evidence of another witness who was at the scene of the sunroof shooting.
'"You can't just touch another man's gun,'" Mr Fresco recalled Pistorius telling the traffic officer in late 2012 after the group was pulled over for speeding.
The double-amputee runner has been charged with premeditated murder for the killing of girlfriend Reeva Steenkamp in the early hours of February 14, 2013.
He also faces three firearms charges, including two for allegedly shooting a gun in public that feature Mr Fresco as a witness. They related to the alleged gunshot out of the sunroof, as well as another incident in which a gun was fired under a table in a busy restaurant in Johannesburg. Pistorius has pleaded not guilty to all four charges.
During the 2012 stop for speeding, according to Mr Fresco, Pistorius also told the police officer: "Now your fingerprints are all over my gun. So if something happens, you're going to be liable for anything that happens."
Mr Fresco said he and Pistorius and Samantha Taylor, the runner's girlfriend at the time and a state witness who has given a similar account of the episode, then drove away.
"Then without prior warning, he shot out the sunroof," Mr Fresco, who was driving, said of Pistorius, who he said was in the passenger seat.
Mr Fresco said he "instinctively" moved over to the right side of the vehicle and away from where the gun was shot, and then asked Pistorius if he was "mad".
"He just laughed," Mr Fresco recalled. "But it felt as if my ear was already bleeding."
Mr Fresco also testified that he took the blame when Mr Fresco's gun, a Glock 27 .40 calibre pistol, was being handled by the Olympic runner under a table in a restaurant in early 2013 and fired. It was about a month before Pistorius killed Miss Steenkamp.
Mr Fresco told the court that he warned Pistorius that the gun was "one-up", meaning it had a bullet in the chamber.
"I knew that he had a big love for weapons ... my assumption was that he had competency," Mr Fresco said in court.
Pistorius has said he shot Miss Steenkamp by accident, fearing she was an intruder in his home. The prosecution says he intentionally killed her after an argument.
In earlier evidence, the chief lawyer for Pistorius questioned the methods of the pathologist who conducted an autopsy on Miss Steenkamp. Professor Gert Saayman was giving evidence for a second day about the gunshot wounds suffered by the model when Pistorius opened fire through a toilet cubicle door at his home before dawn on Valentine's Day last year.
Prof Saayman has asserted that, judging by the food contents in her stomach, Miss Steenkamp probably last ate no more than two hours before her death. Miss Steenkamp was shot after 3am, meaning she must have eaten after 1am. Pistorius has said the couple was in the bedroom by 10pm.
Lawyer Barry Roux asked Prof Saayman what medical texts he had consulted in reaching his conclusion about the food, and said he wanted to see them. Prof Saayman said his findings were a "synthesis" of his own professional experiences and observations in addition to consultation of past studies.
Prof Saayman also said the amount of urine in Miss Steenkamp's bladder at the time of her death amounted to the rough equivalent of a teaspoon. The evidence could relate to theories about whether Miss Steenkamp had gotten up in the middle of the night to go to the toilet, as Pistorius contends, or was there following a loud argument with the runner, as the prosecution has suggested.
The pathologist said he had conducted between 10,000 and 15,000 autopsies over 30 years.