Texture Change

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,724
Reaction score
2,689
Points
203
Location
Dallas, TX
This worked in Crimson Editor. But I transfered to VS2005 for UMMU. Compiled with no errors. all works but my texture change.
I have a texture change from green to red and back depending on conditions.
But I get no textures to show up for the specific item. All other textures show up.
Code:
#define STRICT
#define ORBITER_MODULE
#define ENG                 1    
#include "LSPOD.h"
#include "orbitersdk.h"
#include "OrbiterSoundSDK3.h"


MESHHANDLE POD = oapiLoadMeshGlobal ("LSPOD");
SURFHANDLE red_tex= oapiLoadTexture ("LSPOD/LSPOD_RED.dds");
SURFHANDLE green_tex= oapiLoadTexture ("LSPOD/LSPOD_GREEN.dds ");
SURFHANDLE red1_tex= oapiLoadTexture ("LSPOD/LSPOD_RED1.dds");
SURFHANDLE green1_tex= oapiLoadTexture ("LSPOD/LSPOD_GREEN1.dds ");
VISHANDLE MainExternalMeshVisual = 0;
Code:
if (level10==1) PCL=1;
if (level10==0) PCL=0;

if (level11==1) PCL1=1;
if (level11==0) PCL1=0;

if (level8==1)     PCL2=1;
if (level8==0) PCL2=0;    

if (level9==1)     PCL3=1;
if (level9==0) PCL3=0;        


    
    TextureChange();
Here are where the conditions are found:
Code:
void LSPOD::TextureChange()
{

if ((MainExternalMeshVisual != 0) & ((PCL==1)|(PCL1==1)))
oapiSetTexture (MainExternalMeshVisual,11,red1_tex );
if ((MainExternalMeshVisual != 0) & ((PCL==0)& (PCL1==0)))
oapiSetTexture(MainExternalMeshVisual,11,green1_tex );


if ((MainExternalMeshVisual != 0) & ((PCL2==1)|(PCL3==1)))
oapiSetTexture (MainExternalMeshVisual,12,red_tex );
if ((MainExternalMeshVisual != 0) & ((PCL2==0)& (PCL3==0)))
oapiSetTexture(MainExternalMeshVisual,12,green_tex );




}
Code:
H file:
void clbkPostStep (double simtt, double simdt, double mjd);
    void clbkFocusChanged(bool getfocus,OBJHANDLE hNewVessel,OBJHANDLE hOldVessel);
    void TextureChange();
 

Urwumpe

