Jump to content

  • Log In with Google      Sign In   
  • Create Account


wildboar

Member Since 29 Dec 2009
Offline Last Active Mar 24 2013 06:09 PM

Topics I've Started

Field of view check

23 March 2013 - 12:48 PM

I have a small function:

 

 

 

bool CanSee(UnitInstance * Me, Vector3& Him)
{
   Vector3 NN1 = Me->Pos - Him;
   Vector3 NN2 = Me->PrevVel;

   NN1.normalize();
   NN2.normalize();

   return(Vector3::dot(NN1, NN2) < 0.0f);
}

This gives me too wide of a field of view check, this is between enemy and player used for stealth system.

How can I make it a lesser FOV?


Barycentric UV Help

03 January 2013 - 07:08 AM

I have a function like this from recast, its a function that tests if a triangle gets intersected by a ray:

 

 

 

static bool intersectSegmentTriangle(const float* sp, const float* sq,
const float* a, const float* b, const float* c,
float &t)
{
float v, w;
float ab[3], ac[3], qp[3], ap[3], norm[3], e[3];
rcVsub(ab, b, a);
rcVsub(ac, c, a);
rcVsub(qp, sp, sq);


// Compute triangle normal. Can be precalculated or cached if
// intersecting multiple segments against the same triangle
rcVcross(norm, ab, ac);


// Compute denominator d. If d <= 0, segment is parallel to or points
// away from triangle, so exit early
float d = rcVdot(qp, norm);
if (d <= 0.0f) return false;


// Compute intersection t value of pq with plane of triangle. A ray
// intersects iff 0 <= t. Segment intersects iff 0 <= t <= 1. Delay
// dividing by d until intersection has been found to pierce triangle
rcVsub(ap, sp, a);
t = rcVdot(ap, norm);
if (t < 0.0f) return false;
if (t > d) return false; // For segment; exclude this code line for a ray test


// Compute barycentric coordinate components and test if within bounds
rcVcross(e, qp, ap);
v = rcVdot(ac, e);
if (v < 0.0f || v > d) return false;
w = -rcVdot(ab, e);
if (w < 0.0f || v + w > d) return false;


// Segment/ray intersects triangle. Perform delayed division
t /= d;


return true;
}

 

The trouble I am having is that I now have attached some uv coords to the vertices, how can I find out the interpolated uv coord from 3 uv coords of those 3 vertices that go into the function. I need to do something with that t value to get the point in the triangle where the ray hits and then use that to calculate my desired uv coord to output. What I want to achieve is to be able to raycast a triangle and get a uv coord at the point where the ray intersects.
 
Thanks in advance.

Turret System

17 December 2012 - 05:22 PM

I am trying to make a simple turret system without using skeletal animation.

I have 2 meshes, turret base and the turret itself. I am trying to attach a particle emitter to the ends of the turret where the cube is like this:
http://imgur.com/tbely

I just rotate the turret mesh around the y axis and it looks like its aiming for something, but I tried to rotate the cube around the turret using the same rotation matrix and it never aligns properly :(

Is there some different way I should be doing this? do I really need to use bones and animation files for this? there must be a simpler way of handling this.

Blob Shadow

20 November 2012 - 05:15 AM

I am trying to implement a simple blob shadow for a low spec game. I need to implement it in the most efficient way possible since there is no much ms left to spare per frame to rendering.

1) Is it possible to somehow get fragments position in the shader and when rendering the ground get xyz position of player and make the shader draw a black circle shape?

2) Raycasting the ground from player feet downwards 2000.0f units and drawing a quad at that position. Should I raycast the entire mesh every frame like this or skip frames or what? Is this a good method to do it?

3) Any other easy method to do it?

4x4 to 3x3+vec3 matrix conversion world/view/proj

07 November 2012 - 12:21 PM

I heard that an OpenGL projection matrix needs all 4x4 cells to store the values. An API I am using has 3x3 + vec3 representation of the projection matrix. I am just wondering how I am able to convert my 4x4 matrix to the API's format and back. This API is fully closed source so I have no idea what is going on in the background. I managed to convert the world matrix correctly but having no luck with the view/proj matrices as they produce incorrect visual results.

This is what I have so far:


CIwFMat ConvertToMarmaladeFormat(Matrix4& Mat)

