Jump to content
  • Advertisement
Sign in to follow this  
giugio

draw mesh at 0,0,-1000 opengl / webgl

This topic is 2536 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

hello.
I have this test webgl vertex shader:


<script id="TextureEffectv" type="x-shader/x-vertex">
attribute vec3 aVertexPosition;
attribute vec3 aVertexNormal;
attribute vec2 aTextureCoord;

uniform mat4 uMVMatrix;
uniform mat4 uPMatrix;
uniform mat3 uNMatrix;

uniform vec3 uAmbientColor;
uniform vec3 uLightingDirection;
uniform vec3 uLightingDirection2;
uniform vec3 CameraModelPosition;

uniform vec3 ColorFront;
uniform vec3 ColorBack;
varying vec3 transformedNormal;
varying vec3 vLightWeighting;
varying vec3 vLightWeightingback;
varying vec2 vTextureCoord;
void main(void) {
gl_Position = uPMatrix * uMVMatrix * vec4(aVertexPosition, 1.0);

vTextureCoord = aTextureCoord;
vec3 uDirectionalColor = vec3(1,1,1);
transformedNormal = uNMatrix * aVertexNormal;

float directionalLightWeighting = max(dot(transformedNormal, uLightingDirection), 0.0) ;
vLightWeighting = uDirectionalColor * directionalLightWeighting * ColorFront ;

float directionalLightWeighting2 = max(dot(transformedNormal, uLightingDirection2), 0.0) ;
vLightWeighting += uDirectionalColor * directionalLightWeighting2 * ColorFront ;

float directionalLightWeightingback = max(dot(transformedNormal, uLightingDirection), 0.0) ;
vLightWeightingback = uDirectionalColor * directionalLightWeightingback * ColorBack ;

float directionalLightWeighting2back = max(dot(transformedNormal, uLightingDirection2), 0.0) ;
vLightWeightingback += uDirectionalColor * directionalLightWeighting2back * ColorBack ;
}
</script>



Now i would draw a mesh at 0,0,-1000 without the gllookat or glorto.
I have only the uMVMatrix for do this, is sufficent?
how i can change the word view matrix for draw the mesh at 0,0,-1000?
I know that the camera position is the inverse of the word view matrix?
but... i 'm not understand at all
thanks.

Share this post


Link to post
Share on other sites
Advertisement

hello.
I have this test webgl vertex shader:


<script id="TextureEffectv" type="x-shader/x-vertex">
attribute vec3 aVertexPosition;
attribute vec3 aVertexNormal;
attribute vec2 aTextureCoord;

uniform mat4 uMVMatrix;
uniform mat4 uPMatrix;
uniform mat3 uNMatrix;

uniform vec3 uAmbientColor;
uniform vec3 uLightingDirection;
uniform vec3 uLightingDirection2;
uniform vec3 CameraModelPosition;

uniform vec3 ColorFront;
uniform vec3 ColorBack;
varying vec3 transformedNormal;
varying vec3 vLightWeighting;
varying vec3 vLightWeightingback;
varying vec2 vTextureCoord;
void main(void) {
gl_Position = uPMatrix * uMVMatrix * vec4(aVertexPosition, 1.0);

vTextureCoord = aTextureCoord;
vec3 uDirectionalColor = vec3(1,1,1);
transformedNormal = uNMatrix * aVertexNormal;

float directionalLightWeighting = max(dot(transformedNormal, uLightingDirection), 0.0) ;
vLightWeighting = uDirectionalColor * directionalLightWeighting * ColorFront ;

float directionalLightWeighting2 = max(dot(transformedNormal, uLightingDirection2), 0.0) ;
vLightWeighting += uDirectionalColor * directionalLightWeighting2 * ColorFront ;

float directionalLightWeightingback = max(dot(transformedNormal, uLightingDirection), 0.0) ;
vLightWeightingback = uDirectionalColor * directionalLightWeightingback * ColorBack ;

float directionalLightWeighting2back = max(dot(transformedNormal, uLightingDirection2), 0.0) ;
vLightWeightingback += uDirectionalColor * directionalLightWeighting2back * ColorBack ;
}
</script>



Now i would draw a mesh at 0,0,-1000 without the gllookat or glorto.
I have only the uMVMatrix for do this, is sufficent?
how i can change the word view matrix for draw the mesh at 0,0,-1000?
I know that the camera position is the inverse of the word view matrix?
but... i 'm not understand at all
thanks.

I'm expalin better:

void Camera::updateViewMatrix()
{
// Reconstruct the view matrix.

m_viewMatrix = m_orientation.toMatrix4();

m_xAxis.set(m_viewMatrix[0][0], m_viewMatrix[1][0], m_viewMatrix[2][0]);
m_yAxis.set(m_viewMatrix[0][1], m_viewMatrix[1][1], m_viewMatrix[2][1]);
m_zAxis.set(m_viewMatrix[0][2], m_viewMatrix[1][2], m_viewMatrix[2][2]);
m_viewDir = -m_zAxis;

if (m_behavior == CAMERA_BEHAVIOR_ORBIT)
{
// Calculate the new camera position based on the current
// orientation. The camera must always maintain the same
// distance from the target. Use the current offset vector
// to determine the correct distance from the target.

m_eye = m_target + m_zAxis * m_orbitOffsetDistance;
}

m_viewMatrix[3][0] = -Vector3::dot(m_xAxis, m_eye);
m_viewMatrix[3][1] = -Vector3::dot(m_yAxis, m_eye);
m_viewMatrix[3][2] = -Vector3::dot(m_zAxis, m_eye);
}

i choose the m_behavior == CAMERA_BEHAVIOR_ORBIT use of the camera.
the orientation is the orientation of the camera in quaternion m_orientation.toMatrix4(); .
the camera have a CRender class reference and, this.m_render.UpdateFromCamera(this); calls the CRender class
get the matrixes from the camera(the CRender class have also a reference to camera object)then draw the mesh in the scene with those matrixes.

The problem is this:
I use a shader for drawing the mesh and create an orbit camera system.
the model is always at 0;0;0 or other arbitrary positions, the thing that change is the camera (orientation and position) i can set the orientation and position in the MVMatrix , but if i place those how i can draw the mesh at 0;0;0 ??
How i can draw the mesh at 0;0;0 and apply the Model view matrix that return my camera object and have the eye position and camera orientation?
thanks.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!