C++ :: Get Angle Of Bullet After Bouncing?
Jun 30, 2014
I'm trying to make a bullet bounce after it hits a wall. I think bouncing on the top and bottom wall works perfectly, but it won't bounce off of the left and right walls. How would I get it to bounce? This is how I get the direction the bullet it going whenever I shoot.
player.dir = GetAngle(player.mouseX, player.mouseY, player.x, player.y);
float GetAngle(float x1, float y1, float x2, float y2) {
return atan2(y1 - y2, x1 - x2);
}
Also what I was trying to do to make the bullet bounce.
if (bullets[i].x < 10 || bullets[i].x > screenWidth - 10 ||
bullets[i].y < 10 || bullets[i].y > screenHeight - 10) {
if (bullets[i].type == 8)
bullets[i].dir *= -1;
}
View 3 Replies
ADVERTISEMENT
Jul 11, 2013
I would like to set the bullet library to GCC. I downloaded source code of bullet but i don't know how to set that.
View 6 Replies
View Related
Jun 9, 2014
I'm using the Bullet physics library in my program and am currently trying to implement picking. The way the world is currently set up, there is a terrain with a box on top of it. Whenever I click on the box, my program only registers that the terrain has been clicked and doesn't recognize that the box has been clicked.
void PhysicsEngine::RayTest() {
vec2 Mouse = MOUSE_POSITION;
Mouse.y = WINDOW_DIMENSIONS.y - Mouse.y;
vec4 RayStart = vec4(2*Mouse.x/WINDOW_DIMENSIONS.x - 1,2*Mouse.y/WINDOW_DIMENSIONS.y - 1, -1, 1);
vec4 RayEnd = RayStart; RayEnd.z = 0;
[Code] .....
View 3 Replies
View Related
Apr 19, 2014
i'm working on a robotics project, to move the robot from it's current position to target position i need to calculate the angle first before i can move the robot.this the code I use to calculate the angle:
double cal_angle ( int current_x , int current_y , int tar_x , int tar_y )
{
return atan2(tar_y - current_y, tar_x - current_x);
}
int main ()
[code]....
as u can see the angle between x4,y4 to x1,y1 should be 3.14 (180)however , the result are correct as long as the distance from the current position to target position > 1 (not sure actually).
View 2 Replies
View Related
Feb 20, 2014
My question is not in c++ programing , but because my aim is to make code that calculate the three angles between two vector i ask my question here
So as the title i have three point that create two vector and I want to get the angles in x,y and z of the point2
I used crosproduct that give me one angle without axe , I don't know in which axe this angle
My aim is the three angles for the 3 axes ....
View 7 Replies
View Related
Nov 10, 2013
I am making a game and I am trying to rotate an image so that it is always pointing at the player. I have two lines, the first point of both of them is on the image and the second point of one line is on the last position of the player, and the second point of the other one is on the current position of the player. To rotate the image I need to get the angle between the two lines. how I can get that angle with only the points from the lines?
View 7 Replies
View Related
Dec 7, 2014
On a right angled triangle, if the user inputs only ONE side length (not the hypotenuse) and only ONE angle, what code is required to work out the hypotenuse? I know how to work out the final side and the remaining angle once I have this.
View 4 Replies
View Related
Apr 25, 2012
I developed this simple sample program to test cos():
Code:
#include <cmath>
#include <iostream>
using namespace std;
int main() {
const float radiansToDegrees = 180.0f / 3.141592653589793f;
float c = sqrt(2.0f);
float a = 1;
float angleRadians = cos(a/c);
float angle = radiansToDegrees*angleRadians;
}
I expected angle to be 45 exactly, but it's value is: angle = 43.558804
Why is the angle not 45 degrees? What did I do wrong?
View 4 Replies
View Related
Mar 17, 2014
I want to use an accelerometer to simply light up an LED at a certain angle. I want to use all three axis each corresponding to a different LED.
I am however getting no change in the LEDs. My code is below.
Code:
#pragma config FOSC = INTIO67, FCMEN = OFF, IESO = OFF // CONFIG1H
#pragma config PWRT = OFF, BOREN = SBORDIS, BORV = 30 // CONFIG2L
#pragma config WDTEN = OFF, WDTPS = 32768 // CONFIG2H
#pragma config MCLRE = OFF, LPT1OSC = OFF, PBADEN = ON, CCP2MX = PORTC // CONFIG3H
#pragma config STVREN = ON, LVP = OFF, XINST = OFF // CONFIG4L
[Code]...
View 6 Replies
View Related
Oct 7, 2013
Let (x,y) be the center of the circle. (x,y) will not be (0,0). I have radius of the circle. Now i want to find the angle and radius of the given point inside the circle.
View 2 Replies
View Related
Apr 16, 2012
In a cartesian coordinate system, I want to be able to predict a compass angle of an object. So I have a base position of (0,0) and then a distance and compass angle to an object. This object also has a heading and a speed. How can I predict the new compass angle of the object with that information?
my coordinate system is like this:
Code:
0 y
|
|
270-------------- 90 x
|
|
180
I think the first step would be to compute the cartesian coordinates of the object:
float degs_to_rads = 3.141592653589793 / 180.0;
x = distance * sin(angle*degs_to_rads);
y = distance * cos(angle*degs_to_rads);
then the next step would be to compute the predicted x and y from the speed and heading of the object:
predictedx = ??
predictedy = ??
then finally convert back to an angle, and distance:
newDistance = sqrt(predictedx^2 + predictedy^2);
newAngle = atan2(predictedy, predictedx);
fill in the blanks?? Are my other things correct?
View 10 Replies
View Related
Jul 24, 2013
This is an assignment which the purpose is to calculate an angle value in form of trigonometric functions. These are the codes that I've wrote so far.
#include <iostream>
#include <cstdlib>
using namespace std;
void menu(double &value) {
system("cls");
cout<<"*****Trigonometry Program*****"<<endl;
[Code] ....
I have completed the codes for the interface part. Before I proceed with the formula for the trigonometric functions, I would like to make sure the program is Error-free, which if there is accidental invalid input from the user, the program would the user to enter another input until it is a valid response.
The only problem I have encountered for this matter was in menu(value)
If I enter an integer, the program will proceed without error. However, If I enter a character, the program will slip into an endless loop which constantly shows this
*****Trigonometry Program*****
Please enter an angle value => Is the angle in Degree or Radian?
Type D if it is in Degree
Type R if it is in Radian
Your response=> 0 //my initial input for value
Do you want to continue?
Type Y to continue
Type any other key to stop
Your response =>
Where is the source of the problem? I'm pretty sure it's the loop, but I don't know what to do.
View 2 Replies
View Related
Sep 22, 2013
I want to make an object, which moves from x1,y1 to x2,y2 in a straight line, also make a sinus over the line (so the x,0 is the line itself, and cux,cury is the object. So the object will move as a sinus over the line. How do I do this in c++?
View 3 Replies
View Related
Sep 25, 2013
I m developing an application using kinect.The IDE I use is Visual studio 2012 and kinect SDK 1.8.I m developing using vc++
I want to overlay an image on the person tracked when the person turns 180 degress to kinect. ie the person is not facing the kinect.
how do i track the rotation angle of the person as he/she turns away from kinect.
View 7 Replies
View Related