HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

CameraMap object/struct

08-10-2008, 10:14 PM#1
MaD[Lion]
this is a struct as part of my camera system for generating camera map, for absolute camera movement, sadly blizzard is too gay, i cant get the values exact... i dont know wat i have done wrong, everything seems right.
The concept is moving camera to each vertex on the terrain and get the Z for tat, and then calculate the Z value in between those using some geometry math. The system would first move the camera to a vertex position, example (0,0). Then it will wait 0.01 to ensure the camera is updated then it will GetCameraTargetPositionZ() and store them to gamecache with X as missionkey and Y as key.
But things just doesnt work out well... Maybe someone can try to debug it and find something i havent seen...

methods:
-CameraMap.Generate() - This will generate the camera map, takes some time
-CameraMap.GetZ(x,y) - this will get the camera map Z at a coordinate after the map has been generated, else it will just give 0.

Collapse JASS:
//---------------------------------------//
// CAMERA MAPPING
//---------------------------------------//

struct CameraMap
    private static integer X
    private static integer Y
    private static gamecache gc
    private static integer MaxX
    private static integer MaxY
    private static integer MinX
    private static integer MinY
    private static integer dx
    private static integer dy
    private static timer Tmr
    private static boolean Checking
    private static integer Vertices
    private static integer TotalVertices
    
    private static method onInit takes nothing returns nothing
        set CameraMap.MaxX = R2I(GetCameraBoundMaxX())
        set CameraMap.MaxY = R2I(GetCameraBoundMaxY())
        set CameraMap.MinX = R2I(GetCameraBoundMinX())
        set CameraMap.MinY = R2I(GetCameraBoundMinY())
        set CameraMap.gc = InitGameCache("cm.w3v")
        set CameraMap.TotalVertices = R2I(1+(CameraMap.MaxX-CameraMap.MinX)/128)*R2I(1+(CameraMap.MaxY-CameraMap.MinY)/128)
    endmethod

    private static method Scan takes nothing returns nothing
        if (CameraMap.Checking) then
            call StoreReal(CameraMap.gc,I2S(CameraMap.X),I2S(CameraMap.Y),GetCameraTargetPositionZ())
            set CameraMap.Vertices = CameraMap.Vertices+1
            //Stats
            call ClearTextMessages()
            call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,0.3,"MaDCam is generating camera map:")
            call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,0.3,"-Vertex: ("+I2S(CameraMap.X)+","+I2S(CameraMap.Y)+")")
            call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,0.3,"-Vertices: "+I2S(CameraMap.Vertices)+"/"+I2S(CameraMap.TotalVertices))
            call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,0.3,"-ETA: "+R2S(I2R(CameraMap.TotalVertices)*0.02-(CameraMap.Vertices)*0.02)+"s")
            call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,0.3,"-Progress: |cffffcc00"+SubString("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!",0,1+80*CameraMap.Vertices/CameraMap.TotalVertices)+"|r - "+I2S(R2I(100*CameraMap.Vertices/CameraMap.TotalVertices))+"%")
            //--
            set CameraMap.X = CameraMap.X+(128*CameraMap.dx)
            //Scanning sectors
            if ((CameraMap.X>CameraMap.MaxX) or (CameraMap.X<CameraMap.MinX)) then
                if (CameraMap.dx==-1) then
                    set CameraMap.X = -128
                else
                    set CameraMap.X = 0
                endif
                set CameraMap.Y = CameraMap.Y+(128*CameraMap.dy)
            endif
            //Switching sectors
            if ((CameraMap.Y>CameraMap.MaxY) or (CameraMap.Y<CameraMap.MinY)) then
                set CameraMap.dx = CameraMap.dx*CameraMap.dy
                set CameraMap.dy = CameraMap.dy*-1
                if (CameraMap.dx==-1) then
                    set CameraMap.X = -128
                else
                    set CameraMap.X = 0
                endif
                if (CameraMap.dy==-1) then
                    set CameraMap.Y = -128
                else
                    set CameraMap.Y = 0
                endif
                if ((CameraMap.dx==1) and (CameraMap.dy==1)) then
                    call DestroyTimer(CameraMap.Tmr)
                    set CameraMap.Tmr = null
                    call ShowInterface(true, 1)
                    call CinematicFadeBJ( bj_CINEFADETYPE_FADEIN, 1.00, "ReplaceableTextures\\CameraMasks\\White_mask.blp", 0, 0, 0, 0 )
                endif
            endif
            set CameraMap.Checking=false
        else
            call SetCameraPosition(CameraMap.X,CameraMap.Y)
            set CameraMap.Checking=true
        endif
    endmethod

    static method Generate takes nothing returns nothing
        set CameraMap.Tmr = CreateTimer()
        set CameraMap.X = 0
        set CameraMap.Y = 0
        set CameraMap.dx = 1
        set CameraMap.dy = 1
        set CameraMap.Vertices = 0
        set CameraMap.Checking = false
        call CinematicFadeBJ( bj_CINEFADETYPE_FADEOUT, 0.00, "ReplaceableTextures\\CameraMasks\\White_mask.blp", 0, 0, 0, 0 )
        call TimerStart(CameraMap.Tmr,0.01,true,function CameraMap.Scan)
        call ShowInterface(false, 0)
    endmethod
    
    static method GetZ takes real X, real Y returns real
        local real Z
        
        //Points
        local real xa = I2R(R2I(X/128)*128)
        local real ya = I2R(R2I(Y/128)*128)
        local real za
        local real xb
        local real yb
        local real zb
        local real xc
        local real yc
        local real zc
        local real xd
        local real yd
        local real zd
        
        //vectors
        local real v0x
        local real v0y
        local real v1x
        local real v1y
        local real v2x
        local real v2y
        
        //dot products
        local real dot00
        local real dot01
        local real dot02
        local real dot11
        local real dot12
        local real DotDivisor
        
        //factor for triangle test and calculating Z
        local real u
        local real v
        
        //Compute points
        if (X<0) then
            set xa = xa-128
        endif
        if (Y>=0) then
            set ya = ya+128
        endif
        set xb = xa+128
        set yb = ya
        set xc = xb
        set yc = ya-128
        set xd = xa
        set yd = yc

        //Compute vectors
        set v0x = xc-xa
        set v0y = yc-ya
        set v1x = xb-xa
        set v1y = yb-ya
        set v2x = X-xa
        set v2y = Y-ya
        
        //Compute dot products
        set dot00 = v0x*v0x + v0y*v0y
        set dot01 = v0x*v1x + v0y*v1y
        set dot02 = v0x*v2x + v0y*v2y
        set dot11 = v1x*v1x + v1y*v1y
        set dot12 = v1x*v2x + v1y*v2y
        
        // Compute barycentric coordinates
        set DotDivisor = 1/(dot00*dot11 - dot01*dot01)
        set u = (dot11*dot02 - dot01*dot12)*DotDivisor
        set v = (dot00*dot12 - dot01*dot02)*DotDivisor
        
        //Check if point is inside triangle ABC else its in ACD
        if ((u>0) and (v>0) and (u+v<1)) then
            set u = (xb-X)/128
            set v = (yb-Y)/128
            set za = GetStoredReal(CameraMap.gc,I2S(R2I(xa)),I2S(R2I(ya)))
            set zb = GetStoredReal(CameraMap.gc,I2S(R2I(xb)),I2S(R2I(yb)))
            set zc = GetStoredReal(CameraMap.gc,I2S(R2I(xc)),I2S(R2I(yc)))
            set Z = zb + u*(za-zb) + v*(zc-zb)
        else
            set u = (X-xd)/128
            set v = (Y-yd)/128
            set za = GetStoredReal(CameraMap.gc,I2S(R2I(xa)),I2S(R2I(ya)))
            set zd = GetStoredReal(CameraMap.gc,I2S(R2I(xd)),I2S(R2I(yd)))
            set zc = GetStoredReal(CameraMap.gc,I2S(R2I(xc)),I2S(R2I(yc)))
            set Z = zd + u*(zc-zd) + v*(za-zd)
        endif
        
        return Z
    endmethod
