# too_many_stars

Member

132

336 Neutral

• Rank
Member

• Interests
Art
Programming
1. ## plane point distance help

Thanks for the replies guys. But I must be missing something. Given the correct formula that was quoted: dist = dot( plane_normal , point ) - plane_distance As opposed to the one I used: dist = dot( plane_normal , point ) + plane_distance and the same planes I defined above, we get the following answers. Plane plane1(Vec2(1,0),0) Plane plane2(Vec2(1,0),50) Plane plane3(Vec2(-1,0),350) Plane plane4(Vec2(-1,0),400) and a Point at (200,0) The following would be the distances point to plane1 = dot( Vec2(1,0) , Vec2(200,0)) - 0 = 200 //Correct distance point to plane2 = dot( Vec2(1,0) , Vec2(200,0)) - 50 = 150 //Correct distance point to plane3 = dot( Vec2(-1,0), Vec2(200,0)) - 350 = -200 - 350 = -550//Wrong distance //s/b 150 point to plane4 = dot( Vec2(-1,0), Vec2(200,0)) - 400 = -200 - 400 = -600 //Wrong distance s/b 200 Whether you add or subtract the plane distance from the dot product, you will still get the wrong numbers (as far as I can tell) The only way I can think of getting around this is using negative plane distances in some cases, which is not very intuitive. Thanks, Mike
2. ## plane point distance help

Hello Everyone, I am having an issue with a point plane distances, and was wondering if anyone could help me. To start, a plane is defined by a unit normal, and a distance from the origin Plane(Vec2,float) while a point is simply a point in space Vec2. To get the distance between a point and a plane, usually something like this is done: float distance = dot( plane_normal , point ) + plane_distance_from_origin. So far so good. The issue lies with the following example. Say we have: This also assumes that top left is the origin. Plane plane1(Vec2(1,0),0) Plane plane2(Vec2(1,0),50) Plane plane3(Vec2(-1,0),350) Plane plane4(Vec2(-1,0),400) and a Point at (200,0) The following would be the distances point to plane1 = dot( Vec2(1,0) , Vec2(200,0)) + 0 = 200 //Correct distance point to plane2 = dot( Vec2(1,0) , Vec2(200,0)) + 50 = 250 //WRONG!! incorrect distance. S/B 150 point to plane3 = dot( Vec2(-1,0), Vec2(200,0)) + 350 = -200 + 350 = 150 //Correct distance point to plane4 = dot( Vec2(-1,0), Vec2(200,0)) + 400 = -200 + 400 = 200 //Correct distance My issue is with "point to plane2" distance. I am not sure how to deal with this problem. Could someone please suggest a solution, or give me a source. Thank you very much. Mike

Hello Everyone, I am having an issue getting my shaders to work. Here is what I have. This is the rendering function. glUseProgram( program_id ); GLfloat v[6] = { 0.0f , 0.0f , 1.0f , 1.0f , 1.0f, 0.0f }; GLuint vbo_id = 0; glGenBuffers( 1 , &vbo_id); glBindBuffer( GL_ARRAY_BUFFER , vbo_id); glBufferData( GL_ARRAY_BUFFER , sizeof(v) , v , GL_STATIC_DRAW); glEnableVertexAttribArray( 0 ); glBindBuffer( GL_ARRAY_BUFFER , vbo_id ); glVertexAttribPointer( 0 , 2 , GL_FLOAT, GL_FALSE , 0 , 0 ); glDrawArrays( GL_TRIANGLES , 0 , 3 ); glBindBuffer( GL_ARRAY_BUFFER , 0 ); glDisableVertexAttribArray(0); And the vertex shader #version 330 in vec2 vertex_position; //layout( location = 0 ) in vec2 vertex_position; void main(){ gl_Position.xy = vertex_position * 1.2; gl_Position.z = 0; gl_Position.w = 1; } The fragment shader #version 330 void main(){ gl_FragColor = vec4(1.0,0.0,0.0,1.0); } I did not post the compiling , linking and attribute adding code because it appears to work. For example, if I make a syntax error in one the shaders, it get a warning. Or if there's a linker problem for example. My issue is that I do get a triangle to show up on the screen, but no matter what I do to the vertex or fragment shaders (for example changing the color or size ) it has no effect with what I see on the screen. In essence, there appears to be no communication between the shaders and glew. My frustration is further compounded by the fact that I was able to get this working before on the same laptop. If anyone has any ideas on what could be wrong with my incredibly simple program, please let me know. Thanks, Mike
4. ## std::vector and iterator question

@ Alberth and Alvaro I have implemented a hierarchical space partitioning system used for broad phase collision detection. What I require, is a std::vector (since insertion @ end is quick) to be returned with all the neighbors. Every update step, this vector will (in all likelihood )be of a different size, and hold different game objects. Therefore, if I understand my problem correctly, I only have a few options. 1. The Naive way I am doing it, simply by pushing back a std::vector that's not part of the class every update 2. Some sophisticated iterator way, which allocates enough memory to a member variable std::vector in the class construct, and every update step, uses these iterators to keep track of the elements in the vector. (My original question) 3. Make the std::vector a member variable like Alberth suggests. However, I still have to clear the vector every update step so I can fill it with unique objects and so that I know the size. This seems much like #1. above. Unless I am missing something (which would not be the first time) I think that's how vectors work. @ApochPIQ I will have a look at stable_partitions tonight, it's always good to learn something new, even if takes a while to sink in. Thanks for all the input, Mike
5. ## std::vector and iterator question

