Thread: Get all values from a struct

  1. #1
    Registered User
    Join Date
    Jul 2005
    Posts
    33

    Get all values from a struct

    I made a function in a cpp file that needs to get a float value that is declared and defined in different cpp files and is inside a struct.

    It's a directX program I'm making, and I can get the LPDIRECT3DRMFRAME value just fine, but it doesn't know what the other float values are that are inside that same struct. It says one of them is -1.0737418e+008 when I declared it as 1.1. How do I tell my program where to find the value of this number?

    The struct is

    frFrame.frFrame
    .Weight (It can't tell what this is)
    .Bounce (It can't tell what this is)

  2. #2
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    A debugger can show all the values in all your variables, including structs. I would first find out what types .Weight and stuff are, and then you can deal with them.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  3. #3
    Registered User
    Join Date
    Jul 2005
    Posts
    33
    i know what types they are, floating points.

  4. #4
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    >and I can get the LPDIRECT3DRMFRAME value just fine,
    How are you getting this value? Something like:
    Code:
    cout << frFrame.frFrame
    Probably not since it's directX.

    Also have you tried changing the value of frFrame, just to be sure you are getting what you think?

  5. #5
    Registered User
    Join Date
    Jul 2005
    Posts
    33
    Heres my function

    Code:
    void Phy_Weight(LPDIRECT3DRMFRAME frScene, LPDIRECT3DRMFRAME Camera){
    LPDIRECT3DRMFRAMEARRAY SceneArray;
    FrameStruct frFrame;
    D3DVECTOR vectPos;
    D3DVECTOR vectVel;
    
    int ArraySize;
    
    frScene->GetChildren(&SceneArray);
    ArraySize = SceneArray->GetSize();
    
    	for (int i = 0;i < ArraySize; i++){
    	SceneArray->GetElement(i, &(frFrame.frFrame));
    	frFrame.frFrame->GetVelocity(frScene, &vectVel, false);
    	if (frFrame.frFrame != Camera){
    	frFrame.frFrame->SetVelocity(frScene, vectVel.x, vectVel.y * frFrame.Weight, vectVel.z, false);
    	}
    	}
    }
    Ill break it down for you in case you don't know DX coding.

    First I tell the user defined scene frame (frScene) to get all the frames inside it and put them into an array of frames.

    Next I make the integer ArraySize become the size of the array of frames

    With that info I can start a for loop. Inside the for loop I tell the array to get all of its frames and put them into frFrame.frFrame. This is where it finds out what .frFrame is. But I have no clue how to tell it where to find .Weight and .Bounce.

  6. #6
    vae victus! skorman00's Avatar
    Join Date
    Nov 2003
    Posts
    594
    I don't see that frFrame struct being initialized anywhere. I suspect it's being done here:
    Code:
    SceneArray->GetElement(i, &(frFrame.frFrame));
    but you're sending the frFrame member of frFrame, so anything else in the top level frFrame is probably still chode...unless you know the byte offsets of all the members and do some pointer math, but that's bad to do anyway.

  7. #7
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    > frFrame.frFrame->SetVelocity(frScene, vectVel.x, vectVel.y * frFrame.Weight, vectVel.z, false);

    Here you use frFrame.Weight. Is this the value that's showing as -1.0737418e+008 instead of 1.1?

  8. #8
    Registered User
    Join Date
    Jul 2005
    Posts
    33
    Quote Originally Posted by swoopy
    > frFrame.frFrame->SetVelocity(frScene, vectVel.x, vectVel.y * frFrame.Weight, vectVel.z, false);

    Here you use frFrame.Weight. Is this the value that's showing as -1.0737418e+008 instead of 1.1?
    Correct, I just want to be able to access that variable, everything else works fine.

  9. #9
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    >Correct, I just want to be able to access that variable, everything else works fine.

    >FrameStruct frFrame;
    You declare frFrame here, so in order for Weight to have the value 1.1, you would have to either initialize it in the constructor, or call a setWeight member function. For example to initialize it in the constructor:
    Code:
    FrameStruct::FrameStruct(): Weight(1.1)
    {
    }
    Unless GetElement() sets it, which I doubt.
    Last edited by swoopy; 08-03-2005 at 07:47 PM.

  10. #10
    Registered User
    Join Date
    Jul 2005
    Posts
    33
    Quote Originally Posted by swoopy
    >Correct, I just want to be able to access that variable, everything else works fine.

    >FrameStruct frFrame;
    You declare frFrame here, so in order for Weight to have the value 1.1, you would have to either initialize it in the constructor, or call a setWeight member function. For example to initialize it in the constructor:
    Code:
    FrameStruct::FrameStruct(): Weight(1.1)
    {
    }
    Unless GetElement() sets it, which I doubt.

    It looks there like you're setting the weight to 1.1, I dont want that. See I will have many frame structs, with many different weights, so I want it to find the weight variable that I declared in a different cpp. Also, the weight is subject to change at later times.

  11. #11
    Registered User
    Join Date
    Jul 2005
    Posts
    33
    bump

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. memory issue
    By t014y in forum C Programming
    Replies: 2
    Last Post: 02-21-2009, 12:37 AM
  2. Link List math
    By t014y in forum C Programming
    Replies: 17
    Last Post: 02-20-2009, 06:55 PM
  3. Looking for constructive criticism
    By wd_kendrick in forum C Programming
    Replies: 16
    Last Post: 05-28-2008, 09:42 AM
  4. Concatenating in linked list
    By drater in forum C Programming
    Replies: 12
    Last Post: 05-02-2008, 11:10 PM
  5. problem with structures and linked list
    By Gkitty in forum C Programming
    Replies: 6
    Last Post: 12-12-2002, 06:40 PM