Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


Math Gurus I summon you

This topic is 5573 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Here''s my problem I have a quad built through the use of the following vertices
jcd_math.tuple3f back[] = { new jcd_math.tuple3f( -x, -y, -z),
                                new jcd_math.tuple3f(  x, -y, -z),
                                new jcd_math.tuple3f( -x,  y, -z),
                                new jcd_math.tuple3f(  x,  y, -z)}; 
Having (0,0,1) for normal and 0,0,1,0,0,1,1,1 for textures coordinates. Now how do I figure out the space tangent to such polygon? This is very crucial to my per pixel lighting demo and I would appreciate any help .

Share this post

Link to post
Share on other sites
Figured out, not without having thought about suicide several times

public static class plane{

jcd_math.matrix4f tangent_matrix[];

float vertices[][] = new float[4][5],
normal[] = new float[3],

int texture_dot3,
counter_clock[] = {0,1,2,

plane(jcd_math.tuple3f[] points,jcd_math.tuple3f vector,
float w, float h, int texture_base,int texture_dot3){

this.texture_dot3 = texture_dot3;
this.texture_base = texture_base;
normal[0] = vector.x;
normal[1] = vector.y;
normal[2] = vector.z;
texture_w = w;
texture_h = h;

float texture_s_t[] = { 0, 0,
texture_w, 0,

for(int i =0, a = 0; i<4; i++, a+=2){

vertices[i][0] = points[i].x;
vertices[i][1] = points[i].y;
vertices[i][2] = points[i].z;
vertices[i][3] = texture_s_t[ a];
vertices[i][4] = texture_s_t[a+1];

/* */
/* http://tfpsly.planet-d.net/english/3d/pplight_bump.html */

/* */

void create_tagent_matrices(){

tangent_matrix = new jcd_math.matrix4f[4];
for(int i = 0; i<tangent_matrix.length; i++)
tangent_matrix[i] = new jcd_math.matrix4f();

for(int i = 0, index =0; i<2; i++, index+=3){

jcd_math.tuple3f v_1 = new jcd_math.tuple3f(),
v_2 = new jcd_math.tuple3f(),
crs = new jcd_math.tuple3f();

for(int xyz =0, row =0; xyz<3; xyz++, row+=4){

vertices[counter_clock[index+1]][ 3]-vertices[counter_clock[index+0]][ 3],
vertices[counter_clock[index+1]][ 4]-vertices[counter_clock[index+0]][ 4]);

vertices[counter_clock[index+2]][ 3]-vertices[counter_clock[index+0]][ 3],
vertices[counter_clock[index+2]][ 4]-vertices[counter_clock[index+0]][ 4]);

tangent_matrix[counter_clock[index+0]].elements[0+row]+= -crs.y/crs.x;
tangent_matrix[counter_clock[index+0]].elements[1+row]+= -crs.z/crs.x;
tangent_matrix[counter_clock[index+1]].elements[0+row]+= -crs.y/crs.x;
tangent_matrix[counter_clock[index+1]].elements[1+row]+= -crs.z/crs.x;
tangent_matrix[counter_clock[index+2]].elements[0+row]+= -crs.y/crs.x;
tangent_matrix[counter_clock[index+2]].elements[1+row]+= -crs.z/crs.x;

for(int i = 0; i<4; i++){
jcd_math.tuple3f tangent = new jcd_math.tuple3f( tangent_matrix[i].elements[0],
binormal = new jcd_math.tuple3f(-tangent_matrix[i].elements[1], // if this vector was a person,

-tangent_matrix[i].elements[5], // I would have shot the [censored]

-tangent_matrix[i].elements[9]),// a longtime ago >:D

new_normal = new jcd_math.tuple3f();
if(new_normal.Dot(new jcd_math.tuple3f(normal[0],normal[1],normal[2]))< 0)

tangent_matrix[i] = new jcd_math.matrix4f(tangent,binormal,new_normal,false);

^ a Quad

[edited by - JavaCoolDude on August 16, 2003 4:19:57 PM]

Share this post

Link to post
Share on other sites
Original post by JavaCoolDude
Figured out, not without having thought about suicide several times

Glad we could be of help. But out of curiosity, what did you mean by "space tangent to the polygon"?

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!