Tag Info

New answers tagged

2

Assuming that location is the uniform location you've already retrieved from the shader, and vec is your vector, then in C++11 you can do: glUniform3fv(location, vec.size(), reinterpret_cast<GLfloat *>(vec.data())); Prior to C++11: glUniform3fv(location, vec.size(), reinterpret_cast<GLfloat *>(&vec[0])); The "old" method will work in ...


0

Assuming your Vector3f class is laid out linear in memory. std::vector<Vector3f> m_verts; float* address = &m_verts[0].x; This will get the address of the x value of the first element, so long as your data is laid out linearly, and your sizeof(Vector3f) == size(float) * 3 you should be fine.


3

I would consider generating waypoint graphs instead. They're easy to work with, they give optimal paths, and are generally fast enough for reasonably small environments. The optimal path will be a series of line segments, and each vertex in the path will either be the origin, the destination, or a vertex of one of your obstacles. So although your ...


4

new answer: In the real world, since this field is not densely populated, simply tell the characters to move in the desired direction and once they approach an obstacle, to go clockwise or counter-clockwise around it (depending on which way is shorter). To improve on this, you can walk the characters towards corners instead: In the general case, you ...


1

First use Zehelvion answer to make the car turn correctly, then: Use the timestamp, you measure how much time it took for your last iteration and use that to modulate the speed at which you are changing things. void RunGame(float deltatime) { if (key.KeyCode == Keys.Up) { Player1.speed += accelaration * deltatime Player1.speed = ...


5

Start by adding a variable for the angle that the car is moving at. float angle = Math.Pi / 2; Then add a variable for the current speed. float speed = 0.0; Now create three constants: public static final float acceleration = 0.1; public static final float maxSpeed = 5.0; public static final float rotationRate = Math.Pi / 50; For starters, get your ...


0

When you create a rotation matrix or quaternion from an angle, you are actually taking the sine and cosine of a numeric value in radians. Your value in degrees is being converted to radians, so 90 degrees becomes π/4. π is not something that can be represented accurately in floating point. This is where the accuracy loss is coming from. If you take the ...


1

Floating point math is not perfect. You're trying to compress an infinite set (all real numbers) into an extremely finite space (32 bits). Consequently, not every number can be accurately represented, and some numbers will suffer from rounding error. Basically, as you do increasingly more math on some particular value, you increase the chance(*) that the ...


3

Take an arrow image without any perspective Rotate the image by the desired amount of degree Scale the image vertically.


0

It is unclear as to why you are using a perpendicular. There isn't enough detail to describe the problem you are working. However, perhaps this will help. A 2D vector can be described using the values (x, y). The left hand perpendicular and the right hand perpendicular are easily calculated. The left hand perpendicular of (x, y) is (-y, x). The Right hand ...


0

In neutral position you have defined forward to be the positive Z vector (0, 0, 1). There are two vectors perpendicular to that vector (if we ignore sign), up (0, 1, 0) and left (1, 0, 0). The easiest thing would be to create all three vectors and to apply a matrix transformation to find the left, up, and forward vector in 'camera space'. Matrix transform ...


2

The vector between A and B is B - A. The magnitude of this vector is the distance between these points. If point A is traveling along this vector then it has reached point B when the magnitude is 0 and it passes B when the vector components change signs (positive to negative, or negative to positive) as compared to the original B - A vector. For example, ...


4

The sign of the dot-product of C with AB will be positive when the vector component of CD parallel to vector AB is in the direction AB, and negative when it is in the direction BA. The sign of the (z-component of the) cross-product of vector CD with vector AB will indicate which side of AB the agent is approaching from. Depending on your sign conventions, ...


2

If I understand what you're asking, the vector CD is just a vector, not a ray, so only the direction matters, not location. However, AB is a line segment, not just a vector, so its location matters. Your tests have one 'if' test to make two cases, but I think you actually have four cases. Let's look at the diagram in AB's reference frame: If you can ...


5

You're on the right track. I would start by determining the player's direction based on the keyboard state: direction = Vector(0, 0) if up pressed: direction = direction + Vector(0, -1) if down pressed: direction = direction + Vector(0, 1) if left pressed: direction = direction + Vector(-1, 0) if right pressed: direction = direction + ...


0

Ex-Bukkit dev here. Not sure if you still want this with the whole bukkit situation... Really, the only thing to do here is use some tricky packets, to make it not collide, or simply offset the y of where you spawn in up one. You could even use trig to see whee the arrow would fly, and spawn it one block in that direction. Easiest would be to simply offset ...


0

I think you could switch your cos with sin and vise versa if you're really against adding 90 in your function, but I think adding 90 is a perfectly viable solution. Once a function works, you shouldn't have to care what's inside of it.


1

The distance moved does not take the delta time into account, so if you get updates coming at an irregular interval you'll get jerky motion. Scale your speed by the elapsed time, dt; public void update(float dt){ if(cont == true){ vec = makeVec(); x += vec.x * speed * dt; y += vec.y * speed * dt; } } This might mean you'll ...


2

I believe I see two problems here: var rotationMatrix = Matrix4.CreateFromAxisAngle(target, rotation); This line is passing the target vector into the method to create a rotation. That's probably not right. If you want to rotate about the axis shown in your picture, you'd want to pass it the global up vector, like you do in your LookAt line. The second ...


0

I had to call glUseProgram(program) before glUniformMatrix4fv() or any other uniform call.


1

He's trying to oscillate between V and V+U*0.01+R*0.1, I think. If you want to visualize, it is trying to do something like the picture below: The arrow at the top represents the path DIR will take as time proceeds and it will go back to V when the sin value becomes zero. The summation, just adds the 'perturb' effect to the DIR vector, so that it doesn't ...


4

The three component vectors right, up, and forward probably point along the axes x, y, and z relative to the camera. So by adding these vectors together you can compose any other vector. It works the same as if you built a vector by specifying its three elements individually, except that you are adding three vectors which each have one non-zero element. ...



Top 50 recent answers are included