 Home
 » Viewing Profile: Reputation: Álvaro
Álvaro
Member Since 07 Mar 2002Offline Last Active Today, 06:22 PM
Community Stats
 Group Crossbones+
 Active Posts 7,568
 Profile Views 30,466
 Submitted Links 0
 Member Title Member
 Age Age Unknown
 Birthday Birthday Unknown

Gender
Not Telling

Location
New York (USA)
#5307460 I have an Idea..........
Posted by Álvaro on 23 August 2016  01:12 PM
#5306259 Alternatives for std::heap?
Posted by Álvaro on 16 August 2016  05:54 PM
#5305979 Point around point rotation
Posted by Álvaro on 15 August 2016  08:43 AM
If you stop thinking in angles and start thinking of the rotation as the primary object to think about, you can get around this problem. If you use complex numbers, like in my code, you can use i as your rotation of 90 degrees. If you are not comfortable with complex numbers, you can still store the cosine and the sine in an object and call that a rotation. Then (0, 1) is exactly the rotation you want.
#5305907 Point around point rotation
Posted by Álvaro on 15 August 2016  02:54 AM
Here's one idea to make the code a bit simpler: If you have a function that rotates around the origin, you can write
glm::vec2 rotate_around_center(glm::vec2 point, glm::vec2 center, GLfloat angle) { return rotate_around_origin(point  center, angle) + center; }Another suggestion is to remove the conversion to radians and use radians consistently throughout your code. There is no reason to keep around degrees anywhere. If you need to display an angle in degrees, make the conversion just before displaying it, but don't pollute the rest of the program with degrees.
A slightly different mathematical approach is using complex numbers to represent both points on the plane and rotations. The point (x,y) becomes the number x+i*y, and the rotation of an angle alpha becomes cos(alpha)+i*sin(alpha). Now applying a rotation around the origin is achieved by simply multiplying the complex numbers corresponding to the point and the rotation.
EDIT: Here's some sample code:
#include <iostream> #include <complex> typedef std::complex<float> Complex; float const Tau = std::atan(1.0f) * 8.0f; float const Degree = Tau / 360.0f; Complex rotate_around_origin(Complex point, Complex rotation) { return point * rotation; } Complex rotate_around_center(Complex point, Complex center, Complex rotation) { return rotate_around_origin(point  center, rotation) + center; } Complex rotation_from_angle(float angle) { return Complex(std::cos(angle), std::sin(angle)); } int main() { Complex p(2.0, 5.0); Complex center(1.0, 0.0); Complex rotation = rotation_from_angle(90.0f * Degree); Complex rotated_p = rotate_around_center(p, center, rotation); std::cout << rotated_p << '\n'; }
#5305691 Calculus Problem!
Posted by Álvaro on 13 August 2016  10:35 PM
Does anyone know how to integrate this expression for x please?:
ln(ax^n + c)
a, n and c are of course constants, and bot a and c should be positive but n will tend to be negative.
Why are you trying to do that? Without context it's hard to know if using a numerical method would be acceptable, for instance.
#5305147 Fast Square Root For Distance Calculations?
Posted by Álvaro on 10 August 2016  12:14 PM
#5304404 Only 12 Enemies, And My Fps Drops To 30, Why Is That?
Posted by Álvaro on 06 August 2016  02:22 PM
#5304208 Only 12 Enemies, And My Fps Drops To 30, Why Is That?
Posted by Álvaro on 05 August 2016  09:03 AM
By now you could have tried it, tested it and posted here to tell us how well it worked.
#5304162 Quick Way To Invert Matrix
Posted by Álvaro on 05 August 2016  05:13 AM
He use a determinant , who know what it is ?
I do. Think of a 3x3 square matrix as a linear mapping from a R^3 to R^3. Linear mappings have the feature that volumes are scaled by them. The determinant is the scale that the volumes are multiplied by.
And who can tell how to use it to compute inverse matrix?
The most obvious connection is Cramer's rule.
For advanced users: There are other ways in which the determinant is connected to the inverse. One I learned about recently is that the gradient of the determinant (as a function of n^2 variables) is the transpose of the inverse times the determinant squared, or something like that. It turns you can use that fact together with automatic differentiation to compute the inverse in a really whacky way.
#5303973 String To Char* :(
Posted by Álvaro on 04 August 2016  07:38 AM
Alvaro my program by default uses char* without null terminator
Sure, but strcpy doesn't care what conventions you have in your head.
strcpy(p, str.c_str());
#5303960 String To Char* :(
Posted by Álvaro on 04 August 2016  06:18 AM
p = new char[ (*len) ];
That's not enough space to store the string and a terminating zero.
if ((*len) > 0)
What's the point of that condition? What would you like to happen if str is an empty string?
#5303676 Only 12 Enemies, And My Fps Drops To 30, Why Is That?
Posted by Álvaro on 02 August 2016  11:44 AM
void MMORPG::getBoneLocation(Shader& shader) { for (unsigned int i = 0 ; i < 100 ; i++) { char Name[128]; memset(Name, 0, sizeof(Name)); snprintf(Name, sizeof(Name), "gBones[%d]", i); boneLocation[i] = glGetUniformLocation( shader.programID, Name ); } }
I can think of several problems with that piece of code, but I'll point out two:
* You don't need to call memset at all. Just erase that line.
* getBoneLocation is a pretty bad name for a function that doesn't get you the location of a bone. Perhaps computeBoneLocations or precomputeBoneLocations would do.
#5302362 How To Make My Crosshair Red When Over An Enemy?
Posted by Álvaro on 24 July 2016  04:10 PM
I can't find any material on collision detection between a ray and a box in any of my books. This means that it should be easy, but nothing comes to mind, any ideas?
Figure out how to compute the intersection between a ray and a plane. You can do it in such a way that the result is expressed in a frame of reference in the plane such that both coordinates will be between 0 and 1 precisely when the rectangular face has been hit. Now use that six times.
#5301779 Rotating Camera
Posted by Álvaro on 21 July 2016  09:58 AM
Here's some C++ code that does what you want:
#include <iostream> struct Vector { float x, y, z; Vector(float x, float y, float z) : x(x), y(y), z(z) { } }; struct Point { float x, y, z; Point(float x, float y, float z) : x(x), y(y), z(z) { } }; std::ostream &operator<<(std::ostream &os, Point p) { return os << '(' << p.x << ',' << p.y << ',' << p.z << ')'; } Vector operator(Point p1, Point p2) { return Vector(p1.xp2.x, p1.yp2.y, p1.zp2.z); } Point operator+(Point p, Vector v) { return Point(p.x+v.x, p.y+v.y, p.z+v.z); } //  Start reading here  Vector rotate_about_y_axis(Vector v, float cos, float sin) { return Vector(v.x * cos  v.z * sin, v.y, v.x * sin + v.z * cos); } Point rotate_about_y_axis_around_center(Point p, float cos, float sin, Point center) { return center + rotate_about_y_axis(p  center, cos, sin); } int main() { Point eye(0.0f, 1.2f, 0.0f); Point lookat(0.0f, 1.0f, 2.0f); float cos = 0.0f; // std::cos(angle) float sin = 1.0f; // std::sin(angle) Point rotated_lookat = rotate_about_y_axis_around_center(lookat, cos, sin, eye); std::cout << "lookat after rotation = " << rotated_lookat << '\n'; }
#5301662 Rotating Camera
Posted by Álvaro on 20 July 2016  08:13 PM
In order to rotate a point around another point, first apply a translation that makes the center of rotation be the origin, then rotate, then undo the translation.
Point rotate_around_point(Point p, Point center, Rotation rotation) { return rotate_around_origin(p  center, rotation) + center; }
Are you missing anything?