So I have this code that I think feeds the shader with those 2 matrices:
// Set uniforms
int projectionMatrixLocation = GL.GetUniformLocation( shaderProgramHandle, "projection_matrix" );
int modelviewMatrixLocation = GL.GetUniformLocation( shaderProgramHandle, "modelview_matrix" );
GL.UniformMatrix4( projectionMatrixLocation, false, ref projectionMatrix );
GL.UniformMatrix4( modelviewMatrixLocation, false, ref modelviewMatrix );
And I have this code that I think should rotate the matrix but nothing happens.
projectionMatrix *= Matrix4.CreateTranslation( -(float)CameraPosition.X, 0, -(float)CameraPosition.Y );
projectionMatrix *= Matrix4.Rotate( new Vector3( 0, 1, 0 ), (float)MouseOffsetX / 5F );
projectionMatrix *= Matrix4.Rotate( new Vector3( (float)xaxis.X, 0, (float)xaxis.Y ), (float)MouseOffsetY / 5F );
projectionMatrix *= Matrix4.CreateTranslation( (float)CameraPosition.X, 0, (float)CameraPosition.Y );
What did I do wrong?
Did you set the matrices to the identity matrix first?
This?
GL.MatrixMode( MatrixMode.Projection );
GL.LoadMatrix( ref projectionMatrix );
Do I need GL.LoadIdentity()?
How do I use it and why is it so hard to find information about that stuff?
GL.MatrixMode, GL.LoadMatrix and GL.LoadIdentity are part of the fixed function-pipeline, they won't help.
Should be projectionMatrix = Matrix4.Identity;.
Hmm sounds alright.
You are creating the matrix and applying the transformations before GL.UniformMatrix4( ... );?
No, I call the uniformmatrix4 on load and the transformations OnUpdate.
It's been a little while, but I think that GL.UniformMatrix4( ... ) uploads the data, as such call that after transforming the matrix.
It's doing all kinds of crazy shit now. When I move the mouse if flies all over the place, movement seems to work fine but the near and far planes are clipping with the cube.
I don't understand this stuff at all...
Is the direct mouse input too sensitive perhaps? Multiplying by a small value, say 0.2 or something, might help if that's what you mean.
I don't know how to explain this. It's like there's no cube, just one side of it and it's glued to a sphere (you can see the sphere), when I move the mouse that sphere rotates. (very fast, on all axis)
Hahaha, I sound like I'm mentally ill.
Possibly a screenshot would help to make it understandable.
Anyways, you were modifying the projection matrix. I don't know if this has any effect, for 3D stuff I really havn't gone far beyond beginner programs, but try to modify the modelview matrix instead.
Idea: Maybe your mouse coordinates are in screen space?
As I said, the movement AND rotation worked when I did GL.MatrixMode(projection) and then rotated and moved it with GL.Rotate and GL.Translate
I'll make a short video:
[URL="http://www.swfcabin.com/open/1277411226"]http://www.swfcabin.com/open/1277411226[/URL]
Everything is mouse moved, only the last few horizontal movements are with the keyboard.
You're probably multiplying in the wrong order, remember that matrix concatenation is not commutative. Try restricting your test case. Try it with just translation, or just scale, or just rotation. Then once you have that working you have something to build from.
Ok, I couldn't figure it out for too long so I got an OpenTK example to see how they did shaders and rotation.
It turns out they rotate the model view matrix but since I don't actually know what the difference is I just swapped the projection matrix with the model view in my rotation code. Not it sort of works but not the way it should. It rotates on some weird axis, the movement it totally wrong, for example, when I strafe next to the cube it works fine but somehow the strafe slowly becomes forward motion. That's the best I know how to describe this.
I'll fiddle around with it some more.
I'm really starting to wonder how people figure this stuff out. The coverage on this topics is horrible. Is it the same for DX or is it just OGL?
Get a game maths book, the concepts are the same across DirectX and OpenGL with some slight implementation differences.
I really need some snippets.
So I know how to make a FPS camera without shaders, I also know how to use shaders and then rotate the mode view matrix.
I don't know how to use shaders and make a FPS style camera. Any example I could find either involves only shaders or only camera movement.
The problem is you don't understand what the matrices are doing. Exactly the same maths is being performed in both cases. Your previous comment about projection and model view matrices tells me that you really should brush up on your 3D matrix maths.
There's plenty of stuff on the internet but I can't really point you to anything specific because I got a book '3D Maths for Graphics and Game Programming'.
There's nothing to brush up on. I never did anything with matrices so I'm sort of jumping in head first.
Then he's saying you should get a book or learn about matrix math
Ok, I think I have figured out what the problem is. (at least a part of it)
Apparently GL.Rotate does more than just multiplying the current selected matrix with a rotation matrix because it also rotates the near/far clipping planes and the field of view.
Any ideas what it could be? I mean, when I move the cube by multiplying the matrix with the translation it does move but it looks like the field of view is the same as if I'm standing at the original position.
Oh, and I'll start reading about matrices after this. I just want to get it work.
It's my first time using BASS and i'm not sure how i can do this, i'm using it to play an mp3 file and i need to know the file total time and the elapsed time, how can i do this?
[QUOTE=Fox-Face;22892066]It's my first time using BASS and i'm not sure how i can do this, i'm using it to play an mp3 file and i need to know the file total time and the elapsed time, how can i do this?[/QUOTE]
You can go look in the help files you downloaded for all the functions. For example, to get the elapsed time, you'd use Bass.BASS_ChannelGetPosition(stream) where stream is your stream, which returns the position in bytes. To convert that into seconds, you'd use (int)Bass.BASS_ChannelBytes2Seconds(stream, Bass.BASS_ChannelGetPosition(stream)), again where stream is your stream.
[QUOTE=jmazouri;22892421]You can go look in the help files you downloaded for all the functions. For example, to get the elapsed time, you'd use Bass.BASS_ChannelGetPosition(stream) where stream is your stream, which returns the position in bytes. To convert that into seconds, you'd use (int)Bass.BASS_ChannelBytes2Seconds(stream, Bass.BASS_ChannelGetPosition(stream)), again where stream is your stream.[/QUOTE]
Wow, i feel stupid. Thanks alot.
I've got this vertex shader:
[code]varying vec3 normal;
varying vec3 vertex_to_light_vector;
void main()
{
// Transforming The Vertex
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
// Transforming The Normal To ModelView-Space
normal = gl_NormalMatrix * gl_Normal;
// Transforming The Vertex Position To ModelView-Space
vec4 vertex_in_modelview_space = gl_ModelViewMatrx * gl_Vertex;
// Calculating The Vector From The Vertex Position To The Light Position
vec3 test=vec3(gl_LightSource[0].position);
vec3 test2=vec3(vertex_in_modelview_space);
vertex_to_light_vector = test – test2;
}[/code]
It throws these errors:
0(22) : error C0000: syntax error, unexpected $undefined at token "<undefined>"
0(22) : error C0501: type name expected at token "<undefined>"
0(22) : warning C7022: unrecognized profile specifier "test"
What's wrong?
Actually, forget about the last 2, what does the first one mean?
Well, since your shader only has 20 lines and the error is at line 22, you either didn't post the original code, your shader compiler is wrong (props not if other apps work) or you've got the compiling code wrong.
I also thing that you should put a #version <version-here> at top of that file.
Funny thing, there was #version 100 up there which means that 22. line is vertex_to_light_vector = test – test2;
I just didn't copy it because I wrote that my self. The original shader didn't have it.
I'm getting a really strange error when trying to compile some code in MSVC++, I'll post the error here, and link the code [url=http://pastebin.com/0bDFrnZ6]here[/url], [url=http://pastebin.com/ccn3cz9c]and here[/url].
The error is
[cpp]1>bitmap.obj : error LNK2019: unresolved external symbol "bool const __cdecl Bitmap::GetGLTexture(class Bitmap::File const &,unsigned int &)" (?GetGLTexture@Bitmap@@YA?B_NABVFile@1@AAI@Z) referenced in function "bool const __cdecl Bitmap::GetGLTexture(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,unsigned int &)" (?GetGLTexture@Bitmap@@YA?B_NABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@AAI@Z)
1>main.obj : error LNK2001: unresolved external symbol "bool const __cdecl Bitmap::GetGLTexture(class Bitmap::File const &,unsigned int &)" (?GetGLTexture@Bitmap@@YA?B_NABVFile@1@AAI@Z)[/cpp]
:science: NOOBISH C++ :science:
[code]//Ch6AppE06.cpp
//Displays the number of daily calories
//needed to maintain your current weight
//Created/revised by YEAHNOFP on 6/25/10
#include <iostream>
#include <string>
using namespace std;
int main()
{
//Declare variables
string gender = "";
string activityLevel = "";
double weight = 0.0;
double caloriesNeeded = 0.0;
const int maleModCal = 15;
const int maleRelCal = 13;
const int femModCal = 12;
const int femRelCal = 10;
//Get user input
cout << "Enter gender, (M or F): ";
cin >> gender;
cout << "Is the activity level moderate or relative, (M or R)? ";
cin >> activityLevel;
cout << "Enter weight: ";
cin >> weight;
//Convert gender to uppercase
if (gender = "f") || (gender = "F")
{
transform(gender.begin(), gender.end(), gender.begin(), toupper());
} //End if
if (gender = "m") || (gender = "M");
{
toupper(gender) == "M";
} //End if
//Convert activity level to uppercase
if (activityLevel = "m") || (activityLevel = "M")
{
toupper(activityLevel) == "M";
}
if (activityLevel = "i") || (activityLevel = "I")
{
toupper(activityLevel) == "I";
}
//If user is male
if (toupper(gender) == "M")
{
if (activityLevel = "M")
{
(caloriesNeeded = weight * maleModCal);
}
if (activityLevel = "I")
{
(caloriesNeeded = weight * maleRelCal);
}
}
//If user is female
if (toupper(gender) == 'F')
{
if (activityLevel = "M")
{
(caloriesNeeded = weight * femModCal);
}
if (activityLevel = "I")
{
(caloriesNeeded = weight * femRelCal);
}
}
//Print calories needed
cout << "The number of calories needed to maintain current weight is: " << caloriesNeeded << endl;
system("pause");
return 0;
} //end of main function
[/code]
[b]THIS[/b]
Ok, it's a program that's supposed to get the users gender, weight and activity level. And then multiply by a constant value of calories pertaining to the persons activity level.
Activity level is marked by
[code]A = Moderately active
I = Relatively inactive[/code]
And the gender is obvious.
[b]BUT ANYWAYS[/b]
Whenever I compile above source code, I get a bunch of errors.
What does this mean?
[code]32 C:\Users\SilentJubJub\Desktop\Ch6AppE06(2).cpp could not convert `(&gender)->std::basic_string<_CharT, _Traits, _Alloc>::operator= [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>](((const char*)"f"))' to `bool' [/code]
:confused:
We just started this chapter in class and I think I did a bajillion things wrong. If you guys see anything else, could you let me know?
Sorry, you need to Log In to post a reply to this thread.