Search Home Members Contacts
About Us
Products
Downloads
Community
Support
Pages: [1]
  Print  
Author Topic: Need help with moving 3D models in the Truevision loop...  (Read 1315 times)
Magnum357jhp
Community Member
*
Posts: 84


« on: December 08, 2007, 10:01:54 PM »

ok, first of all, I would like to pose the code I got about this question here (so people can understand my problem) but its somewhat complicated and I don't think one blog of code will really explain the situation.  So I will try to "paraphrase" my problem here and see if anyone can come up with a solution because I'm really stumped on what to do.

I'm working on a project that involves Truevision Models in a 3D environment.  There is not much Animation or models moving around, basically .3ds Models in a Truevision Picture box much like how many of the Tutorial examples in Truevision work.  What I want to do with this project is to move a particular 3D model in .3ds format to a specific position in the 3D environment of Truevision.  I understand how to get the model to the new position, I could simply create a Command buttom to initiate a command to move the model to another part of the 3D evironment.  But the problem I'm having is that I have whole other form that is linked to the project that controls things and when I close that Form to get to the main form, I would like to move the 3D model right after I click the close button of this other form and move the 3D model to the new position.  Unfortunetly, I just can not get the model to move to the new position.  I use the following code line to move certain things to new positions by using the "Main Game Loop" and placing this code in that loop...

sngLineOfScrimagePosition = -20.95 * IntFeildpos

The varible "sngLineOfScirmagePosition" is located in the Main Game Loop so the program knows to update the new position, but for some reason, the new information is not being received in the variable with this other Form in the project.  And since it is not updating, the "Main Game Loop" in the project is not receiving the new data of the Variable to update the new position.  I know the variable is not being updated because I have a simple Label linked to the "sngLineOfScrimagePosition" that is on the Projects Main Form (not the Form initiating the command) that tells me the Variable is not changing. 

Am I not understanding how Forms work?  Wouldn't a simple "Click" Procedure from another form be able to update a variable in the "Main Game Loop" of another form?  I hope people can understand what I'm talking about because I'm all out of ideas.
Logged

"There is no such thing as the ultimate programming language.  Every language has its weaknesses."
Raine
Customers
Community Member
*****
Posts: 1190


« Reply #1 on: December 09, 2007, 03:21:05 AM »

For starters you could insert some Debug.Write lines here and there.
Are you sure you aren't re-initializing the value to its default in the loop, so that the change is invalidated?

Since the change of the value is linked to an input event, put a breakpoint in the OnClick event handler in the other form and let the execution stop when you click the button. Then step inside the code (run line by line) and see what happens.
Logged

ZaPPZion
Community Member
*
Posts: 341


« Reply #2 on: December 09, 2007, 03:48:48 AM »

check the availability of the variable. Maybe you made the variable private or even a local variable of a function/sub/method etc.
Logged
Raine
Customers
Community Member
*****
Posts: 1190


« Reply #3 on: December 09, 2007, 05:29:28 AM »

check the availability of the variable. Maybe you made the variable private or even a local variable of a function/sub/method etc.

that would turn out in a compile error
Logged

ZaPPZion
Community Member
*
Posts: 341


« Reply #4 on: December 09, 2007, 06:06:08 AM »

if you're using vb6, you wont even need to declare variables sometimes, so it could be possible Wink (chances are small i know)
Logged
Raine
Customers
Community Member
*****
Posts: 1190


« Reply #5 on: December 09, 2007, 06:29:34 AM »

so implicitly typed variables are globally scoped?
Logged

ZaPPZion
Community Member
*
Posts: 341


« Reply #6 on: December 09, 2007, 06:37:01 AM »

the scope of not defined variables is private i think, so you cant access them in other modules/forms whatever;)
generally VB6 is pretty messy with the scopes of variables. I learned programming in vb6, but i had to learn a lot about programming tidy:)
Logged
Magnum357jhp
Community Member
*
Posts: 84


« Reply #7 on: December 10, 2007, 03:45:44 AM »


Are you sure you aren't re-initializing the value to its default in the loop, so that the change is invalidated?

Since the change of the value is linked to an input event, put a breakpoint in the OnClick event handler in the other form and let the execution stop when you click the button. Then step inside the code (run line by line) and see what happens.