I must be going crazy or blind, but I can't find the code tags. I disabled my ad blocker as well. I got the idea by looking at Mat Buckland's source code from Programming AI by example. He uses a spatial partition grid to update entities within a tag radius. But he uses some iterator optimization trick, which I don't understand. I wish I could post the code but it would be a jumbled mess without the tags.
6. ## std::vector and iterator question

Hello everyone, A quick question to speed up my code a little bit. Right now, I have a function like this which is part of a class. std::vector MyClass::getObjects(){ std::vector objects; for(some condition...){ if(condition met){ objects.push_back(object); } } return objects; } The problem is I am constantly pushing back objects every frame. In the class constructor, I would like to create a member variable std::vector(1000,null) and instead of pushing back, I would like to range over the container with iterators. For example, one iterator for the first position and another for the current position. So I would like to end up with something like this std::vector MyClass::getObjects(){ std::vector objects; //now a member variable iterator end; //also a member variable for(some condition...){ if(condition met){ assign a place in vector for object and increase iterator //now sure show to get this accommplished } } return objects; } Later in the code.. i would like to be able to go through the container from begin to some arbitrary position end. Please keep in mind that the number of objects in the container will change each frame. Question 1. Is this an optimization worth doing? Question 2. If above is true, please show me how. Thanks, Mike P.S What happened to the code tags?
7. ## 3D collision question

Thanks Irlan,   That's what I suspected, that most of the work is done in world space. Porting over to 3D from 2D, I just want to make sure I understand the foundations before I get too far along and then have to change the entire collision system.   Mike
8. ## 3D collision question

Hello everyone,   Right now I am reading 3D math primer by Fletcher Dunn and Ian Parberry and looking at their AABB3 class (around page 304).   The way they choose to represent their AABB3 class is with:   Vec3 min, Vec3 max   Note there's no position   To move the verts of the  AABB around, they use a 4x3 matrix which means that the AABB resides exclusively in local space.   However, the collision tests for the AABB class such as   bool AABB3::intersectSphere(const Vec3& center, float radius)const    and bool AABB3::intersectAABB(args...)   in the implemention detail all appear to be in local space.   Having come from the 2D realm, where I handled all collisions, including contact points, normals, penetration etc in world space, is it better in 3D to do all this in local space?   Perhaps I am missing something as well (it would not be the first time)     Thanks,   Mike
9. ## spiral physics help

Hi Alvaro,   Yes, I am looking for F=ma => a=F/m. I know the mass, but I don't know how to calculate the Force vector which of course needs a normalized direction and a magnitude for a spiral.   Thanks,   Mike
10. ## spiral physics help

Hello Everyone,   Wondering if anyone has some ideas for me. This is also for 2D. Given a circle C(pos,r) I would like to drop a particle of arbitrary mass in, and watch it spiral towards the center.   I suspect I can use the Logarithmic Spiral to solve this problem, for example from here http://mathworld.wolfram.com/LogarithmicSpiral.html   However, it's position based. What I need is a directional force proportional to the distance from the center. So as the particle gets closer and closer to the center, the force increases.   Any sources or ideas would be much appraciated.   Thanks in advance,   Mike
11. ## missing matrix_projection.hpp from glm

Hello Everyone,   Not sure if I am going crazy but I just downloaded the latest glm version, and I need to call: glm::perspective which I belive is in glm/gtc/the matrix_projection.hpp file in the glm library.   However, I can't find this file anywhere. Is this something new where we need to create the perspective matrix ourselves, or am I missing something embarassingly obvious.   Thanks,   Mike
12. ## Good form using "this" pointer?

Thanks for all the great reply guys.   I just want to make it clear that I don't use the above code snippet, as I rarely see anything of the sort when looking at other people's source code. But once in a while I do come upon it and I was just curious that's all. The initilizer list is my preference.   I also know that many people here work/worked for professional software companies, so I wanted to know some common practices.   Thanks again,   Mike
13. ## Good form using "this" pointer?

Hello everyone,   Not an altogether important question but one I have been wandering about for some time. Say we have the following example. Point(int x, int y){ this->x=x; this->y=y; } I don't see this very often, and I have heard, and read some snarky remarks with respect to the above code. Just wandering if there are any problems which I don't understand.   Bad form/style by 2016 standards? Performance hit? Too verbose?   Thanks,   Mike
14. ## c++, passing std::container without template

Thanks for the response, looks like I have to template.
15. ## c++, passing std::container without template

Hi Guys,   Quick question.   Is it possible to pass a std::container say std::vector, or std::list in a function paramater such as   void foo(some std::container p){  for(auto it=p.begin();it!=p.end();it++){  //do something with container }   }   without having to use templates, ie   template <class container> void foo(container &c){  for(auto it=c.begin();it!=c.end();it++){  //do something with container  } }   Thanks,   Mike