endstruct
08-11-2008, 10:22 AM#2
Toadcop
Because I'm a good person, I will share this with the world without insulting anybody in the process:

Collapse JASS:
function SetCameraZ takes real z returns nothing
    set z = GetCameraField(CAMERA_FIELD_ZOFFSET)+z-GetCameraTargetPositionZ()
    call SetCameraField(CAMERA_FIELD_ZOFFSET,z,- 0.01)
    call SetCameraField(CAMERA_FIELD_ZOFFSET,z,0.01)
endfunction
08-11-2008, 11:34 AM#3
MaD[Lion]
too bad im trying to make a system works for multiplayer ^^

edit: and ur function is for wat?
08-11-2008, 01:20 PM#4
Toadcop
Quote:
this is a struct as part of my camera system for generating camera map, for absolute camera movement, sadly blizzard is too gay, i cant get the values exact... i dont know wat i have done wrong, everything seems right.

Quote:
for absolute camera movement
^

now the most important question.
"why do you need to generate camera map" !?

-> -CameraMap.GetZ(x,y) "how i see you need the Z value"

-> war3 camera use FORCED Z smoothing and it can't be turn off. so thats why the camera Z values are screwed.

-> i post the way to set the absolute camera Z position.

wtf ?
now you continue =)
08-11-2008, 05:43 PM#5
MaD[Lion]
ok tat function was nice thank you. But u still suck for ur fucked up behaviour XD For tat u must be punished. But since u helped me i will not give u bad rep :)
08-11-2008, 06:29 PM#6
Vexorian
Quote:
- lol
this is so fucking amazing pawning effeicient...
btw you are noob 2. a double combo.
it's 3 AM and i can't explain it now... -_- later.
do some researches before posting or making "fucking awesome stuff"
this map shit is useless. well i explained even much more than i thought =)
__________________
Seriously TC, you are going to have to stop it. He was asking for help. Removed posts, warnings issued.
08-11-2008, 07:03 PM#7
Toadcop
Quote:
Seriously TC, you are going to have to stop it. He was asking for help. Removed posts, warnings issued.
no i don't. i need to keep kick ass -> users will begin to think -> solve own problems self.

