metalman666

Members
  • Content count

    82
  • Joined

  • Last visited

Community Reputation

156 Neutral

About metalman666

  • Rank
    Member
  1. C++: General question pointers

    Thanks a lot. All of you. Much appreciated. I now see what was happening. I can sleep now.
  2. C++: General question pointers

    @_fastcall Well this line of code beats me. *(var+1) = 5; This correctly assigned y to 5. Any explanation. I tried the code with inheritance and it did crashed, but the new output is now Dumb::x : 5 Dumb::y : -842150451 not as you wrote Dumb::x : -842150451 Dumb::y : -842150451 Again Why? This really spins my head.
  3. Hello guys, I know the code below is bad, but i need to know why is this even working. Please read the code. #include <iostream> class Dumb { int x; int y; public: const int getX(){ return x; } const int getY(){ return y; } }; int main(void) { Dumb* pDumb = new Dumb(); int* var = (int*)pDumb; (*var) = 10; std::cout << "\nDumb::x : " << pDumb->getX(); std::cout << "\nDumb::y : " << pDumb->getY(); delete pDumb; return 0; } Output:: Dumb::x : 10 Dumb::y : 0 Question: 1. Why line {int* var = (int*)pDumb;} is working? 2. Why line {pDumb->getX();} shows the output as 10? 3. Why line {pDumb->getY();} shows the output as 0? 4. How can a integer pointer assign value to a private variable? My environment: Visual Studio Team Edition 2008, Windows XP Thanks for any explanation.
  4. [C++] Template vector argument

    Quote:Original post by johnstanp A code that compiles: *** Source Snippet Removed *** Actually, what you want to achieve is impossible...You cannot store a string instance in a vector of floats. Your code will only compile for a container of string, that has a member function template< typename T, template< typename > class allocator > void Container< T, allocator< T > >::push_back( T const & ). Hence, *** Source Snippet Removed *** I understand that, actually that implementation was for the strings vector version and i forgot to change it in the template version. Thanks a lot to both of you for your suggestions. [smile]
  5. Hi! everyone, I have 3 functions that reads some data from a string and stores it in a vector list. The 3 functions are for storing in a string vector, int vector and a float vector. I want to make these 3 functions as a general templatised version, but was unable to do it. I am getting compile errors. Can anyone suggest a way to do this? These are the 3 functions. void ReadStringData( const string &readstring, std::vector<string> &_list ); void ReadFloatData( string &readstring, std::vector<float> &_list); void ReadIntData( str &readstring, std::vector<uint32_t> &_list); I have created a generic template function but can't seem to make it work. template<typename T1,typename T2> void ReadData(const T1& data, T2& list) { int32_t lastPos = 0; for (size_t i=0; i<data.length(); ++i) { int32_t pos = data.find(delimiter_colon, 0, lastPos); if (0 == data.length()) { break; } if (1 != pos) { string temp = data.substr(lastPos, pos-lastPos); list.push_back(temp); lastPos = pos+1; } } } How do i call this function with proper arguments? Any inputs will be very helpful. Cheers! Happy holidays.
  6. Degree question

    Since you are from India, i think i should tell you this. I am currently in India for a project. I have mostly met peoples who are engineers, but are working in IT companies as programmers. That's rather odd, i guess. Incidently i met a guy, who said he has done a course in Game dev from a school in chennai and said they are teaching crap. He said, he wasted his money going their and "google" helped him a lot more then that school. I also asked him about Game schools in india and he said none of them are good. That may be his view but that got me thinking. So, i thought to share this with you. Their are plenty of good schools in US though and people hailing from US will give you more ideas. And it's also not true that game studios look for a degree. What they look for is what you know. Without even formal education some people can make it big. The point is, it all boils down to you in getting you a job. You should also search these forums, because these topics creeps up very often. Good luck.
  7. Strange shader behaviour[XNA]

    Thanks a lot! MJP. You're the man. Works wonderfully.[smile]
  8. Hi, I am trying to render a model with a custom shader, but the model is drawn without the texture. The model and texture file are both in the same folder. The strange part is that, i can see the model with texture on opening it in DirectX viewer. Shader code: ///custom shader// /// FFX.fx /// float4x4 fx_WVP : WORLDVIEWPROJECTION; uniform extern Texture fx_texture; sampler TextureSampler = sampler_state { Texture = <fx_texture>; mipfilter = LINEAR; magfilter = LINEAR; //when image bigger then actual size minfilter = LINEAR; //when image smaller then actual size }; struct VS_INPUT { float4 position : POSITION0; float4 color : COLOR0; float2 texture_coord : TEXCOORD0; }; struct VS_OUTPUT { float4 position : POSITION0; float4 color : COLOR0; float2 texture_coord : TEXCOORD0; }; struct PS_OUTPUT { float4 color : COLOR0; }; void vertex_shader(in VS_INPUT IN, out VS_OUTPUT OUT) { float4 pos = IN.position; OUT.position = mul(pos, fx_WVP); OUT.color = IN.color; OUT.texture_coord = IN.texture_coord; } void pixel_shader(in VS_OUTPUT IN, out PS_OUTPUT OUT) { OUT.color = tex2D(TextureSampler, IN.texture_coord); //optional, to add a tint //OUT.color *= IN.color; } technique SIMPLE_2_0 { pass p0 { sampler[0] = (TextureSampler); vertexshader = compile vs_2_0 vertex_shader(); pixelshader = compile ps_2_0 pixel_shader(); } } My model initialize method private void InitializeModels() { model = Content.Load<Model>("cf18"); mat_model = new Matrix[model.Bones.Count]; model.CopyAbsoluteBoneTransformsTo(mat_model); foreach (ModelMesh mesh in model.Meshes) foreach (ModelMeshPart mesh_part in mesh.MeshParts) mesh_part.Effect = effect; } I can't find any error,but you may see what i can't. So, this is driving me nuts. Any input is greatly appreciated. Thanks.
  9. I suppose you already know what's a vector. The process of scaling vectors to unit vectors is known as normalization. The vector length is scaled to 1. Actually unit vectors is a set of numbers, which has been expressed in the same ratio as the original vector but the components are scaled to a fraction that ranges between -1 & +1. You will get the normalized vector by dividing the X, Y and Z coord of a vector by the total vector length. For e.g. unit_vector.X = vector.X / vector_length same for Y & Z. The vector length is calculated by pythagorean theorem. Look it up it's really easy. for e.g. Math.sqrt(vector.X * vector.X + vector.Y * vector.Y + vector.Z * vector.Z) As of your other questions click here, will clear some of your doubts. If not ask back. Good luck[smile]
  10. Smooth movement of a charecter

    You may use a variable time_lapse where you will store the elapsed time something like. public void SetFrameInterval() { time_lapse = ElapsedGameTime.Milliseconds; } Then you may update your camera position view. Something like. public void UpdateCameraPosView(Vector3 cam, float speed) { speed *= (float)time_lapse; cam *= speed; v_pos.X += cam.X; v_pos.Z += cam.Z; v_view.X += cam.X; v_view.Z += cam.Z; } You have to update the look vector and pass it accordingly to UpdateCameraPosView function. Eg. for movement along X axis public void Strafe(float cam_speed) { Vector3 v_look = Vector3.Zero; Vector3 v_unit_look = Vector3.Zero; const float SPEEDSCALE = 0.005f; cam_speed *= SPEEDSCALE; v_look.Y = v_view.Y; v_look.X = v_view.X - v_pos.X; v_look.Z = v_view.Z - v_pos.Z; v_unit_look = Vector3.Normalize(v_look); Vector3 v_strafe = Vector3.Cross(v_unit_look, v_up); UpdateCameraPosView(v_strafe, cam_speed); } Hope this helps a bit.[smile]
  11. Trouble using custom .fx on .x model

    Guess i was not clear in my question.[ so, no reply] I will rephrase it. I am using DebugView and it says me this D3D9 Helper: Enhanced D3DDebugging disabled; Application was not compiled with D3D_DEBUG_INFO. I generally use #define D3D_DEBUG_INFO in D3D applications, but i have no idea as how to use that in XNA applications. Any ideas? Anyone? Also please take a look at my previous post. Thank you!
  12. Trouble using custom .fx on .x model

    Well, i figured out this problem. But not sure weather it is the right way to do. I turned off the "maximum validation" from DX control panel, so it works now. Can anyone explain why is it so? One more question, can i use #define D3D_DEBUG_INFO in XNA? Thanks!
  13. Hi, I am getting 'System.InvalidOperationException' in mesh.Draw() line foreach (ModelMesh mesh in model.Meshes) { mat_world = mat_model[mesh.ParentBone.Index] * mat_world; foreach (Effect current_effect in mesh.Effects) { current_effect.CurrentTechnique = current_effect.Techniques["SIMPLE_2_0"]; current_effect.Parameters["fx_WVP"].SetValue( mat_world * mat_view * mat_proj); current_effect.CommitChanges(); } Console.WriteLine("model_mesh" +mesh.GetType()); mesh.Draw(); // this is throwing error } I am initializing the models as private void InitializeModels() { model = Content.Load<Model>("jet"); mat_model = new Matrix[model.Bones.Count]; model.CopyAbsoluteBoneTransformsTo(mat_model); foreach (ModelMesh mesh in model.Meshes) foreach (ModelMeshPart mesh_part in mesh.MeshParts) mesh_part.Effect = ffx_effect; } Is this correct? Please point as to where i am doing wrong. Thank you for any help. [Edited by - metalman666 on October 14, 2008 11:23:15 PM]
  14. [%]mod operator returns the remainder you can do something like this. For example if you have a no. say 123, then 123 % 10, steps: 1. 123%10 -> you get 3 now quotient 12, 2. 12%10 -> you get 2 now quotient 1 3. 1%10 -> you get 1 Then you can get each digits of the number. Cheers!
  15. Unity random guitar riff generator

    You can try GuitarPro. I use it for editing riffs that i come up with. It helps a lot in improvising the feel of the riff. Worth a try. NOTE: its a tablature editor. Cheers!