{

	CIwFMat M;

	M.m[0][0] = Mat[0][0];

	M.m[0][1] = Mat[0][1];

	M.m[0][2] = Mat[0][2];

	M.m[1][0] = Mat[1][0];

	M.m[1][1] = Mat[1][1];

	M.m[1][2] = Mat[1][2];

	M.m[2][0] = Mat[2][0];

	M.m[2][1] = Mat[2][1];

	M.m[2][2] = Mat[2][2];

	M.t = CIwFVec3(Mat[3][0], Mat[3][1], Mat[3][2]);

	return M;

}



Matrix4 ConvertFromMarmaladeFormat(CIwFMat& M)

{

	Matrix4 Mat;

	Mat.identity();

	Mat[0][0] = M.m[0][0];

	Mat[0][1] = M.m[0][1];

	Mat[0][2] = M.m[0][2];

	Mat[1][0] = M.m[1][0];

	Mat[1][1] = M.m[1][1];

	Mat[1][2] = M.m[1][2];

	Mat[2][0] = M.m[2][0];

	Mat[2][1] = M.m[2][1];

	Mat[2][2] = M.m[2][2];

	Mat[3][0] = M.t.x;

	Mat[3][1] = M.t.y;

	Mat[3][2] = M.t.z;

	return Mat;

}



class Matrix4

{

	friend Vector4 operator*(const Vector4 &lhs, const Matrix4 &rhs);

	friend Vector3 operator*(const Vector3 &lhs, const Matrix4 &rhs);

	friend Matrix4 operator*(float scalar, const Matrix4 &rhs);

public:

	static const Matrix4 IDENTITY;

	static Matrix4 createFromAxes(const Vector3 &x, const Vector3 &y, const Vector3 &z);

	static Matrix4 createFromAxesTransposed(const Vector3 &x, const Vector3 &y, const Vector3 &z);

	static Matrix4 createFromHeadPitchRoll(float headDegrees, float pitchDegrees, float rollDegrees);

	static Matrix4 createMirror(const Vector3 &planeNormal, const Vector3 &pointOnPlane);

	static Matrix4 createOrient(const Vector3 &from, const Vector3 &to);

	static Matrix4 createRotate(const Vector3 &axis, float degrees);

	static Matrix4 createScale(float sx, float sy, float sz);

	static Matrix4 createTranslate(float tx, float ty, float tz);

	Matrix4() {}

	Matrix4(float m11, float m12, float m13, float m14,

			float m21, float m22, float m23, float m24,

			float m31, float m32, float m33, float m34,

			float m41, float m42, float m43, float m44);

	~Matrix4() {}

	float *operator[](int row);

	const float *operator[](int row) const;

	bool operator==(const Matrix4 &rhs) const;

	bool operator!=(const Matrix4 &rhs) const;

	Matrix4 &operator+=(const Matrix4 &rhs);

	Matrix4 &operator-=(const Matrix4 &rhs);

	Matrix4 &operator*=(const Matrix4 &rhs);

	Matrix4 &operator*=(float scalar);

	Matrix4 &operator/=(float scalar);

	Matrix4 operator+(const Matrix4 &rhs) const;

	Matrix4 operator-(const Matrix4 &rhs) const;

	Matrix4 operator*(const Matrix4 &rhs) const;

	Matrix4 operator*(float scalar) const;

	Matrix4 operator/(float scalar) const;

	float determinant() const;

	void fromAxes(const Vector3 &x, const Vector3 &y, const Vector3 &z);

	void fromAxesTransposed(const Vector3 &x, const Vector3 &y, const Vector3 &z);

	void fromHeadPitchRoll(float headDegrees, float pitchDegrees, float rollDegrees);

	void identity();

	Matrix4 inverse() const;

	void orient(const Vector3 &from, const Vector3 &to);

	void rotate(const Vector3 &axis, float degrees);

	void scale(float sx, float sy, float sz);

	void toAxes(Vector3 &x, Vector3 &y, Vector3 &z) const;

	void toAxesTransposed(Vector3 &x, Vector3 &y, Vector3 &z) const;

	void toHeadPitchRoll(float &headDegrees, float &pitchDegrees, float &rollDegrees) const;

	void translate(float tx, float ty, float tz);

	Matrix4 transpose() const;

private:

	float mtx[4][4];

};



class CIwFMat

{

public:

/**

* 3x3 rotation matrix.

*/

	float   m[3][3];

/**

* Trans vector.

*/

	CIwFVec3	t;

...

};


PARTNERS