Not funny anymore
Addon Developer
Donator
Joined
Feb 6, 2008
Messages
37,623
Reaction score
2,341
Points
203
Location
Wolfsburg
Preferred Pronouns
Sire
What about the following suggestion: Make your code clearer for yourself. Don't write code you can't understand yourself (I say this quite often in my university as many people know how to write complex code by just repeating stupid patterns, but later can't say what their code does)

You have for example the condition "MainExternalMeshVisual != NULL" in all your if statements in TextureChange. Why don't you optimize the code and make it simpler to read, if you move this condition into a new if statement at the beginning of the function.

You have two ways to do so: Spaghetti code and structured code. Spaghetti code is not less well structured as so called structured code, but requires more understanding of the program flow.

Spaghetti code solution in Pseudo code:
Code:
void LSPOD::TextureChange()
{
If(mainexternalmeshvisual == NULL)
return;

...
}

This version just aborts the whole function if MainExternalMeshVisual does not exist.

The structured code version would look like that:
Code:
void LSPOD::TextureChange()
{
if(MainExternalMeshVisual != NULL)
{
...
}
}

Next: Why the hell don't you just write
Code:
PCL = level10;
PCL1 = level11; 
PCL2 = level8;
PCL3 = level9;

Thats what you are doing - its a complete waste of innocent bytes.


I think, it is a fair judgment, if I say, that it is not you defining what the program does, but the program is defining what you are doing. You don't control it.
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,724
Reaction score
2,689
Points
203
Location
Dallas, TX
Thanks. What this is to do:
I have 2 joystick meshes with a button on top that starts green. These joystick reflect RCS movement. One controls Rotation and the other Linear.
here is where it figures out forward back or yaw left/right if thrust is applied to either TT up/DOWN or TAWLEft/Right the button turns red


Code:
level0 = GetThrusterGroupLevel (THGROUP_ATT_UP);
level1 = GetThrusterGroupLevel (THGROUP_ATT_DOWN);
level2 = GetThrusterGroupLevel (THGROUP_ATT_LEFT);
level3 = GetThrusterGroupLevel (THGROUP_ATT_RIGHT);

level4 = GetThrusterGroupLevel (THGROUP_ATT_PITCHUP);
level5 = GetThrusterGroupLevel (THGROUP_ATT_PITCHDOWN);
level6 = GetThrusterGroupLevel (THGROUP_ATT_BANKLEFT);
level7 = GetThrusterGroupLevel (THGROUP_ATT_BANKRIGHT);

level8 = GetThrusterGroupLevel (THGROUP_ATT_YAWLEFT);
level9 = GetThrusterGroupLevel (THGROUP_ATT_YAWRIGHT);
level10 = GetThrusterGroupLevel (THGROUP_ATT_FORWARD);
level11 = GetThrusterGroupLevel (THGROUP_ATT_BACK);

{SetAnimation( anim_control1a, level3);}
{SetAnimation( anim_control1, level2);}
{SetAnimation( anim_control1b, level1);}
{SetAnimation( anim_control1c, level0);}

{SetAnimation( anim_control1d, level11);}
{SetAnimation( anim_control1e, level10);}

{SetAnimation( anim_control2a, level7);}
{SetAnimation( anim_control2, level6);}
{SetAnimation( anim_control2b, level5);}
{SetAnimation( anim_control2c, level4);}

{SetAnimation( anim_control2d, level8);}
{SetAnimation( anim_control2e, level9);}

if (level10==1) PCL=1; // ATT_FORWARD
if (level10==0) PCL=0;

if (level11==1) PCL1=1;// ATT_BACK
if (level11==0) PCL1=0;

if (level8==1)     PCL2=1;//YAW_right
if (level8==0) PCL2=0;    

if (level9==1)     PCL3=1;//YAW_left
if (level9==0) PCL3=0;        


    
    TextureChange();
So if you use ATT forward or BAck (PCL1)the button turns red on one joystick if not the button is green
So if you use YAw_Left/right (PCL2)the button turns red on one joystick f not the button is green

Code:
void LSPOD::TextureChange()
{

if ((MainExternalMeshVisual != NULL) & ((PCL==1)|(PCL1==1)))
oapiSetTexture (MainExternalMeshVisual,11,red1_tex ); // turn button1 red
if ((MainExternalMeshVisual != NULL) & ((PCL==0)& (PCL1==0)))
oapiSetTexture(MainExternalMeshVisual,11,green1_tex );// turn button1 green


if ((MainExternalMeshVisual != NULL) & ((PCL2==1)|(PCL3==1)))
oapiSetTexture (MainExternalMeshVisual,12,red_tex );// turn button2 red
if ((MainExternalMeshVisual != NULL) & ((PCL2==0)& (PCL3==0)))
oapiSetTexture(MainExternalMeshVisual,12,green_tex );// turn button2 green

}
 

Urwumpe

Not funny anymore
Addon Developer
Donator
Joined
Feb 6, 2008
Messages
37,623
Reaction score
2,341
Points
203
Location
Wolfsburg
Preferred Pronouns
Sire
Uuuuuuuugh?! Eeeeeeeek!

Why don't you use "clbkRCSMode" for that?

Also, I see that you use "&" instead of "&&". Do you know what "&" does?
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,724
Reaction score
2,689
Points
203
Location
Dallas, TX
Didn't know about it. Looked at it in the SDK doc and it looks like it tells if the rcs is rotaional and linear.

clbkRCSMode
Called when a vessel’s RCS (reaction control system) mode changes. Usually the RCS
consists of a set of small thrusters arranged so as to allow controlled attitude changes.
In Orbiter, the RCS can be driven in either rotational mode (to change the vessel’s
angular velocity) or in linear mode (to change its linear velocity), or be switched off.
Synopsis:
void clbkRCSMode (int mode)
Parameters:
mode new RCS mode: 0=disabled, 1=rotational, 2=linear
 

Urwumpe

Not funny anymore
Addon Developer
Donator
Joined
Feb 6, 2008
Messages
37,623
Reaction score
2,341
Points
203
Location
Wolfsburg
Preferred Pronouns
Sire
Yes. Exactly.

And do you now also know what the difference is between "&" and "&&" ? Or "|" and "||"? You use only "&" and "|", so maybe you know what you are doing...
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,724
Reaction score
2,689
Points
203
Location
Dallas, TX
yes, && compares 2 expression if acts like AND
|| acts like OR

corrected by code

I have this:
Code:
if ((MainExternalMeshVisual != NULL) & ((PCL==1)||(PCL1==1)))
oapiSetTexture (MainExternalMeshVisual,11,red1_tex );
if ((MainExternalMeshVisual != NULL) & ((PCL==0)&& (PCL1==0)))
oapiSetTexture(MainExternalMeshVisual,11,green1_tex );

so if either PCL ==1 (ATT_Up has thrust) or PCL1 (Att_Down has thrust) changes the button to red
if PCL and PCL! have no thrust then the button is green
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,724
Reaction score
2,689
Points
203
Location
Dallas, TX
This is what it should look like: I have the texture change turn off for this

when I have texture change on the green button are white
f_08050108392m_450c814.jpg
 

tblaxland

O-F Administrator
Administrator
Addon Developer
Webmaster
Joined
Jan 1, 2008
Messages
7,320
Reaction score
25
Points
113
Location
Sydney, Australia
I tread here lightly but...

Don't you want those buttons to show whether you are in OFF/ROT/LIN? Why not do:
Code:
clbkRCSMode (int mode)
{
     if (MainExternalMeshVisual != NULL) {
          switch (mode) {
               case 1: // Rotational mode
                     oapiSetTexture(MainExternalMeshVisual,11,green1_tex); // turn button1 green
                     oapiSetTexture(MainExternalMeshVisual,12,red_tex); // turn button2 red
                     break;

               case 2: // Linear mode
                     oapiSetTexture(MainExternalMeshVisual,11,red1_tex); // turn button1 red
                     oapiSetTexture(MainExternalMeshVisual,12,green_tex); // turn button2 green
                     break;

               default:
                     oapiSetTexture(MainExternalMeshVisual,11,green1_tex); // turn button1 green
                     oapiSetTexture(MainExternalMeshVisual,12,green_tex); // turn button2 green
                     break;

          } // switch (mode)

     } // if (MainExternalMeshVisual != NULL)
             
} // clbkRCSMode (int mode)
I believe that is what Urwumpe was trying to suggest.

EDIT: breaks added.
 

Urwumpe

Not funny anymore
Addon Developer
Donator
Joined
Feb 6, 2008
Messages
37,623
Reaction score
2,341
Points
203
Location
Wolfsburg
Preferred Pronouns
Sire
yes, && compares 2 expression if acts like AND
|| acts like OR

And what is the difference between "&" and "&&"?

If it wouldn't be important, I wouldn't ask. :dry:
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,724
Reaction score
2,689
Points
203
Location
Dallas, TX
& = and
&& = if both expressions are and they it is true

The color of the button changes only when ATT_UP or Att_Down is applied on the Lin stick One sticj controls Lin and the other rot
 

Urwumpe

Not funny anymore
Addon Developer
Donator
Joined
Feb 6, 2008
Messages
37,623
Reaction score
2,341
Points
203
Location
Wolfsburg
Preferred Pronouns
Sire
OK, in more logical words:

& = bit-wise "and" operator. The result is the AND of all bits of the operands.
&& = logical/boolean "and" operator. The result is true, if both operand are true.

If you use "&" and it works like "&&", you have been lucky to have had a implementation of the C++ language, which makes booleans one-bit datatypes. But you can't rely on that.
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,724
Reaction score
2,689
Points
203
Location
Dallas, TX
Ok, Thanks, redid the code:
Code:
void LSPOD::TextureChange()
{
if (MainExternalMeshVisual != NULL) {
    if  ((PCL==1)||(PCL1==1)) //ATT_UP/DOwn thrust applied turn button red 
        {oapiSetTexture (MainExternalMeshVisual,11,red1_tex );}
    if  ((PCL==0)&& (PCL1==0))// no ATT_UP/DOwn thrust applied turn button green
        {oapiSetTexture(MainExternalMeshVisual,11,green1_tex );}
    if  ((PCL2==1)||(PCL3==1)){
        oapiSetTexture (MainExternalMeshVisual,12,red_tex );}
    if ((PCL2==0)&& (PCL3==0)){
        oapiSetTexture(MainExternalMeshVisual,12,green_tex );}
}
}
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,724
Reaction score
2,689
Points
203
Location
Dallas, TX
Okay this is what the code looks like
Code:
void LSPOD::TextureChange()

{
    if (MainExternalMeshVisual = 0){
        if((PCL==1)||(PCL1==1)){
            oapiSetTexture (MainExternalMeshVisual,11,red1_tex );}
        if ((PCL==0)&&(PCL1==0)){
            oapiSetTexture(MainExternalMeshVisual,11,green1_tex );}
        if ((PCL2==1)||(PCL3==1)){
            oapiSetTexture (MainExternalMeshVisual,12,red_tex );}
        if ((PCL2==0)&& (PCL3==0)){
            oapiSetTexture(MainExternalMeshVisual,12,green_tex );}
}
}

I get the green button but no red even though PCL =1. if I have if (MainExternalMeshVisual!=NULL){

I get no green buttons
 

tblaxland

O-F Administrator
Administrator
Addon Developer
Webmaster
Joined
Jan 1, 2008
Messages
7,320
Reaction score
25
Points
113
Location
Sydney, Australia
Code:
    if (MainExternalMeshVisual = 0){
        ...
    }
You are setting MainExternalMeshVisual to zero (= means assign, == means comparison). I don't know how you are getting the green buttons, because you are passing oapiSetTexture an invalid mesh handle.

(MainExternalMeshVisual != NULL) would be the correct usage.

I notice you have MainExternalMeshVisual defined as a VISHANDLE whereas oapiSetTexture expects a MESHHANDLE so you probably don't have a valid handle for the mesh to start with.
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,724
Reaction score
2,689
Points
203
Location
Dallas, TX
Thanks I deleted the VISHANDLE MainExternalMeshVisual = 0;
and made the other changes. if (MainExternalMeshVisual != NULL)
but now I get MainExternalMeshVisual' : undeclared identifier
 

Urwumpe

Not funny anymore
Addon Developer
Donator
Joined
Feb 6, 2008
Messages
37,623
Reaction score
2,341
Points
203
Location
Wolfsburg
Preferred Pronouns
Sire
Please. Learn some basic C++ first. Only the basics. It can't be too hard to notice that he meant "MainExternalMeshVisual = 0" in the if statement and that it is bad to delete the declaration of VISHANDLE MainExternalMeshVisual.

Of course it does not work that way. If you would thought first about WHAT you are about to do, you would have noticed yourself, that it can't work and is very likely not meant that way.

Also, he meant that you need a handle to a mesh (MESHHANDLE) for oapiSetTexture. You can get this meshhandle by oapiGetMesh or by storing the meshhandle in clbkSetClassCaps.

We can teach you C++, but we can't teach you thinking for yourself.
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,724
Reaction score
2,689
Points
203
Location
Dallas, TX
Thanks,
Okay I looked at SDK and using MESHHANDLE POD = oapiLoadMeshGlobal ("LSPOD");

Code:
void LSPOD::TextureChange()
{

    if  ((PCL==1)||(PCL1==1))// thrust applied turn red
        {oapiSetTexture (POD,11,red1_tex );}
    if  ((PCL==0)&& (PCL1==0))// no thrust turn back green
        {oapiSetTexture(POD,11,green1_tex );}
    if  ((PCL2==1)||(PCL3==1))//
        {oapiSetTexture (POD,12,red_tex );}
    if ((PCL2==0)&& (PCL3==0))
        {oapiSetTexture(POD,12,green_tex );}
}


I did a //sprintf(oapiDebugString(),"PCL%2.2f PCL1%2.2f ",PCL,PCL1);
and determined that PCL =1 when thrust is applied.

All I get is green button, no red
 

Urwumpe

Not funny anymore
Addon Developer
Donator
Joined
Feb 6, 2008
Messages
37,623
Reaction score
2,341
Points
203
Location
Wolfsburg
Preferred Pronouns
Sire
Why don't you use the else statement for green anyway? It can only be red or green.
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,724
Reaction score
2,689
Points
203
Location
Dallas, TX
Interesting, so like this:
This gives me no green or red lights

Code:
void LSPOD::TextureChange()
{

    if  ((PCL==1)||(PCL1==1))//thrust applied turn red
        {oapiSetTexture (POD,11,red1_tex );}
    else  
        {oapiSetTexture(POD,11,green1_tex );}
    if  ((PCL2==1)||(PCL3==1))
        {oapiSetTexture (POD,12,red_tex );}
    else
        {oapiSetTexture(POD,12,green_tex );}
}

I redid the code to this simple piece.
Code:
void LSPOD::TextureChange()
{
    if  (PCL==1)//thrust applied
        {oapiSetTexture (POD,11,red1_tex );}
}

And no red button just green buttons.
 
Last edited:
Top