Ill check to see if the value is "re-initializing" but I don't think so.  The Varible is not changing at all.  Oh, and the above variable is set at "Global" inside a VB6 Module so I don't think the scope is quite the issue here (at least I don't think it is).

I'm not sure what a "Breakpoint" is.  Is that that Red Dot thing in VB6 to stop the excution at a particular spot in the program?  What good will that do anyways?  Where in the other Forms ClickEvent Buttom command would I put this breakpoint?  Maybe I should post the Programs Main Loop and the Buttons Click event here and see what people think could be done.
Logged

"There is no such thing as the ultimate programming language.  Every language has its weaknesses."
Magnum357jhp
Community Member
*
Posts: 84


« Reply #8 on: December 10, 2007, 03:59:37 AM »

Ok, the following is two code blogs that have the problem.  The first is the other Form's Buttons ClickEvent procedure, and is suppose to set certain perameters up and move a particular model to a certain position.

Code:
Private Sub cmdKickPlay_Click()
    byteOFFPlaySelect = 6
    byteOFFFormation = 12
    Unload OFFSelection
    GameForm.cmdOFFCall.Enabled = False
    GameForm.cmdDEFCall.Enabled = True

        'Following code used to setup 3/4pt Feildgoals in Truevision
        If byte3or4ptFeildGoalInitiatior = True Then
            If intTeam = 1 And intFeildpos > 60 And byte3or4ptFeildGoalIndicator = 1 Then
                intTogo = intTogo + (intFeildpos - 60)
                intFeildpos = 60
                intBallon = (100 - intFeildpos)
                GameForm.lblOffDef.Caption = "DEF"
                GameForm.lblSpot.Caption = intBallon
                GameForm.picPossession.Picture = LoadPicture(App.Path + "..\Misc Art\HomePOS.bmp")
                sngLineOfScrimagePosition = (-20.95 * intFeildpos)
                GameForm.lblToGo.Caption = intTogo
            End If
   
            If intTeam = 2 And intFeildpos < 40 And byte3or4ptFeildGoalIndicator = 1 Then
                intTogo = intTogo + (40 - intFeildpos)
                intFeildpos = 40
                intBallon = intFeildpos
                GameForm.lblOffDef.Caption = "DEF"
                GameForm.lblSpot.Caption = intBallon
                GameForm.picPossession.Picture = LoadPicture(App.Path + "..\Misc Art\GuestPOS.bmp")
                sngLineOfScrimagePosition = (-20.95 * intFeildpos)
                GameForm.lblToGo.Caption = intTogo
            End If
            byte3or4ptFeildGoalInitiatior = False
        End If
       
End Sub

The important part of this code (at least I think it is) is the "sngLineOfScrimagePositioin" varible where it gets its new data (sngLineOfScrimagePosition = (20.95 * intfeildpos).  When the user clicks the command button on the other form, I want the new data to be sent to this Varible then the Varible is read in the program Main Loop.  The following code is the Main Loop code...

Code:
Private Sub Main_loop()
   
    Do
        DoEvents
       
        If PanControlUp = True Then
            sngPositionY = sngPositionY + (TV8.TimeElapsed / 5)
            camera.SetPosition sngPositionX, sngPositionY, sngPositionZ
        End If
       
        If PanControlDown = True Then
            sngPositionY = sngPositionY - (TV8.TimeElapsed / 5)
            camera.SetPosition sngPositionX, sngPositionY, sngPositionZ
        End If
       
        If ZoomControlIn = True Then
            sngPositionZ = sngPositionZ - (TV8.TimeElapsed / 2)
            camera.SetPosition sngPositionX, sngPositionY, sngPositionZ
        End If
       
        If ZoomControlOut = True Then
            sngPositionZ = sngPositionZ + (TV8.TimeElapsed / 2)
            camera.SetPosition sngPositionX, sngPositionY, sngPositionZ
        End If
       
        If PanControlLeft = True Then
            sngPositionX = sngPositionX + (TV8.TimeElapsed / 2)
            camera.SetPosition sngPositionX, sngPositionY, sngPositionZ
        End If
       
        If PanControlRight = True Then
            sngPositionX = sngPositionX - (TV8.TimeElapsed / 2)
            camera.SetPosition sngPositionX, sngPositionY, sngPositionZ
        End If
       
        ChainScrimage(1).SetPosition 605, 25, sngLineOfScrimagePosition
        ChainScrimage(2).SetPosition -607, 25, sngLineOfScrimagePosition
        LineOfScrimage.SetPosition 0, 0, sngLineOfScrimagePosition
       
       
        TV8.Clear
       
        scene.RenderAllMeshes
       
        '---------
       
        TV8.RenderToScreen
        Label10.Caption = sngLineOfScrimagePosition
       
    Loop Until DoLoop = False
       
    Main_quit
       
End Sub

As you can see with the following line (LineOfScrimage.SetPosition 0, 0, sngLineOfScrimagePosition) the new data should change the Varible to the new setting then the program Main Loop would adjust the position of the model to the new position.  This would easily work with just a simple Command Button on the same form as the Truevision Program, but for some reason the new data is most likely not being updated to the new varible by clicking the Command Bottom on the other form.  I know this because the line of code (Label10.Caption = sngLineOfScrimagePosition) is linked to a label on the Main Form that shows the varible is not updating. 
Logged

"There is no such thing as the ultimate programming language.  Every language has its weaknesses."
Raine
Customers
Community Member
*****
Posts: 1190


« Reply #9 on: December 10, 2007, 05:00:03 AM »

I don't really remember VB6 as I used that a long time ago...

however are you sure the variable isn't global for only the module is included in?

In the main loop: sngLineOfScrimagePosition = (-20.95 * intFeildpos)

Why don't you just make it a Main Form variable, so that you can access it like this:

(Public SngLineofScrImagePosition As Single)

MainForm.SngLineOfScrimagePosition

And set Option Explicit on if you haven't.

What about using VB.NET? Tongue

Edit: yes, the red point should be a breakpoint?
« Last Edit: December 10, 2007, 05:01:37 AM by RaineC » Logged

ZaPPZion
Community Member
*
Posts: 341


« Reply #10 on: December 10, 2007, 06:32:27 AM »

yea the red dot is a breakpoint. It's very very usefull, because the program will break (pause) at that line of code. Then you can hover your mouse over the variables to see their states, that way you can probably see what's going on:)
Logged
kwazai
Community Member
*
Posts: 168


« Reply #11 on: December 10, 2007, 08:12:17 AM »

take the variable out of the "if then" constructs and see if it changes on the main form then. it could be that the "if then" conditions are not being satisfied. just my .02$
mike
Logged

murphys law-28th corollary- if there are five ways for something to go wrong and you circumvent all five , a sixth will promptly develop.
Magnum357jhp
Community Member
*
Posts: 84


« Reply #12 on: December 10, 2007, 06:30:26 PM »

Ok, I first did what ZaPPZion suggested with the breakpoint feature and move my cursor over the variable as it stoped at that variables code (sngLineOfScrimagePosition)  The program indicates for some reason that the Varible is = 0.  I also did what kwazai suggested and move the "sngLineOfScrimagePosition = (-20.95 * intFeildpos)" line outside of the If/Then statement, just below the whole blog of code in the Command buttons Click event.  I Breakpointed this aswell and too indicated = 0.  I also tested this with the program and it still did not move the model to the new position (LineOfScrimage.SetPosition 0, 0, sngLineOfScrimagePosition)  I'm really stumped on this.  I don't see any reason why the varible is = 0.  The label10.caption indicates otherwise.

P.S.  I do have a copy of VB.net, but I prefer VB6.  There are a lot of differences between the two languages (even some of the syntax) and VB6 is not quite such a resource hog.
Logged

"There is no such thing as the ultimate programming language.  Every language has its weaknesses."
Magnum357jhp
Community Member
*
Posts: 84


« Reply #13 on: December 11, 2007, 12:05:01 AM »

Aha!  Success.  I think I figured out an alternative that might help me acheive what I want to do.  After careful studying of people comments above, I decided to try to take the entire If/Then code from the other Forms Click Event and directly place it inside the Programs Main Loop.  I had tried this before I beleive, but with little success, but for some reason its actually making the 3D model move the to the proper position now.   Smiley  Not sure why it didn't work before because I did experiment with this idea, but it seems to be working a lot better that way then trying to use another Forms Click Event. 

Anyway, if all goes well, thank you guys for the input.   Smiley
Logged

"There is no such thing as the ultimate programming language.  Every language has its weaknesses."
Pages: [1]
  Print  
 
Jump to:  

Powered by SMF 1.1.3 | SMF © 2006-2007, Simple Machines LLC
Seo4Smf v0.2 © Webmaster's Talks