do you think i am simply bad/evil ? lol... anything has a higher sense =)

@Vex restore my post with the attached map... you may delete the rest text if you want.
08-11-2008, 07:51 PM#8
Anitarf
Quote:
no i don't. i need to keep kick ass -> users will begin to think -> solve own problems self.
If everybody had to invent everything themselves, we'd never get anywhere. I found that function immensly useful, you should submit it to the script section. Sometimes the simplest tricks are the most difficult to think of, you can't blame MaD[Lion] for trying to find a solution the long way around, at least he was still trying, I gave up long ago. I wish I had this function one year ago...
08-11-2008, 09:01 PM#9
Vexorian
Quote:
do you think i am simply bad/evil ? lol... anything has a higher sense =)
I think you are lame. I also think you want to get banned, I also think I do not really want to do that, but if you keep being that offensive against users in this forum, I'll have to do it. If you get banned you will not succeed at making users do what you want them to do. Although that's probably a good thing cause doing everything by yourself is the most stupid idea I've ever heard of.
08-11-2008, 09:19 PM#10
Toadcop
Quote:
Because I'm a good person, I will share this with the world without insulting anybody in the process
omfg T_T ...


this one ->
Quote:
call SetCameraField(CAMERA_FIELD_ZOFFSET,z,- 0.01)
call SetCameraField(CAMERA_FIELD_ZOFFSET,z,0.01)

is the mega imba =) i needed 2 years to figure this out...
cause I BET NO ONE ON EARTH (xD) no that what camera use somekind stack for this commands at least for timed Z change. and if doesnt get synced with the frames (YES FRAMES!) it will be "lost" and the camera will SELF change constant it's height and you CAN'T DO ANYTHING reset etc. doesnt work. so i just tested X thundret of times different ways.
and in this year while developing TcX 1.03 if found out what if to call the camera change with - duration and after with the same but positive it will ballance the whole thing and no gliches will happen.

hmm i can create a demo map to demo what i mean and to show what it does fix... the fact what blizz does use hardcoded camera param is a great phail... if they would read params from miscdata.txt this all would be useless... T_T (about the stack lost issues i am not sure =))

ok here is the map OFC you need to wait ~ 30 seconds... to see what i am talking about. after time is elapsed simply watch on your screen =)


// @ Vex
Quote:
Although that's probably a good thing cause doing everything by yourself is the most stupid idea I've ever heard of.
to code anything in the map by your self. IS THE BEST IDEA ever =) ask some skilled mapmakers. including you... lol. have someone code important code parts for you ?
ofc art etc. maybe done by someone else =) // we are currently in TS section ;)
if you want you can ban me. it will not stop me from reading anyway. and from posting posts... or you want to get new hobbie stalking my clones ? xD
IP is irrelevant =)
Attached Files
File type: w3xCamZ.w3x (42.5 KB)
08-11-2008, 09:52 PM#11
MaD[Lion]
i agree with toad in tat u have to make things urself, at least once to knwo how it works. Tats why i make my own systems eventho there already exists... just i understand my better and learn better. Toadcop is smart but he had this fucked up attitude which i dont get why lol Maybe he need a gf :P
08-12-2008, 02:25 AM#12
Ammorth
Offtopic: I think it's cause he's russian and thats just the russian mentality (I should know, im russian too).

Back on topic: That negative time is brilliant! If only I had known about this months ago!
08-12-2008, 03:37 AM#13
Vexorian
Quote:
to code anything in the map by your self. IS THE BEST IDEA ever =) ask some skilled mapmakers. including you... lol. have someone code important code parts for you ?

The NIH syndrome KILLS people. One of the main libraries in the only map I ever made was Anitarf's vector system.
08-12-2008, 10:01 AM#14
Toadcop
Quote:
The NIH syndrome KILLS people. One of the main libraries in the only map I ever made was Anitarf's vector system.
- hahahahaahah <- YOU REMADE IT into oo xD don't tell shit =) i saw it... (write own/remade) is almost the same.

Quote:
Back on topic: That negative time is brilliant! If only I had known about this months ago!
yeah and me 2-3 years ago xD
btw i am not sure what you have understand... but the negative value is for avoiding camera glitches =) not to set he needed Z height =)
08-15-2008, 01:32 PM#15
dorreen
Hey Toadcop or someone, I used this this Toadcops method to get exact camera height, and it is working fine, exepect that there is some nasty black flashes sometimes. Im not sure if its this Toadcops thingie what causes them or is it something else, does anyone knows anything about this?

Im calculating terrain Z height, and changing camera height, so it matches terrain height.


EDIT. I made some changes, and now Flashing starts after certain period of time, when game starts everything is ok.

EDIT2, Could this have something to do with really big FarZ values? ( I think I fixed it now )